Bläddra i källkod

Add parameter $skipCourseList + fix message see BT#12458

jmontoyaa 8 år sedan
förälder
incheckning
046f054871
2 ändrade filer med 20 tillägg och 6 borttagningar
  1. 5 4
      main/coursecopy/copy_course.php
  2. 15 2
      main/inc/lib/course.lib.php

+ 5 - 4
main/coursecopy/copy_course.php

@@ -6,6 +6,7 @@ use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
 use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
 
 /**
+ * @todo rework file in order to use addFlash
  * @package chamilo.backup
  */
 
@@ -84,17 +85,17 @@ if (Security::check_token('post') && (
     $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
     $user_info = api_get_user_info();
     $course_info = api_get_course_info();
+
     $courseList = CourseManager::get_courses_list_by_user_id(
         $user_info['user_id'],
         false,
         false,
-        false
+        false,
+        [$course_info['real_id']]
     );
 
     if (empty($courseList)) {
-        Display::addFlash(
-            Display::return_message(get_lang('NoDestinationCoursesAvailable'))
-        );
+        Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
     } else {
         $options = array();
         foreach ($courseList as $courseItem) {

+ 15 - 2
main/inc/lib/course.lib.php

@@ -2679,19 +2679,22 @@ class CourseManager
 
     /**
      * Get list of courses for a given user
+     *
      * @param int $user_id
      * @param boolean $include_sessions Whether to include courses from session or not
      * @param boolean $adminGetsAllCourses If the user is platform admin,
      * whether he gets all the courses or just his. Note: This does *not* include all sessions
      * @param bool $loadSpecialCourses
-     * @return array    List of codes and db name
+     * @param array $skipCourseList List of course ids to skip
+     * @return array List of codes and db name
      * @author isaac flores paz
      */
     public static function get_courses_list_by_user_id(
         $user_id,
         $include_sessions = false,
         $adminGetsAllCourses = false,
-        $loadSpecialCourses = true
+        $loadSpecialCourses = true,
+        $skipCourseList = []
     ) {
         $user_id = intval($user_id);
         $urlId = api_get_current_access_url_id();
@@ -2770,6 +2773,11 @@ class CourseManager
 
         if (Database::num_rows($result)) {
             while ($row = Database::fetch_array($result, 'ASSOC')) {
+                if (!empty($skipCourseList)) {
+                    if (in_array($row['real_id'], $skipCourseList)) {
+                        continue;
+                    }
+                }
                 $course_list[] = $row;
                 $codes[] = $row['real_id'];
             }
@@ -2782,6 +2790,11 @@ class CourseManager
                     WHERE user_id = $user_id AND s.c_id = c.id";
             $r = Database::query($sql);
             while ($row = Database::fetch_array($r, 'ASSOC')) {
+                if (!empty($skipCourseList)) {
+                    if (in_array($row['real_id'], $skipCourseList)) {
+                        continue;
+                    }
+                }
                 if (!in_array($row['real_id'], $codes)) {
                     $course_list[] = $row;
                 }