Alex Aragón 5 years ago
parent
commit
288b199179

+ 7 - 7
main/inc/lib/fileUpload.lib.php

@@ -1712,18 +1712,18 @@ function create_unexisting_directory(
                 );
 
                 if ($document_id) {
+                    $lastEditType = [
+                        0 => 'invisible',
+                        1 => 'visible',
+                        2 => 'delete',
+                    ];
                     // Update document item_property
-                    if (in_array($visibility, [0, 1, 2])) {
-                        $visibilities = [
-                            0 => 'invisible',
-                            1 => 'visible',
-                            2 => 'delete',
-                        ];
+                    if (isset($lastEditType[$visibility])) {
                         api_item_property_update(
                             $_course,
                             TOOL_DOCUMENT,
                             $document_id,
-                            $visibilities[$visibility],
+                            $lastEditType[$visibility],
                             $user_id,
                             $groupInfo,
                             $to_user_id,

+ 14 - 11
main/inc/lib/system_announcements.lib.php

@@ -757,26 +757,33 @@ class SystemAnnouncementManager
             return true;
         }
 
+        $urlJoin = '';
+        $urlCondition = '';
         $user_table = Database::get_main_table(TABLE_MAIN_USER);
         if (api_is_multiple_url_enabled()) {
             $current_access_url_id = api_get_current_access_url_id();
             $url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-            $url_condition = " INNER JOIN $url_rel_user uu ON uu.user_id = u.user_id ";
+            $urlJoin = " INNER JOIN $url_rel_user uu ON uu.user_id = u.user_id ";
+            $urlCondition = " AND access_url_id = '".$current_access_url_id."' ";
         }
 
         if ($teacher != 0 && $student == 0) {
-            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition 
-                    WHERE status = '1' ";
+            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $urlJoin 
+                    WHERE status = '1' $urlCondition";
         }
 
         if ($teacher == 0 && $student != 0) {
-            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition 
-                    WHERE status = '5' ";
+            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $urlJoin 
+                    WHERE status = '5' $urlCondition";
         }
 
         if ($teacher != 0 && $student != 0) {
-            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition 
-                    WHERE 1 = 1 ";
+            $sql = "SELECT DISTINCT u.user_id FROM $user_table u $urlJoin 
+                    WHERE 1 = 1 $urlCondition";
+        }
+
+        if (!isset($sql)) {
+            return false;
         }
 
         if (!empty($language)) {
@@ -784,10 +791,6 @@ class SystemAnnouncementManager
             $sql .= " AND language = '".Database::escape_string($language)."' ";
         }
 
-        if (api_is_multiple_url_enabled()) {
-            $sql .= " AND access_url_id = '".$current_access_url_id."' ";
-        }
-
         // Sent to active users.
         $sql .= " AND email <>'' AND active = 1 ";
 

+ 39 - 6
main/lp/learnpath.class.php

@@ -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(