WIP - show "eye" in base course elements (when entering a session)

See BT#10620
pull/2487/head
jmontoyaa 9 years ago
parent 67e703c67c
commit e1af1bbbf9
  1. 143
      main/inc/lib/link.lib.php

@ -765,7 +765,6 @@ class Link extends Model
$_user['user_id'] $_user['user_id']
); );
Display::addFlash(Display::return_message(get_lang('VisibilityChanged'))); Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
} elseif ($scope == TOOL_LINK_CATEGORY) { } elseif ($scope == TOOL_LINK_CATEGORY) {
api_item_property_update( api_item_property_update(
$_course, $_course,
@ -805,7 +804,7 @@ class Link extends Model
$sql = "SELECT *, linkcat.id $sql = "SELECT *, linkcat.id
FROM $tblLinkCategory linkcat FROM $tblLinkCategory linkcat
WHERE WHERE
linkcat.c_id = " . $courseId . " linkcat.c_id = $courseId
$sessionCondition $sessionCondition
ORDER BY linkcat.display_order DESC"; ORDER BY linkcat.display_order DESC";
@ -862,8 +861,12 @@ class Link extends Model
* *
* @return array * @return array
*/ */
public static function getLinksPerCategory($categoryId, $courseId, $sessionId, $withBaseContent = true) public static function getLinksPerCategory(
{ $categoryId,
$courseId,
$sessionId,
$withBaseContent = true
) {
$tbl_link = Database:: get_course_table(TABLE_LINK); $tbl_link = Database:: get_course_table(TABLE_LINK);
$TABLE_ITEM_PROPERTY = Database:: get_course_table(TABLE_ITEM_PROPERTY); $TABLE_ITEM_PROPERTY = Database:: get_course_table(TABLE_ITEM_PROPERTY);
$courseId = (int) $courseId; $courseId = (int) $courseId;
@ -874,22 +877,57 @@ class Link extends Model
$condition_session = api_get_session_condition( $condition_session = api_get_session_condition(
$sessionId, $sessionId,
true, true,
$withBaseContent, false,
'link.session_id' 'ip.session_id'
); );
$sql = "SELECT *, link.id if (!empty($sessionId)) {
$conditionBaseSession = api_get_session_condition(
0,
true,
$withBaseContent,
'ip.session_id'
);
$condition = " AND
(
(ip.visibility = '1' $conditionBaseSession) OR
(
(ip.visibility = '0' OR ip.visibility = '1')
$condition_session
)
)
";
} else {
$condition = api_get_session_condition(
0,
true,
false,
'ip.session_id'
);
$condition .= " AND (ip.visibility = '0' OR ip.visibility = '1') $condition " ;
}
$sql = "SELECT
link.id,
ip.session_id,
link.session_id link_session_id,
url,
category_id,
visibility,
description,
title,
target
FROM $tbl_link link FROM $tbl_link link
INNER JOIN $TABLE_ITEM_PROPERTY ip INNER JOIN $TABLE_ITEM_PROPERTY ip
ON (link.id = ip.ref AND link.c_id = ip.c_id) ON (link.id = ip.ref AND link.c_id = ip.c_id)
WHERE WHERE
ip.tool = '" . TOOL_LINK . "' AND ip.tool = '" . TOOL_LINK . "' AND
link.category_id = '" . $categoryId . "' AND link.category_id = '" . $categoryId . "' AND
(ip.visibility = '0' OR ip.visibility = '1')
$condition_session AND
link.c_id = $courseId AND link.c_id = $courseId AND
ip.c_id = $courseId ip.c_id = $courseId
ORDER BY link.display_order ASC"; $condition
ORDER BY link.display_order ASC, ip.session_id DESC";
$result = Database:: query($sql); $result = Database:: query($sql);
@ -914,15 +952,25 @@ class Link extends Model
$links = self::getLinksPerCategory($catid, $courseId, $session_id); $links = self::getLinksPerCategory($catid, $courseId, $session_id);
$content = ''; $content = '';
$numberoflinks = count($links); $numberOfLinks = count($links);
if (!empty($links)) { if (!empty($links)) {
$content .= '<div class="link list-group">'; $content .= '<div class="link list-group">';
$i = 1; $i = 1;
$linksAdded = [];
foreach ($links as $myrow) { foreach ($links as $myrow) {
$linkId = $myrow['id'];
if (in_array($linkId, $linksAdded)) {
continue;
}
$linksAdded[] = $linkId;
$categoryId = $myrow['category_id'];
// Validation when belongs to a session. // Validation when belongs to a session.
$session_img = api_get_session_image( $session_img = api_get_session_image(
$myrow['session_id'], $myrow['link_session_id'],
$_user['status'] $_user['status']
); );
@ -935,22 +983,21 @@ class Link extends Model
'check-circle-o', 'check-circle-o',
'default btn-sm', 'default btn-sm',
array( array(
'onclick' => "check_url('" . $myrow['id'] . "', '" . addslashes($myrow['url']) . "');", 'onclick' => "check_url('" . $linkId . "', '" . addslashes($myrow['url']) . "');",
'title' => get_lang('CheckURL') 'title' => get_lang('CheckURL')
) )
); );
$link_validator .= Display::span( $link_validator .= Display::span(
'', '',
array( array(
'id' => 'url_id_' . $myrow['id'], 'id' => 'url_id_' . $linkId,
'class' => 'check-link' 'class' => 'check-link'
) )
); );
if ($session_id == $myrow['session_id']) { if ($session_id == $myrow['link_session_id']) {
$url = api_get_self().'?' .api_get_cidreq().'&action=editlink&category=' .(!empty ($category) ? $category : ''). $url = api_get_self().'?'.api_get_cidreq().'&action=editlink&id='.$linkId;
'&id=' . $myrow['id'] .
'&category_id=' . $myrow['id'];
$title = get_lang('Edit'); $title = get_lang('Edit');
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
'', '',
@ -961,48 +1008,53 @@ class Link extends Model
'title' => $title 'title' => $title
) )
); );
}
$urlVisibility = api_get_self().'?'.api_get_cidreq() .
'&sec_token=' . $token .
'&id=' . $linkId .
'&scope=link&category_id=' . $categoryId;
if ($myrow['visibility'] == '1') { switch ($myrow['visibility']) {
$url .= 'link.php?' . api_get_cidreq() . case '1':
'&sec_token=' . $token . $urlVisibility .= '&action=invisible';
'&action=invisible&id=' . $myrow['id'] .
'&scope=link&category_id=' . $myrow['category_id'];
$title = get_lang('MakeInvisible'); $title = get_lang('MakeInvisible');
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
'', '',
$url, $urlVisibility,
'eye', 'eye',
'default btn-sm', 'default btn-sm',
array( array(
'title' => $title 'title' => $title
) )
); );
} break;
case '0':
if ($myrow['visibility'] == '0') { $urlVisibility .= '&action=visible';
$url .= 'link.php?' . api_get_cidreq() .'&sec_token=' . $token .'&action=visible&id=' . $myrow['id'] .'&scope=link&category_id=' . $myrow['category_id'];
$title = get_lang('MakeVisible'); $title = get_lang('MakeVisible');
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
'', '',
$url, $urlVisibility,
'eye-slash', 'eye-slash',
'primary btn-sm', 'primary btn-sm',
array( array(
'title' => $title 'title' => $title
) )
); );
} break;
}
if ($session_id == $myrow['link_session_id']) {
$moveLinkParams = [ $moveLinkParams = [
'id' => $myrow['id'], 'id' => $linkId,
'scope' => 'category', 'scope' => 'category',
'category_id' => $myrow['category_id'], 'category_id' => $categoryId,
'action' => 'move_link_up' 'action' => 'move_link_up'
]; ];
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
get_lang('MoveUp'), get_lang('MoveUp'),
'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams), api_get_self() . '?'.api_get_cidreq() . '&' . http_build_query($moveLinkParams),
'level-up', 'level-up',
'default', 'default',
['class' => 'btn-sm ' . ($i === 1 ? 'disabled' : '')], ['class' => 'btn-sm ' . ($i === 1 ? 'disabled' : '')],
@ -1012,14 +1064,14 @@ class Link extends Model
$moveLinkParams['action'] = 'move_link_down'; $moveLinkParams['action'] = 'move_link_down';
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
get_lang('MoveDown'), get_lang('MoveDown'),
'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams), api_get_self().'?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
'level-down', 'level-down',
'default', 'default',
['class' => 'btn-sm ' . ($i === $numberoflinks ? 'disabled' : '')], ['class' => 'btn-sm ' . ($i === $numberOfLinks ? 'disabled' : '')],
false false
); );
$url .= api_get_self() . '?' . api_get_cidreq() .'&sec_token=' . $token .'&action=deletelink&id=' . $myrow['id'] .'&category_id=' . $myrow['category_id']; $url .= api_get_self().'?'.api_get_cidreq() .'&sec_token=' . $token .'&action=deletelink&id=' . $linkId .'&category_id=' . $categoryId;
$event = "javascript: if(!confirm('" . get_lang('LinkDelconfirm') . "'))return false;"; $event = "javascript: if(!confirm('" . get_lang('LinkDelconfirm') . "'))return false;";
$title = get_lang('Delete'); $title = get_lang('Delete');
@ -1033,19 +1085,9 @@ class Link extends Model
'title' => $title 'title' => $title
) )
); );
} else {
$title = get_lang('EditionNotAvailableFromSession');
$toolbar .= Display::toolbarButton(
'',
'#',
'trash-o',
'default btn-sm',
array(
'title' => $title
)
);
} }
} }
$iconLink = Display::return_icon( $iconLink = Display::return_icon(
'url.png', 'url.png',
get_lang('Link'), get_lang('Link'),
@ -1058,7 +1100,7 @@ class Link extends Model
$content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>'; $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
$content .= '<h4 class="list-group-item-heading">'; $content .= '<h4 class="list-group-item-heading">';
$content .= $iconLink; $content .= $iconLink;
$url = 'link_goto.php?' . api_get_cidreq() .'&link_id=' . $myrow['id'] .'&link_url=' . urlencode($myrow['url']); $url = api_get_path(WEB_CODE_PATH).'link/link_goto.php?' . api_get_cidreq() .'&link_id=' . $linkId .'&link_url=' . urlencode($myrow['url']);
$content .= Display::tag( $content .= Display::tag(
'a', 'a',
Security:: remove_XSS($myrow['title']), Security:: remove_XSS($myrow['title']),
@ -1079,7 +1121,7 @@ class Link extends Model
$content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>'; $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
$content .= '<h4 class="list-group-item-heading">'; $content .= '<h4 class="list-group-item-heading">';
$content .= $iconLink; $content .= $iconLink;
$url = 'link_goto.php?' . api_get_cidreq() .'&link_id=' . $myrow['id'] . "&link_url=" . urlencode($myrow['url']); $url = api_get_path(WEB_CODE_PATH).'link/link_goto.php?' . api_get_cidreq() .'&link_id=' . $linkId . "&link_url=" . urlencode($myrow['url']);
$content .= Display::tag( $content .= Display::tag(
'a', 'a',
Security:: remove_XSS($myrow['title']), Security:: remove_XSS($myrow['title']),
@ -1609,6 +1651,7 @@ class Link extends Model
$header .= Security::remove_XSS($myrow['category_title']).'</a>'; $header .= Security::remove_XSS($myrow['category_title']).'</a>';
$header .= '<div class="pull-right">'; $header .= '<div class="pull-right">';
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if ($session_id == $myrow['session_id']) { if ($session_id == $myrow['session_id']) {
$header .= $strVisibility; $header .= $strVisibility;

Loading…
Cancel
Save