Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'wip-MDL-26781' of git://github.com/sammarshallou/moodle

  • Loading branch information...
commit 3bfb75a9eda182274c52c055d5200081c7d9b5c3 2 parents 7b2dde5 + adaeccb
Petr Škoda authored March 21, 2011
3  admin/settings/subsystems.php
@@ -37,9 +37,10 @@
37 37
     $optionalsubsystems->add(new admin_setting_configcheckbox('enablecompletion',
38 38
         get_string('enablecompletion','completion'),
39 39
         get_string('configenablecompletion','completion'), 0));
40  
-    $optionalsubsystems->add(new admin_setting_configcheckbox('enableavailability',
  40
+    $optionalsubsystems->add($checkbox = new admin_setting_configcheckbox('enableavailability',
41 41
         get_string('enableavailability','condition'),
42 42
         get_string('configenableavailability','condition'), 0));
  43
+    $checkbox->set_affects_modinfo(true);
43 44
 
44 45
     $optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', get_string('enableplagiarism','plagiarism'), get_string('configenableplagiarism','plagiarism'), 0));
45 46
 }
30  course/lib.php
@@ -1082,20 +1082,32 @@ function get_array_of_activities($courseid) {
1082 1082
                    $mod[$seq]->id               = $rawmods[$seq]->instance;
1083 1083
                    $mod[$seq]->cm               = $rawmods[$seq]->id;
1084 1084
                    $mod[$seq]->mod              = $rawmods[$seq]->modname;
  1085
+
  1086
+                    // Oh dear. Inconsistent names left here for backward compatibility.
1085 1087
                    $mod[$seq]->section          = $section->section;
  1088
+                   $mod[$seq]->sectionid        = $rawmods[$seq]->section;
  1089
+
  1090
+                   $mod[$seq]->module           = $rawmods[$seq]->module;
  1091
+                   $mod[$seq]->added            = $rawmods[$seq]->added;
  1092
+                   $mod[$seq]->score            = $rawmods[$seq]->score;
1086 1093
                    $mod[$seq]->idnumber         = $rawmods[$seq]->idnumber;
1087 1094
                    $mod[$seq]->visible          = $rawmods[$seq]->visible;
  1095
+                   $mod[$seq]->visibleold       = $rawmods[$seq]->visibleold;
1088 1096
                    $mod[$seq]->groupmode        = $rawmods[$seq]->groupmode;
1089 1097
                    $mod[$seq]->groupingid       = $rawmods[$seq]->groupingid;
1090 1098
                    $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
1091 1099
                    $mod[$seq]->indent           = $rawmods[$seq]->indent;
1092 1100
                    $mod[$seq]->completion       = $rawmods[$seq]->completion;
1093 1101
                    $mod[$seq]->extra            = "";
1094  
-                   if(!empty($CFG->enableavailability)) {
  1102
+                   $mod[$seq]->completiongradeitemnumber =
  1103
+                           $rawmods[$seq]->completiongradeitemnumber;
  1104
+                   $mod[$seq]->completionview   = $rawmods[$seq]->completionview;
  1105
+                   $mod[$seq]->completionexpected = $rawmods[$seq]->completionexpected;
  1106
+                   $mod[$seq]->availablefrom    = $rawmods[$seq]->availablefrom;
  1107
+                   $mod[$seq]->availableuntil   = $rawmods[$seq]->availableuntil;
  1108
+                   $mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
  1109
+                   if (!empty($CFG->enableavailability)) {
1095 1110
                        condition_info::fill_availability_conditions($rawmods[$seq]);
1096  
-                       $mod[$seq]->availablefrom    = $rawmods[$seq]->availablefrom;
1097  
-                       $mod[$seq]->availableuntil   = $rawmods[$seq]->availableuntil;
1098  
-                       $mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
1099 1111
                        $mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion;
1100 1112
                        $mod[$seq]->conditionsgrade  = $rawmods[$seq]->conditionsgrade;
1101 1113
                    }
@@ -1152,13 +1164,19 @@ function get_array_of_activities($courseid) {
1152 1164
                    // 'empty'. This list corresponds to code in the cm_info constructor.
1153 1165
                    foreach(array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
1154 1166
                            'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content',
1155  
-                           'icon', 'iconcomponent', 'customdata', 'availablefrom', 'availableuntil',
1156  
-                           'conditionscompletion', 'conditionsgrade') as $property) {
  1167
+                           'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom',
  1168
+                           'availableuntil', 'conditionscompletion', 'conditionsgrade',
  1169
+                           'completionview', 'completionexpected', 'score') as $property) {
1157 1170
                        if (property_exists($mod[$seq], $property) &&
1158 1171
                                empty($mod[$seq]->{$property})) {
1159 1172
                            unset($mod[$seq]->{$property});
1160 1173
                        }
1161 1174
                    }
  1175
+                   // Special case: this value is usually set to null, but may be 0
  1176
+                   if (property_exists($mod[$seq], 'completiongradeitemnumber') &&
  1177
+                           is_null($mod[$seq]->completiongradeitemnumber)) {
  1178
+                       unset($mod[$seq]->completiongradeitemnumber);
  1179
+                   }
1162 1180
                }
1163 1181
             }
1164 1182
         }
16  lib/adminlib.php
@@ -1382,6 +1382,8 @@ public function show_save() {
1382 1382
     public $plugin; // null means main config table
1383 1383
     /** @var bool true indicates this setting does not actually save anything, just information */
1384 1384
     public $nosave = false;
  1385
+    /** @var bool if set, indicates that a change to this setting requires rebuild course cache */
  1386
+    public $affectsmodinfo = false;
1385 1387
 
1386 1388
     /**
1387 1389
      * Constructor
@@ -1444,6 +1446,14 @@ public function get_id() {
1444 1446
     }
1445 1447
 
1446 1448
     /**
  1449
+     * @param bool $affectsmodinfo If true, changes to this setting will
  1450
+     *   cause the course cache to be rebuilt
  1451
+     */
  1452
+    public function set_affects_modinfo($affectsmodinfo) {
  1453
+        $this->affectsmodinfo = $affectsmodinfo;
  1454
+    }
  1455
+
  1456
+    /**
1447 1457
      * Returns the config if possible
1448 1458
      *
1449 1459
      * @return mixed returns config if successful else null
@@ -1489,6 +1499,12 @@ public function config_write($name, $value) {
1489 1499
         // store change
1490 1500
         set_config($name, $value, $this->plugin);
1491 1501
 
  1502
+        // Some admin settings affect course modinfo
  1503
+        if ($this->affectsmodinfo) {
  1504
+            // Clear course cache for all courses
  1505
+            rebuild_course_cache(0, true);
  1506
+        }
  1507
+
1492 1508
         // log change
1493 1509
         $log = new stdClass();
1494 1510
         $log->userid       = during_initial_install() ? 0 :$USER->id; // 0 as user id during install
125  lib/modinfolib.php
@@ -340,13 +340,35 @@ class cm_info extends stdClass  {
340 340
     public $idnumber;
341 341
 
342 342
     /**
343  
-     * Visible setting (0 or 1; if this is 0, students cannot see/access the activity)  - from
  343
+     * Time that this course-module was added (unix time) - from course_modules table
  344
+     * @var int
  345
+     */
  346
+    public $added;
  347
+
  348
+    /**
  349
+     * This variable is not used and is included here only so it can be documented.
  350
+     * Once the database entry is removed from course_modules, it should be deleted
  351
+     * here too.
  352
+     * @var int
  353
+     * @deprecated Do not use this variable
  354
+     */
  355
+    public $score;
  356
+
  357
+    /**
  358
+     * Visible setting (0 or 1; if this is 0, students cannot see/access the activity) - from
344 359
      * course_modules table
345 360
      * @var int
346 361
      */
347 362
     public $visible;
348 363
 
349 364
     /**
  365
+     * Old visible setting (if the entire section is hidden, the previous value for
  366
+     * visible is stored in this field) - from course_modules table
  367
+     * @var int
  368
+     */
  369
+    public $visibleold;
  370
+
  371
+    /**
350 372
      * Group mode (one of the constants NONE, SEPARATEGROUPS, or VISIBLEGROUPS) - from
351 373
      * course_modules table
352 374
      * @var int
@@ -381,6 +403,27 @@ class cm_info extends stdClass  {
381 403
     public $completion;
382 404
 
383 405
     /**
  406
+     * Set to the item number (usually 0) if completion depends on a particular
  407
+     * grade of this activity, or null if completion does not depend on a grade - from
  408
+     * course_modules table
  409
+     * @var mixed
  410
+     */
  411
+    public $completiongradeitemnumber;
  412
+
  413
+    /**
  414
+     * 1 if 'on view' completion is enabled, 0 otherwise - from course_modules table
  415
+     * @var int
  416
+     */
  417
+    public $completionview;
  418
+
  419
+    /**
  420
+     * Set to a unix time if completion of this activity is expected at a
  421
+     * particular time, 0 if no time set - from course_modules table
  422
+     * @var int
  423
+     */
  424
+    public $completionexpected;
  425
+
  426
+    /**
384 427
      * Available date for this activity (0 if not set, or set to seconds since epoch; before this
385 428
      * date, activity does not display to students) - from course_modules table
386 429
      * @var int
@@ -430,6 +473,12 @@ class cm_info extends stdClass  {
430 473
     public $modname;
431 474
 
432 475
     /**
  476
+     * ID of module - from course_modules table
  477
+     * @var int
  478
+     */
  479
+    public $module;
  480
+
  481
+    /**
433 482
      * Name of module instance for display on page e.g. 'General discussion forum' - from cached
434 483
      * data in modinfo field
435 484
      * @var string
@@ -444,6 +493,12 @@ class cm_info extends stdClass  {
444 493
     public $sectionnum;
445 494
 
446 495
     /**
  496
+     * Section id - from course_modules table
  497
+     * @var int
  498
+     */
  499
+    public $section;
  500
+
  501
+    /**
447 502
      * Availability conditions for this course-module based on the completion of other
448 503
      * course-modules (array from other course-module id to required completion state for that
449 504
      * module) - from cached data in modinfo field
@@ -786,12 +841,11 @@ public function __construct(course_modinfo $modinfo, $course, $mod, $info) {
786 841
         $this->idnumber         = isset($mod->idnumber) ? $mod->idnumber : '';
787 842
         $this->name             = $mod->name;
788 843
         $this->visible          = $mod->visible;
789  
-        $this->sectionnum       = $mod->section;
  844
+        $this->sectionnum       = $mod->section; // Note weirdness with name here
790 845
         $this->groupmode        = isset($mod->groupmode) ? $mod->groupmode : 0;
791 846
         $this->groupingid       = isset($mod->groupingid) ? $mod->groupingid : 0;
792 847
         $this->groupmembersonly = isset($mod->groupmembersonly) ? $mod->groupmembersonly : 0;
793 848
         $this->indent           = isset($mod->indent) ? $mod->indent : 0;
794  
-        $this->completion       = isset($mod->completion) ? $mod->completion : 0;
795 849
         $this->extra            = isset($mod->extra) ? $mod->extra : '';
796 850
         $this->extraclasses     = isset($mod->extraclasses) ? $mod->extraclasses : '';
797 851
         $this->onclick          = isset($mod->onclick) ? $mod->onclick : '';
@@ -809,22 +863,32 @@ public function __construct(course_modinfo $modinfo, $course, $mod, $info) {
809 863
             $this->extra = '';
810 864
         }
811 865
 
812  
-        if (!empty($CFG->enableavailability)) {
813  
-            // We must have completion information from modinfo. If it's not
814  
-            // there, cache needs rebuilding
815  
-            if (!isset($mod->showavailability)) {
816  
-                throw new modinfo_rebuild_cache_exception(
817  
-                        'enableavailability option was changed; rebuilding '.
818  
-                        'cache for course ' . $course->id);
819  
-            }
820  
-            $this->showavailability = $mod->showavailability;
821  
-            $this->availablefrom = isset($mod->availablefrom) ? $mod->availablefrom : 0;
822  
-            $this->availableuntil = isset($mod->availableuntil) ? $mod->availableuntil : 0;
823  
-            $this->conditionscompletion = isset($mod->conditionscompletion)
824  
-                    ? $mod->conditionscompletion : array();
825  
-            $this->conditionsgrade = isset($mod->conditionsgrade)
826  
-                    ? $mod->conditionsgrade : array();
827  
-        }
  866
+        // Note: These fields from $cm were not present in cm_info in Moodle
  867
+        // 2.0.2 and prior. They may not be available if course cache hasn't
  868
+        // been rebuilt since then.
  869
+        $this->section = isset($mod->sectionid) ? $mod->sectionid : 0;
  870
+        $this->module = isset($mod->module) ? $mod->module : 0;
  871
+        $this->added = isset($mod->added) ? $mod->added : 0;
  872
+        $this->score = isset($mod->score) ? $mod->score : 0;
  873
+        $this->visibleold = isset($mod->visibleold) ? $mod->visibleold : 0;
  874
+
  875
+        // Note: it saves effort and database space to always include the
  876
+        // availability and completion fields, even if availability or completion
  877
+        // are actually disabled
  878
+        $this->completion = isset($mod->completion) ? $mod->completion : 0;
  879
+        $this->completiongradeitemnumber = isset($mod->completiongradeitemnumber)
  880
+                ? $mod->completiongradeitemnumber : null;
  881
+        $this->completionview = isset($mod->completionview)
  882
+                ? $mod->completionview : 0;
  883
+        $this->completionexpected = isset($mod->completionexpected)
  884
+                ? $mod->completionexpected : 0;
  885
+        $this->showavailability = isset($mod->showavailability) ? $mod->showavailability : 0;
  886
+        $this->availablefrom = isset($mod->availablefrom) ? $mod->availablefrom : 0;
  887
+        $this->availableuntil = isset($mod->availableuntil) ? $mod->availableuntil : 0;
  888
+        $this->conditionscompletion = isset($mod->conditionscompletion)
  889
+                ? $mod->conditionscompletion : array();
  890
+        $this->conditionsgrade = isset($mod->conditionsgrade)
  891
+                ? $mod->conditionsgrade : array();
828 892
 
829 893
         // Get module plural name.
830 894
         // TODO This was a very old performance hack and should now be removed as the information
@@ -964,18 +1028,6 @@ private function obtain_view_data() {
964 1028
 
965 1029
 
966 1030
 /**
967  
- * Special exception that may only be thrown within the constructor for course_modinfo to
968  
- * indicate that the cache needs to be rebuilt. Not for use anywhere else.
969  
- */
970  
-class modinfo_rebuild_cache_exception extends coding_exception {
971  
-    function __construct($why) {
972  
-        // If it ever escapes, that's a code bug
973  
-        parent::__construct('This exception should be caught by code', $why);
974  
-    }
975  
-}
976  
-
977  
-
978  
-/**
979 1031
  * Returns reference to full info about modules in course (including visibility).
980 1032
  * Cached and as fast as possible (0 or 1 db query).
981 1033
  *
@@ -1016,16 +1068,7 @@ function get_fast_modinfo(&$course, $userid=0) {
1016 1068
 
1017 1069
     unset($cache[$course->id]); // prevent potential reference problems when switching users
1018 1070
 
1019  
-    try {
1020  
-        $cache[$course->id] = new course_modinfo($course, $userid);
1021  
-    } catch (modinfo_rebuild_cache_exception $e) {
1022  
-        debugging($e->debuginfo);
1023  
-        rebuild_course_cache($course->id, true);
1024  
-        $course = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
1025  
-        // This second time we don't catch the exception - if you request cache rebuild twice
1026  
-        // in a row, that's a bug => coding_exception
1027  
-        $cache[$course->id] = new course_modinfo($course, $userid);
1028  
-    }
  1071
+    $cache[$course->id] = new course_modinfo($course, $userid);
1029 1072
 
1030 1073
     // Ensure cache does not use too much RAM
1031 1074
     if (count($cache) > MAX_MODINFO_CACHE_SIZE) {

0 notes on commit 3bfb75a

Please sign in to comment.
Something went wrong with that request. Please try again.