@@ -6158,9 +6158,9 @@ class learnpath
);
}
- $delete_icon .= '
lp_id.'"
+ onclick="return confirmation(\''.addslashes($title).'\');"
class="btn btn-default">';
$delete_icon .= Display::return_icon(
'delete.png',
@@ -6269,14 +6269,14 @@ class learnpath
Display::tag(
'div',
"
- $previewIcon
- $audio
- $edit_icon
+ $previewIcon
+ $audio
+ $edit_icon
$pluginCalendarIcon
- $forumIcon
- $prerequisities_icon
- $move_item_icon
- $audio_icon
+ $forumIcon
+ $prerequisities_icon
+ $move_item_icon
+ $audio_icon
$orderIcons
$delete_icon
",
@@ -6948,7 +6948,7 @@ class learnpath
if (empty($documentInfo)) {
// Try with iid
$table = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT id, path FROM $table
+ $sql = "SELECT id, path FROM $table
WHERE c_id = $course_id AND iid = $document_id AND path NOT LIKE '%_DELETED_%' ";
$res_doc = Database::query($sql);
$row = Database::fetch_array($res_doc);
@@ -8384,7 +8384,7 @@ class learnpath
if ($action === 'add') {
if (is_numeric($extra_info)) {
$extra_info = (int) $extra_info;
- $sql_doc = "SELECT path FROM $tbl_doc
+ $sql_doc = "SELECT path FROM $tbl_doc
WHERE c_id = $course_id AND iid = ".$extra_info;
$result = Database::query($sql_doc);
$path_file = Database::result($result, 0, 0);
@@ -9169,7 +9169,7 @@ class learnpath
$item_url = stripslashes($extra_info['url']);
} elseif (is_numeric($extra_info)) {
$extra_info = (int) $extra_info;
- $sql = "SELECT title, description, url
+ $sql = "SELECT title, description, url
FROM $tbl_link
WHERE c_id = $course_id AND iid = $extra_info";
$result = Database::query($sql);
@@ -9502,7 +9502,7 @@ class learnpath
$return = '';
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item
+ $sql = "SELECT * FROM $tbl_lp_item
WHERE iid = ".$item_id;
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
@@ -9569,9 +9569,9 @@ class learnpath
// Try with iid
$table = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT path FROM $table
- WHERE
- c_id = ".api_get_course_int_id()." AND
- iid = ".$row['path']." AND
+ WHERE
+ c_id = ".api_get_course_int_id()." AND
+ iid = ".$row['path']." AND
path NOT LIKE '%_DELETED_%'";
$result = Database::query($sql);
$documentData = Database::fetch_array($result);
@@ -9608,9 +9608,9 @@ class learnpath
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql = "SELECT * FROM ".$tbl_lp_item."
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->lp_id." AND
+ WHERE
+ c_id = $course_id AND
+ lp_id = ".$this->lp_id." AND
parent_item_id = 0
ORDER BY display_order ASC";
$res_zero = Database::query($sql);
@@ -9657,12 +9657,12 @@ class learnpath
if (!id) {
return false;
}
-
+
var cbo = document.getElementById('previous');
for(var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
-
+
var k=0;
for(var i = 1; i <= child_name[id].length; i++){
var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
@@ -9670,7 +9670,7 @@ class learnpath
cbo.options[i] = option;
k = i;
}
-
+
cbo.options[k].selected = true;
$('#previous').selectpicker('refresh');
}";
@@ -9860,55 +9860,55 @@ class learnpath
}
$return .= '
';
- $return .= '';
$return .= ' | ';
$return .= '';
- $return .= '';
$return .= ' | ';
}
if ($item['item_type'] == TOOL_HOTPOTATOES) {
$return .= '';
- $return .= '';
$return .= ' | ';
$return .= '';
- $return .= '';
$return .= ' | ';
}
@@ -10114,18 +10114,18 @@ class learnpath
}
$sql_quiz = "SELECT * FROM $tbl_quiz
- WHERE
- c_id = $course_id AND
+ WHERE
+ c_id = $course_id AND
$activeCondition
- $condition_session
+ $condition_session
$categoryCondition
$keywordCondition
ORDER BY title ASC";
$sql_hot = "SELECT * FROM $tbl_doc
- WHERE
- c_id = $course_id AND
- path LIKE '".$uploadPath."/%/%htm%'
+ WHERE
+ c_id = $course_id AND
+ path LIKE '".$uploadPath."/%/%htm%'
$condition_session
ORDER BY id ASC";
@@ -10275,7 +10275,7 @@ class learnpath
'link.session_id'
);
- $sql = "SELECT
+ $sql = "SELECT
link.id as link_id,
link.title as link_title,
link.session_id as link_session_id,
@@ -11748,9 +11748,9 @@ EOD;
$max_order = $row_max_order->display_order;
// Get the previous item ID
$sql = "SELECT iid as previous FROM $table_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->lp_id." AND
+ WHERE
+ c_id = $course_id AND
+ lp_id = ".$this->lp_id." AND
display_order = '$max_order' ";
$rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max);
@@ -12787,7 +12787,7 @@ EOD;
$this->accumulateScormTime = (int) $value;
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
- $sql = "UPDATE $lp_table
+ $sql = "UPDATE $lp_table
SET accumulate_scorm_time = ".$this->accumulateScormTime."
WHERE iid = $lp_id";
Database::query($sql);
@@ -13015,7 +13015,7 @@ EOD;
$learningPathId = (int) $learningPathId;
$id_in_path = (int) $id_in_path;
- $sql = "SELECT item_type, title, ref
+ $sql = "SELECT item_type, title, ref
FROM $tbl_lp_item
WHERE c_id = $course_id AND lp_id = $learningPathId AND iid = $id_in_path";
$res_item = Database::query($sql);
@@ -13363,8 +13363,8 @@ EOD;
public function getAccumulateWorkTimeTotalCourse()
{
$table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT SUM(accumulate_work_time) AS total
- FROM $table
+ $sql = "SELECT SUM(accumulate_work_time) AS total
+ FROM $table
WHERE c_id = ".$this->course_int_id;
$result = Database::query($sql);
$row = Database::fetch_array($result);
@@ -13407,8 +13407,8 @@ EOD;
$courseId = (int) $courseId;
$table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT accumulate_work_time
- FROM $table
+ $sql = "SELECT accumulate_work_time
+ FROM $table
WHERE c_id = $courseId AND id = $lpId";
$result = Database::query($sql);
$row = Database::fetch_array($result);
@@ -13537,7 +13537,7 @@ EOD;
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $tbl_lp_item
+ $sql = "SELECT * FROM $tbl_lp_item
WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
if ($addParentCondition) {
@@ -13677,4 +13677,66 @@ EOD;
return '';
}
+
+ /**
+ * Save the new order for learning path items
+ *
+ * We have to update parent_item_id, previous_item_id, next_item_id, display_order in the database.
+ *
+ * @param array $orderList A associative array with item ID as key and parent ID as value.
+ * @param int $courseId
+ */
+ public static function sortItemByOrderList(array $orderList, $courseId = 0)
+ {
+ $courseId = $courseId ?: api_get_course_int_id();
+ $itemList = new LpItemOrderList();
+
+ foreach ($orderList as $id => $parentId) {
+ $item = new LpOrderItem($id, $parentId);
+ $itemList->add($item);
+ }
+
+ $parents = $itemList->getListOfParents();
+
+ foreach ($parents as $parentId) {
+ $sameParentLpItemList = $itemList->getItemWithSameParent($parentId);
+ $previous_item_id = 0;
+ for ($i = 0; $i < count($sameParentLpItemList->list); $i++) {
+ $item_id = $sameParentLpItemList->list[$i]->id;
+ // display_order
+ $display_order = $i + 1;
+ $itemList->setParametersForId($item_id, $display_order, 'display_order');
+ // previous_item_id
+ $itemList->setParametersForId($item_id, $previous_item_id, 'previous_item_id');
+ $previous_item_id = $item_id;
+ // next_item_id
+ $next_item_id = 0;
+ if ($i < count($sameParentLpItemList->list) - 1) {
+ $next_item_id = $sameParentLpItemList->list[$i + 1]->id;
+ }
+ $itemList->setParametersForId($item_id, $next_item_id, 'next_item_id');
+ }
+ }
+
+ $table = Database::get_course_table(TABLE_LP_ITEM);
+
+ foreach ($itemList->list as $item) {
+ $params = [];
+ $params['display_order'] = $item->display_order;
+ $params['previous_item_id'] = $item->previous_item_id;
+ $params['next_item_id'] = $item->next_item_id;
+ $params['parent_item_id'] = $item->parent_item_id;
+
+ Database::update(
+ $table,
+ $params,
+ [
+ 'iid = ? AND c_id = ? ' => [
+ (int) $item->id,
+ (int) $courseId,
+ ],
+ ]
+ );
+ }
+ }
}