diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php
index 49a365a140..9d668d7ef4 100755
--- a/main/inc/lib/link.lib.php
+++ b/main/inc/lib/link.lib.php
@@ -1,6 +1,8 @@
0) {
@@ -883,14 +885,13 @@ class Link extends Model
$_user['status']
);
- //$css_class = $i % 2 == 0 ? $css_class = 'row_odd' : $css_class = 'row_even';
$toolbar = '';
$link_validator = '';
if (api_is_allowed_to_edit(null, true)) {
$toolbar .= Display::toolbarButton(
'',
'#',
- 'retweet',
+ 'check-circle-o',
'default btn-sm',
array(
'onclick' => "check_url('" . $myrow['id'] . "', '" . addslashes($myrow['url']) . "');",
@@ -904,9 +905,6 @@ class Link extends Model
'class' => 'check-link'
)
);
- }
-
- if (api_is_allowed_to_edit(null, true)) {
if ($session_id == $myrow['session_id']) {
$url = api_get_self() . '?' . api_get_cidreq() .
@@ -924,21 +922,6 @@ class Link extends Model
)
);
- // DISPLAY MOVE UP COMMAND only if it is not the top link.
- /* commented at least since 2014-10-11
- if ($i != 1) {
- echo '' . Display :: return_icon('up.png', get_lang('Up'), array (), ICON_SIZE_SMALL) . '', "\n";
- } else {
- echo Display :: return_icon('up_na.png', get_lang('Up'), array (), ICON_SIZE_SMALL) . '';
- }
-
- // DISPLAY MOVE DOWN COMMAND only if it is not the bottom link.
- if ($i < $numberoflinks) {
- echo '' . Display :: return_icon('down.png', get_lang('Down'), array (), ICON_SIZE_SMALL) . '', "\n";
- } else {
- echo Display :: return_icon('down_na.png', get_lang('Down'), array (), ICON_SIZE_SMALL) . '', "\n";
- }*/
-
if ($myrow['visibility'] == '1') {
$url .= 'link.php?' . api_get_cidreq() .
'&sec_token=' . $token .
@@ -970,6 +953,30 @@ class Link extends Model
);
}
+ $moveLinkParams = [
+ 'id' => $myrow['id'],
+ 'scope' => 'category',
+ 'category_id' => $myrow['category_id'],
+ 'action' => 'move_link_up'
+ ];
+ $toolbar .= Display::toolbarButton(
+ get_lang('MoveUp'),
+ 'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
+ 'level-up',
+ 'default',
+ ['class' => 'btn-sm ' . ($i === 1 ? 'disabled' : '')],
+ false
+ );
+ $moveLinkParams['action'] = 'move_link_down';
+ $toolbar .= Display::toolbarButton(
+ get_lang('MoveDown'),
+ 'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
+ 'level-down',
+ 'default',
+ ['class' => 'btn-sm ' . ($i === $numberoflinks ? 'disabled' : '')],
+ false
+ );
+
$url .= api_get_self() . '?' . api_get_cidreq() .'&sec_token=' . $token .'&action=deletelink&id=' . $myrow['id'] .'&category_id=' . $myrow['category_id'];
$event = "javascript: if(!confirm('" . get_lang('LinkDelconfirm') . "'))return false;";
$title = get_lang('Delete');
@@ -1037,7 +1044,7 @@ class Link extends Model
array(
'href' => $url,
'target' => '_blank',
- 'class' => 'invisible'
+ 'class' => 'text-muted'
)
);
$content .= $link_validator;
@@ -1131,7 +1138,6 @@ class Link extends Model
*/
public static function movecatlink($action, $catlinkid, $courseId = null, $sessionId = null)
{
- $tbl_link = Database:: get_course_table(TABLE_LINK);
$tbl_categories = Database:: get_course_table(TABLE_LINK_CATEGORY);
if (is_null($courseId)) {
@@ -1142,50 +1148,26 @@ class Link extends Model
$sessionId = api_get_session_id();
}
$sessionId = intval($sessionId);
+ $thiscatlinkId = intval($catlinkid);
if ($action == 'down') {
- $thiscatlinkId = intval($catlinkid);
$sortDirection = 'DESC';
}
if ($action == 'up') {
- $thiscatlinkId = intval($catlinkid);
$sortDirection = 'ASC';
}
- // We check if it is a category we are moving or a link.
- // If it is a category, a querystring catmove = true is present in the url.
- $catmove = 'true';
- if ($catmove == 'true') {
- $movetable = $tbl_categories;
- $catid = $catlinkid;
- } else {
- $movetable = $tbl_link;
- // Getting the category of the link.
- if (!empty ($thiscatlinkId)) {
- $sql = "SELECT category_id FROM " . $movetable . "
- WHERE c_id = $courseId AND id='$thiscatlinkId'";
- $result = Database:: query($sql);
- $catid = Database:: fetch_array($result);
- }
- }
-
- // This code is copied and modified from announcements.php.
+ $movetable = $tbl_categories;
if (!empty($sortDirection)) {
if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC'))) {
$sortDirection = 'ASC';
}
- if ($catmove == 'true') {
- $sql = "SELECT id, display_order FROM $movetable
- WHERE c_id = $courseId
- ORDER BY display_order $sortDirection";
- } else {
- $sql = "SELECT id, display_order FROM $movetable
- WHERE c_id = $courseId AND category_id='" . $catid[0] . "'
- ORDER BY display_order $sortDirection";
- }
+ $sql = "SELECT id, display_order FROM $movetable
+ WHERE c_id = $courseId
+ ORDER BY display_order $sortDirection";
$linkresult = Database:: query($sql);
$thislinkOrder = 1;
while ($sortrow = Database:: fetch_array($linkresult)) {
@@ -1784,4 +1766,76 @@ class Link extends Model
return $category;
}
+
+ /**
+ * Move a the display_order from a link in its category
+ * @param int $id The link ID
+ * @param string $direction The direction to sort the links
+ * @return bool
+ */
+ private static function moveLinkDisplayOrder($id, $direction)
+ {
+ $em = Database::getManager();
+ /** @var CLink $link */
+ $link = $em->find('ChamiloCourseBundle:CLink', $id);
+
+ if (!$link) {
+ return false;
+ }
+
+ $compareLinks = $em
+ ->getRepository('ChamiloCourseBundle:CLink')
+ ->findBy(
+ ['cId' => $link->getCId(), 'categoryId' => $link->getCategoryId()],
+ ['displayOrder' => $direction]
+ );
+ /** @var CLink $prevLink */
+ $prevLink = null;
+
+ /** @var CLink $compareLink */
+ foreach ($compareLinks as $compareLink) {
+ if ($compareLink->getId() !== $link->getId()) {
+ $prevLink = $compareLink;
+
+ continue;
+ }
+
+ if (!$prevLink) {
+ return false;
+ }
+
+ $newPrevLinkDisplayOrder = $link->getDisplayOrder();
+ $newLinkDisplayOrder = $prevLink->getDisplayOrder();
+
+ $link->setDisplayOrder($newLinkDisplayOrder);
+ $prevLink->setDisplayOrder($newPrevLinkDisplayOrder);
+
+ $em->merge($prevLink);
+ $em->merge($link);
+ break;
+ }
+
+ $em->flush();
+ return true;
+ }
+
+ /**
+ * Move to up a the display_order from a link in its category
+ * @param int $id
+ * @return bool
+ */
+ public static function moveLinkUp($id)
+ {
+ return self::moveLinkDisplayOrder($id, 'ASC');
+ }
+
+ /**
+ * Move to down a the display_order from a link in its category
+ * @param int $id
+ * @return bool
+ */
+ public static function moveLinkDown($id)
+ {
+ return self::moveLinkDisplayOrder($id, 'DESC');
+ }
}
diff --git a/main/install/install.lib.php b/main/install/install.lib.php
index 3124881c62..a8838294cb 100755
--- a/main/install/install.lib.php
+++ b/main/install/install.lib.php
@@ -3029,7 +3029,7 @@ function migrateSwitch($fromVersion, $manager, $processFiles = true)
$sql = "SELECT * FROM c_student_publication where (post_group_id <> 0 or post_group_id is not null)";
$statement = $connection->executeQuery($sql);
$result = $statement->fetchAll();
- foreach ($results as $row) {
+ foreach ($result as $row) {
$groupId = $row['post_group_id'];
$courseId = $row['c_id'];
$sessionId = $row['session_id'];
diff --git a/main/link/link.php b/main/link/link.php
index 09027b65fe..072033573d 100755
--- a/main/link/link.php
+++ b/main/link/link.php
@@ -185,6 +185,16 @@ switch ($action) {
header('Location: '.$linkListUrl);
exit;
break;
+ case 'move_link_up':
+ Link::moveLinkUp($id);
+ header('Location: ' . $linkListUrl);
+ exit;
+ break;
+ case 'move_link_down':
+ Link::moveLinkDown($id);
+ header('Location: ' . $linkListUrl);
+ exit;
+ break;
case 'list':
default:
ob_start();
diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php
index f8359a56a0..75289413e8 100755
--- a/main/mySpace/myStudents.php
+++ b/main/mySpace/myStudents.php
@@ -733,7 +733,7 @@ if (!empty($student_id)) {
}
$scoretotal_display = '0/0 (0%)';
- if (!empty($scoretotal)) {
+ if (!empty($scoretotal) && !empty($scoretotal[1])) {
$scoretotal_display =
round($scoretotal[0], 1 ).'/'.
round($scoretotal[1], 1).