Fix lp order when using categories see BT#12739

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent ca5c0fed3d
commit 981560ab35
  1. 36
      main/lp/learnpath.class.php
  2. 10
      main/lp/lp_controller.php
  3. 8
      main/lp/lp_list.php

@ -3854,20 +3854,29 @@ class learnpath
/**
* Move a LP up (display_order)
* @param integer $lp_id Learnpath ID
* @param int $lp_id Learnpath ID
* @param int $categoryId
* @return bool
*/
public static function move_up($lp_id)
public static function move_up($lp_id, $categoryId = 0)
{
$courseId = api_get_course_int_id();
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$categoryCondition = '';
if (!empty($categoryId)) {
$categoryId = (int) $categoryId;
$categoryCondition = " AND category_id = $categoryId";
}
$sql = "SELECT * FROM $lp_table
WHERE c_id = $courseId
$categoryCondition
ORDER BY display_order";
$res = Database::query($sql);
if ($res === false) {
return false;
}
$lps = [];
$lp_order = [];
$num = Database::num_rows($res);
@ -3904,15 +3913,24 @@ class learnpath
/**
* Move a learnpath down (display_order)
* @param integer $lp_id Learnpath ID
* @param int $lp_id Learnpath ID
* @param int $categoryId
* @return bool
*/
public static function move_down($lp_id)
public static function move_down($lp_id, $categoryId = 0)
{
$course_id = api_get_course_int_id();
$courseId = api_get_course_int_id();
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$categoryCondition = '';
if (!empty($categoryId)) {
$categoryId = (int) $categoryId;
$categoryCondition = " AND category_id = $categoryId";
}
$sql = "SELECT * FROM $lp_table
WHERE c_id = $course_id
WHERE c_id = $courseId
$categoryCondition
ORDER BY display_order";
$res = Database::query($sql);
if ($res === false) {
@ -3931,7 +3949,7 @@ class learnpath
if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
$need_fix = true;
$sql_u = "UPDATE $lp_table SET display_order = $i
WHERE c_id = ".$course_id." AND id = ".$row['id'];
WHERE c_id = ".$courseId." AND id = ".$row['id'];
Database::query($sql_u);
}
$row['display_order'] = $i;
@ -3944,10 +3962,10 @@ class learnpath
$order = $lps[$lp_id]['display_order'];
if ($order < $max) { // If it's the first element, no need to move up.
$sql_u1 = "UPDATE $lp_table SET display_order = $order
WHERE c_id = ".$course_id." AND id = ".$lp_order[$order + 1];
WHERE c_id = ".$courseId." AND id = ".$lp_order[$order + 1];
Database::query($sql_u1);
$sql_u2 = "UPDATE $lp_table SET display_order = ".($order + 1)."
WHERE c_id = ".$course_id." AND id = ".$lp_id;
WHERE c_id = ".$courseId." AND id = ".$lp_id;
Database::query($sql_u2);
}
}

@ -886,7 +886,8 @@ switch ($action) {
error_log('New LP - No learnpath given for publish', 0);
require 'lp_list.php';
} else {
learnpath::move_up($_REQUEST['lp_id']);
learnpath::move_up($_REQUEST['lp_id'], $_REQUEST['category_id']);
Display::addFlash(Display::return_message(get_lang('Updated')));
require 'lp_list.php';
}
break;
@ -899,7 +900,8 @@ switch ($action) {
error_log('New LP - No learnpath given for publish', 0);
require 'lp_list.php';
} else {
learnpath::move_down($_REQUEST['lp_id']);
learnpath::move_down($_REQUEST['lp_id'], $_REQUEST['category_id']);
Display::addFlash(Display::return_message(get_lang('Updated')));
require 'lp_list.php';
}
break;
@ -968,9 +970,9 @@ switch ($action) {
$_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
$publicated_on = $_REQUEST['publicated_on'];
$publicated_on = $_REQUEST['publicated_on'];
} else {
$publicated_on = null;
$publicated_on = null;
}
if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {

@ -721,23 +721,23 @@ foreach ($categories as $item) {
if ($details['lp_display_order'] == 1 && $max != 1) {
$dsp_order .= Display::url(
Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL),
"lp_controller.php?".api_get_cidreq()."&action=move_lp_down&lp_id=$id"
"lp_controller.php?".api_get_cidreq()."&action=move_lp_down&lp_id=$id&category_id=$categoryId"
);
} elseif ($current == $max - 1 && $max != 1) {
$dsp_order .= Display::url(
Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL),
"lp_controller.php?".api_get_cidreq()."&action=move_lp_up&lp_id=$id"
"lp_controller.php?".api_get_cidreq()."&action=move_lp_up&lp_id=$id&category_id=$categoryId"
);
} elseif ($max == 1) {
$dsp_order = '';
} else {
$dsp_order .= Display::url(
Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL),
"lp_controller.php?".api_get_cidreq()."&action=move_lp_down&lp_id=$id"
"lp_controller.php?".api_get_cidreq()."&action=move_lp_down&lp_id=$id&category_id=$categoryId"
);
$dsp_order .= Display::url(
Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL),
"lp_controller.php?".api_get_cidreq()."&action=move_lp_up&lp_id=$id"
"lp_controller.php?".api_get_cidreq()."&action=move_lp_up&lp_id=$id&category_id=$categoryId"
);
}
}

Loading…
Cancel
Save