Browse Source

Add exercise session visibility BT#10897

jmontoya 9 years ago
parent
commit
a79264162d

+ 10 - 1
app/Migrations/Schema/V111/Version111.php

@@ -34,7 +34,16 @@ class Version111 extends AbstractMigrationChamilo
 
         $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_my_files',NULL,'radio','Platform','true','AllowMyFilesTitle','AllowMyFilesComment','',NULL, 1)");
         $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','true','Yes') ");
-        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','false0','No') ");
+        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','false','No') ");
+
+
+        $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_invisible_in_session',NULL,'radio','Session','false','ExerciseInvisibleInSessionTitle','ExerciseInvisibleInSessionComment','',NULL, 1)");
+        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','true','Yes') ");
+        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','false','No') ");
+
+        $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('configure_exercise_visibility_in_course',NULL,'radio','Session','false','ConfigureExerciseVisibilityInCourseTitle','ConfigureExerciseVisibilityInCourseComment','',NULL, 1)");
+        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','true','Yes') ");
+        $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','false','No') ");
 
     }
 

+ 27 - 0
main/course_info/infocours.php

@@ -392,6 +392,33 @@ if ($allowLPReturnLink === 'true') {
     $form->addGroup($group, '', array(get_lang("LpReturnLink")), '');
 }
 
+$exerciseInvisible = api_get_setting('exercise_invisible_in_session');
+$configureExerciseVisibility = api_get_setting('configure_exercise_visibility_in_course');
+
+if ($exerciseInvisible === 'true' &&
+    $configureExerciseVisibility === 'true'
+) {
+    $group = array(
+        $form->createElement(
+            'radio',
+            'exercise_invisible_in_session',
+            get_lang('ExerciseInvisibleInSession'),
+            get_lang('Yes'),
+            1
+        ),
+        $form->createElement(
+            'radio',
+            'exercise_invisible_in_session',
+            null,
+            get_lang('No'),
+            0
+        )
+    );
+    $form->addGroup($group, '', array(get_lang("ExerciseInvisibleInSession")), '');
+}
+
+
+
 if (is_settings_editable()) {
     $form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
 } else {

+ 46 - 0
main/exercice/exercise.php

@@ -512,6 +512,52 @@ while ($row = Database :: fetch_array($result, 'ASSOC')) {
     $exercise_list[$row['iid']] = $row;
 }
 
+if (!empty($exercise_list) &&
+    api_get_setting('exercise_invisible_in_session') === 'true'
+) {
+    if (!empty($sessionId)) {
+        $changeDefaultVisibility = true;
+        if (api_get_setting('configure_exercise_visibility_in_course') === 'true') {
+            if (api_get_course_setting('exercise_invisible_in_session') == 1) {
+                $changeDefaultVisibility = true;
+            } else {
+                $changeDefaultVisibility = false;
+            }
+        }
+
+        if ($changeDefaultVisibility) {
+            // Check exercise
+            foreach ($exercise_list as $exercise) {
+                if ($exercise['session_id'] == 0) {
+                    $visibilityInfo = api_get_item_property_info(
+                        $courseInfo,
+                        TOOL_QUIZ,
+                        $exercise['iid'],
+                        $sessionId
+                    );
+
+                    if (empty($visibilityInfo)) {
+                        // Create a record for this
+                        api_item_property_update(
+                            $courseInfo,
+                            TOOL_QUIZ,
+                            $exercise['iid'],
+                            'invisible',
+                            api_get_user_id(),
+                            0,
+                            null,
+                            '',
+                            '',
+                            $sessionId
+                        );
+                    }
+                }
+            }
+        }
+    }
+}
+
+
 if (isset($list_ordered) && !empty($list_ordered)) {
     $new_question_list = array();
     foreach ($list_ordered as $exercise_id) {

+ 1 - 1
main/exercice/exercise_admin.php

@@ -13,7 +13,7 @@ use \ChamiloSession as Session;
 require_once '../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 
-if (!api_is_allowed_to_edit(null,true)) {
+if (!api_is_allowed_to_edit(null, true)) {
     api_not_allowed(true);
 }
 

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

@@ -4994,7 +4994,8 @@ class CourseManager
             'email_alert_to_teacher_on_new_user_in_course',
             'enable_lp_auto_launch',
             'pdf_export_watermark_text',
-            'show_system_folders'
+            'show_system_folders',
+            'exercise_invisible_in_session'
         );
 
         $allowLPReturnLink = api_get_setting('allow_lp_return_link');