Browse Source

Only show courses from the current urlId see BT#7041

Julio Montoya 11 years ago
parent
commit
979e4f5ea9
2 changed files with 26 additions and 6 deletions
  1. 3 4
      main/admin/add_courses_to_usergroup.php
  2. 23 2
      main/inc/lib/course.lib.php

+ 3 - 4
main/admin/add_courses_to_usergroup.php

@@ -94,11 +94,10 @@ if ($_POST['form_sent']) {
         exit;
     }
 }
-$data               = $usergroup->get($id);
-$course_list_in     = $usergroup->get_courses_by_usergroup($id);
-$course_list        = CourseManager::get_courses_list(0, 0, 'title');
+$data = $usergroup->get($id);
+$course_list_in = $usergroup->get_courses_by_usergroup($id);
+$course_list = CourseManager::get_courses_list(0, 0, 'title', 'asc', -1, null, api_get_current_access_url_id());
 
-//api_display_tool_title($tool_name.' ('.$session_info['name'].')');
 $elements_not_in = $elements_in= array();
 
 if (!empty($course_list)) {

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

@@ -130,10 +130,25 @@ class CourseManager
      * @param    string    The direction of the order (ASC or DESC). Optional, defaults to ASC.
      * @param    string    The visibility of the course, or all by default.
      * @param    string    If defined, only return results for which the course *title* begins with this string
+     * @return array
      */
-    public static function get_courses_list($from = 0, $howmany = 0, $orderby = 1, $orderdirection = 'ASC', $visibility = -1, $startwith = '') {
+    public static function get_courses_list(
+        $from = 0,
+        $howmany = 0,
+        $orderby = 1,
+        $orderdirection = 'ASC',
+        $visibility = -1,
+        $startwith = '',
+        $urlId = null
+    ) {
+
+        $sql = "SELECT course.* FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." course ";
+
+        if (!empty($urlId)) {
+            $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+            $sql .= " INNER JOIN $table url ON (url.course_code = course.code) ";
+        }
 
-        $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." ";
         if (!empty($startwith)) {
             $sql .= "WHERE title LIKE '".Database::escape_string($startwith)."%' ";
             if ($visibility !== -1 && $visibility == strval(intval($visibility))) {
@@ -145,6 +160,12 @@ class CourseManager
                 $sql .= " AND visibility = $visibility ";
             }
         }
+
+        if (!empty($urlId)) {
+            $urlId = intval($urlId);
+            $sql .= " AND access_url_id= $urlId";
+        }
+
         if (!empty($orderby)) {
             $sql .= " ORDER BY ".Database::escape_string($orderby)." ";
         } else {