|
@@ -627,7 +627,7 @@ class learnpath
|
|
|
if (!empty($next)) {
|
|
|
$sql = "UPDATE $tbl_lp_item
|
|
|
SET previous_item_id = $new_item_id
|
|
|
- WHERE c_id = $course_id AND id = $next";
|
|
|
+ WHERE c_id = $course_id AND id = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
|
|
|
Database::query($sql);
|
|
|
}
|
|
|
|
|
@@ -656,6 +656,11 @@ class learnpath
|
|
|
WHERE c_id = $course_id AND iid = $new_item_id";
|
|
|
Database::query($sql);
|
|
|
|
|
|
+ $sql = "UPDATE $tbl_lp_item
|
|
|
+ SET previous_item_id = ".$this->getLastInFirstLevel()."
|
|
|
+ WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
|
|
|
+ Database::query($sql);
|
|
|
+
|
|
|
// Upload audio.
|
|
|
if (!empty($_FILES['mp3']['name'])) {
|
|
|
// Create the audio folder if it does not exist yet.
|
|
@@ -1242,7 +1247,7 @@ class learnpath
|
|
|
WHERE iid = $previous";
|
|
|
Database::query($sql_upd);
|
|
|
$sql_upd = "UPDATE $lp_item SET previous_item_id = $previous
|
|
|
- WHERE iid = $next";
|
|
|
+ WHERE iid = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
|
|
|
Database::query($sql_upd);
|
|
|
// Now update all following items with new display order.
|
|
|
$sql_all = "UPDATE $lp_item SET display_order = display_order-1
|
|
@@ -1258,6 +1263,11 @@ class learnpath
|
|
|
WHERE c_id = $course_id AND prerequisite = $id";
|
|
|
Database::query($sql_all);
|
|
|
|
|
|
+ $sql = "UPDATE $lp_item
|
|
|
+ SET previous_item_id = ".$this->getLastInFirstLevel()."
|
|
|
+ WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
|
|
|
+ Database::query($sql);
|
|
|
+
|
|
|
// Remove from search engine if enabled.
|
|
|
if (api_get_setting('search_enabled') === 'true') {
|
|
|
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
|
|
@@ -1991,6 +2001,28 @@ class learnpath
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get the last element in the first level.
|
|
|
+ * Unlike learnpath::get_last this function doesn't consider the subsection' elements.
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getLastInFirstLevel()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $lastId = Database::getManager()
|
|
|
+ ->createQuery('SELECT i.iid FROM ChamiloCourseBundle:CLpItem i
|
|
|
+ WHERE i.lpId = :lp AND i.parentItemId = 0 AND i.itemType != :type ORDER BY i.displayOrder DESC')
|
|
|
+ ->setMaxResults(1)
|
|
|
+ ->setParameters(['lp' => $this->lp_id, 'type' => TOOL_LP_FINAL_ITEM])
|
|
|
+ ->getSingleScalarResult();
|
|
|
+
|
|
|
+ return $lastId;
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Gets the navigation bar for the learnpath display screen.
|
|
|
*
|
|
@@ -8701,7 +8733,8 @@ class learnpath
|
|
|
$arrHide = [];
|
|
|
// POSITION
|
|
|
for ($i = 0; $i < count($arrLP); $i++) {
|
|
|
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
|
|
|
+ if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id &&
|
|
|
+ $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
|
|
|
//this is the same!
|
|
|
if (isset($extra_info['previous_item_id']) &&
|
|
|
$extra_info['previous_item_id'] == $arrLP[$i]['id']
|
|
@@ -9417,8 +9450,8 @@ class learnpath
|
|
|
$lastPosition = null;
|
|
|
|
|
|
for ($i = 0; $i < count($arrLP); $i++) {
|
|
|
- if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) ||
|
|
|
- $arrLP[$i]['item_type'] == TOOL_LP_FINAL_ITEM
|
|
|
+ if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) &&
|
|
|
+ $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM
|
|
|
) {
|
|
|
if ((isset($extra_info['previous_item_id']) &&
|
|
|
$extra_info['previous_item_id'] == $arrLP[$i]['id']) || $action == 'add'
|
|
@@ -13246,7 +13279,7 @@ EOD;
|
|
|
|
|
|
if ($form->validate()) {
|
|
|
$values = $form->exportValues();
|
|
|
- $lastItemId = $this->get_last();
|
|
|
+ $lastItemId = $this->getLastInFirstLevel();
|
|
|
|
|
|
if (!$finalItem) {
|
|
|
$documentId = $this->create_document(
|