Beispiel #1
0
 /**
  * Utility function that resets grade/completion conditions in table based
  * in data from editing form.
  *
  * @param condition_info_base $ci Condition info
  * @param object $fromform Data from form
  * @param bool $wipefirst If true, wipes existing conditions
  */
 protected static function update_from_form(condition_info_base $ci, $fromform, $wipefirst)
 {
     if ($wipefirst) {
         $ci->wipe_conditions();
     }
     foreach ($fromform->conditiongradegroup as $record) {
         if ($record['conditiongradeitemid']) {
             $ci->add_grade_condition($record['conditiongradeitemid'], unformat_float($record['conditiongrademin']), unformat_float($record['conditiongrademax']));
         }
     }
     foreach ($fromform->conditionfieldgroup as $record) {
         if ($record['conditionfield']) {
             $ci->add_user_field_condition($record['conditionfield'], $record['conditionfieldoperator'], $record['conditionfieldvalue']);
         }
     }
     if (isset($fromform->conditioncompletiongroup)) {
         foreach ($fromform->conditioncompletiongroup as $record) {
             if ($record['conditionsourcecmid']) {
                 $ci->add_completion_condition($record['conditionsourcecmid'], $record['conditionrequiredcompletion']);
             }
         }
     }
 }
 /**
  * Used to notify the completion system (if necessary) that a user's grade
  * has changed, and clear up a possible score cache.
  *
  * @param bool $deleted True if grade was actually deleted
  */
 function notify_changed($deleted)
 {
     global $CFG;
     // Inform conditionlib since it may cache the grades for conditional availability of modules or sections.
     if (!empty($CFG->enableavailability)) {
         require_once $CFG->libdir . '/conditionlib.php';
         condition_info_base::inform_grade_changed($this, $deleted);
     }
     require_once $CFG->libdir . '/completionlib.php';
     // Bail out immediately if completion is not enabled for site (saves loading
     // grade item & requiring the restore stuff).
     if (!completion_info::is_enabled_for_site()) {
         return;
     }
     // Ignore during restore, as completion data will be updated anyway and
     // doing it now will result in incorrect dates (it will say they got the
     // grade completion now, instead of the correct time).
     if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
         return;
     }
     // Load information about grade item
     $this->load_grade_item();
     // Only course-modules have completion data
     if ($this->grade_item->itemtype != 'mod') {
         return;
     }
     // Use $COURSE if available otherwise get it via item fields
     $course = get_course($this->grade_item->courseid, false);
     // Bail out if completion is not enabled for course
     $completion = new completion_info($course);
     if (!$completion->is_enabled()) {
         return;
     }
     // Get course-module
     $cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid);
     // If the course-module doesn't exist, display a warning...
     if (!$cm) {
         // ...unless the grade is being deleted in which case it's likely
         // that the course-module was just deleted too, so that's okay.
         if (!$deleted) {
             debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'");
         }
         return;
     }
     // Pass information on to completion system
     $completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted);
 }
 /**
  * Used to notify the completion system (if necessary) that a user's grade
  * has changed, and clear up a possible score cache.
  *
  * @param bool $deleted True if grade was actually deleted
  */
 function notify_changed($deleted)
 {
     global $CFG;
     // Ignore during restore
     // TODO There should be a proper way to determine when we are in restore
     // so that this hack looking for a $restore global is not needed.
     global $restore;
     if (!empty($restore->backup_unique_code)) {
         return;
     }
     // Inform conditionlib since it may cache the grades for conditional availability of modules or sections.
     if (!empty($CFG->enableavailability)) {
         require_once $CFG->libdir . '/conditionlib.php';
         condition_info_base::inform_grade_changed($this, $deleted);
     }
     require_once $CFG->libdir . '/completionlib.php';
     // Bail out immediately if completion is not enabled for site (saves loading
     // grade item below)
     if (!completion_info::is_enabled_for_site()) {
         return;
     }
     // Load information about grade item
     $this->load_grade_item();
     // Only course-modules have completion data
     if ($this->grade_item->itemtype != 'mod') {
         return;
     }
     // Use $COURSE if available otherwise get it via item fields
     $course = get_course($this->grade_item->courseid, false);
     // Bail out if completion is not enabled for course
     $completion = new completion_info($course);
     if (!$completion->is_enabled()) {
         return;
     }
     // Get course-module
     $cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid);
     // If the course-module doesn't exist, display a warning...
     if (!$cm) {
         // ...unless the grade is being deleted in which case it's likely
         // that the course-module was just deleted too, so that's okay.
         if (!$deleted) {
             debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'");
         }
         return;
     }
     // Pass information on to completion system
     $completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted);
 }