Browse Source

Implementation of "hidden" visibility for courses - still misses visibility switch for courses in session for platform admin - refs BT#6585

Yannick Warnier 11 years ago
parent
commit
7fcbd56b4a

+ 1 - 0
main/admin/course_add.php

@@ -92,6 +92,7 @@ $group[]= $form->createElement('radio', 'visibility', get_lang('CourseAccess'),
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
+$group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
 
 $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
 

+ 1 - 0
main/admin/course_edit.php

@@ -157,6 +157,7 @@ $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"),
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
+$group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
 $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
 
 $group = array();

+ 4 - 0
main/admin/course_list.php

@@ -148,6 +148,9 @@ function get_course_visibility_icon($v) {
         case 3:
             return Display::return_icon('bullet_blue.gif', get_lang('OpenToTheWorld'), array('style' => $style));
             break;
+        case 4:
+            return Display::return_icon('bullet_grey.gif', get_lang('CourseVisibilityHidden'), array('style' => $style));
+            break;
         default:
             return '';
     }
@@ -192,6 +195,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
     $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
     $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
     $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
+    $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
     $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
     $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
     $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);

+ 1 - 1
main/auth/courses_controller.php

@@ -173,7 +173,7 @@ class CoursesController { // extends Controller {
         $data = array();
         $courseInfo = api_get_course_info($course_code);
         // The course must be open in order to access the auto subscription
-        if (in_array($courseInfo['visibility'], array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED))) {
+        if (in_array($courseInfo['visibility'], array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED, COURSE_VISIBILITY_HIDDEN))) {
             $error = get_lang('SubscribingNotAllowed');
             //$message = get_lang('SubscribingNotAllowed');
         } else {

+ 4 - 0
main/course_info/infocours.php

@@ -196,6 +196,10 @@ $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"),
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
 $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
+// The "hidden" visibility is only available to portal admins
+if (api_is_platform_admin()) {
+    $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
+}
 $form->addGroup($group, '', array(get_lang("CourseAccess"), get_lang("CourseAccessConfigTip")), '');
 
 $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";

BIN
main/img/bullet_grey.gif


+ 13 - 4
main/inc/lib/course.lib.php

@@ -2961,6 +2961,9 @@ class CourseManager {
             if ($number_of_courses > 0) {
                 while ($course = Database::fetch_array($rs_special_course)) {
                     $course_info = api_get_course_info($course['code']);
+                    if ($course_info['visibility'] != COURSE_VISIBILITY_HIDDEN) {
+                        continue;
+                    }
                     $params = array();
                     // Get notifications.
                     //$course['id_session']   = null;
@@ -3108,6 +3111,9 @@ class CourseManager {
         // Browse through all courses.
         while ($course = Database::fetch_array($result)) {
             $course_info = api_get_course_info($course['code']);
+            if ($course_info['visibility'] == COURSE_VISIBILITY_HIDDEN) {
+                continue;
+            }
             //$course['id_session'] = null;
             $course_info['id_session'] = null;
             $course_info['status'] = $course['status'];
@@ -3281,7 +3287,7 @@ class CourseManager {
         $session_title = '';
 
         if ($session_accessible) {
-            if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
+            if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) {
                 if (!$nosession) {
                     if (empty($course_info['id_session'])) {
                         $course_info['id_session'] = 0;
@@ -3308,7 +3314,7 @@ class CourseManager {
 
         $params['right_actions'] = '';
 
-        if ($course_visibility != COURSE_VISIBILITY_CLOSED) {
+        if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
             if ($load_dirs) {
                 $params['right_actions'] .= '<a id="document_preview_'.$course_info['real_id'].'_'.$course_info['id_session'].'" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
                 $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_'.$course_info['id_session'], 'class'=>'document_preview_container'));
@@ -3338,7 +3344,7 @@ class CourseManager {
         $session_title .= isset($course['special_course']) ? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
 
         // Display the "what's new" icons
-        if ($course_visibility != COURSE_VISIBILITY_CLOSED) {
+        if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
             $session_title .= Display :: show_notification($course_info);
         }
 
@@ -3802,7 +3808,7 @@ class CourseManager {
               "  WHERE   u.access_url_id = ".$_configuration['access_url']." AND".
               "          login_course_date <= now() AND ".
               "          login_course_date > DATE_SUB(now(), INTERVAL $days DAY) AND".
-              "          visibility <> '".COURSE_VISIBILITY_CLOSED."'".
+              "          visibility <> '".COURSE_VISIBILITY_CLOSED."' AND visibility <> '".COURSE_VISIBILITY_HIDDEN."'".
               "  GROUP BY course_code".
               "  ORDER BY course_count DESC".
               "  LIMIT $limit";
@@ -3925,6 +3931,9 @@ class CourseManager {
         if (!isset($course['real_id']) && empty($course['real_id'])) {
             $course = api_get_course_info($course['code']);
         }
+        if ($course['visibility'] != COURSE_VISIBILITY_HIDDEN) {
+            return array();
+        }
 
         $is_admin = api_is_platform_admin_by_id($uid);
         $options = array();

+ 5 - 0
main/inc/lib/login.lib.php

@@ -673,6 +673,11 @@ class Login
                             $is_allowed_in_course = true;
                         }
                         break;
+                    case COURSE_VISIBILITY_HIDDEN: //4
+                        if ($is_platformAdmin) {
+                            $is_allowed_in_course = true;
+                        }
+                        break;
                 }
             }
 

+ 9 - 1
main/inc/lib/main_api.lib.php

@@ -64,7 +64,8 @@ define('COURSE_VISIBILITY_REGISTERED', 1);
 define('COURSE_VISIBILITY_OPEN_PLATFORM', 2);
 /** Open for the whole world */
 define('COURSE_VISIBILITY_OPEN_WORLD', 3);
-
+/** Invisible to all except admin */
+define('COURSE_VISIBILITY_HIDDEN', 4);
 
 // SESSION VISIBILITY CONSTANTS
 define('SESSION_VISIBLE_READ_ONLY', 1);
@@ -887,6 +888,11 @@ function api_protect_course_script($print_headers = false, $allow_session_admins
     		case COURSE_VISIBILITY_OPEN_WORLD: //Open - access allowed for the whole world - 3
     			$is_visible = true;
     			break;
+            case COURSE_VISIBILITY_HIDDEN: //Completely closed: the course is only accessible to the teachers. - 0
+                if (api_is_platform_admin()) {
+                    $is_visible = true;
+                }
+                break;
     	}
         //If pasword is set and user is not registered to the course then the course is not visible
         if ($is_allowed_in_course == false & isset($course_info['registration_code']) && !empty($course_info['registration_code'])) {
@@ -4824,6 +4830,8 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
         case COURSE_VISIBILITY_REGISTERED:
         case COURSE_VISIBILITY_CLOSED:
             return $is_platformAdmin || $is_courseMember || $is_courseAdmin;
+        case COURSE_VISIBILITY_HIDDEN:
+            return $is_platformAdmin;
     }
     return false;
 }

+ 1 - 1
main/inc/lib/social.lib.php

@@ -460,7 +460,7 @@ class SocialManager extends UserManager
         $result .= $s_htlm_status_icon;
 
         //show a hyperlink to the course, unless the course is closed and user is not course admin
-        if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
+        if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) {
             $result .= '<a href="javascript:void(0)" id="ln_'.$count.'"  onclick=toogle_course(this,\''.$course_id.'\');>&nbsp;'.$course_title.'</a>';
         } else {
             $result .= $course_title." "." ".get_lang('CourseClosed')."";

+ 6 - 4
main/inc/lib/userportal.lib.php

@@ -497,7 +497,7 @@ class IndexManager {
 
 			foreach ($course_list as $course) {
 				// $setting_show_also_closed_courses
-
+                if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; }
 				if (!$setting_show_also_closed_courses) {
 					// If we do not show the closed courses
 					// we only show the courses that are open to the world (to everybody)
@@ -532,15 +532,17 @@ class IndexManager {
 					$courses_list_string .= "<li>";
 					if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
                         || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
-                        || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
+                        || ($user_identified && key_exists($course['code'], $courses_of_user)
+                            && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
                         || $courses_of_user[$course['code']]['status'] == '1'
                         || api_is_platform_admin()) {
                             $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
                         }
-                        $courses_list_string .= $course['title'];
+                    $courses_list_string .= $course['title'];
                     if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
 						|| ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
-						|| ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
+						|| ($user_identified && key_exists($course['code'], $courses_of_user)
+                            && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
 	                        || $courses_of_user[$course['code']]['status'] == '1'
 						|| api_is_platform_admin()) {
                         $courses_list_string .= '</a><br />';

+ 1 - 1
main/template/default/auth/courses_categories.php

@@ -147,7 +147,7 @@ $stok = Security::get_token();
 
             foreach ($browse_courses_in_category as $course) {
                 // if course is closed, don't show it.
-                if ($course['visibility'] == COURSE_VISIBILITY_CLOSED) {
+                if ($course['visibility'] == COURSE_VISIBILITY_CLOSED || $course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
                     continue;
                 }
                 // course isn't closed

+ 1 - 0
plugin/dashboard/block_global_info/block_global_info.class.php

@@ -142,6 +142,7 @@ class BlockGlobalInfo extends Block
             array(get_lang('NumberOfCoursesOpen'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_PLATFORM.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_PLATFORM).'</a>'),
             array(get_lang('NumberOfCoursesPrivate'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_REGISTERED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_REGISTERED).'</a>'),
             array(get_lang('NumberOfCoursesClosed'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_CLOSED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_CLOSED).'</a>')
+            array(get_lang('NumberOfCoursesHidden'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_HIDDEN.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_HIDDEN).'</a>')
         );
         return $global_info;
     }