示例#1
0
 public function save()
 {
     //add
     parent::save();
     //add
     if ($this->autocreate) {
         $this->track_auto_create();
     }
     $status = field_data::set_for_context_from_datarecord(CONTEXT_ELIS_TRACK, $this);
     return $status;
 }
示例#2
0
 /**
  * Save the record to the database.  This method is used to both create a
  * new record, and to update an existing record.
  *
  * @param boolean $strict_match Whether we should use the association table rather
  *                              than just check idnumbers when comparing to Moodle users
  */
 public function save($strict_match = true)
 {
     $isnew = empty($this->id);
     $now = time();
     if ($isnew) {
         $this->timecreated = $now;
     } else {
         $this->timemodified = $now;
     }
     parent::save();
     /// Synchronize Moodle data with this data.
     $this->synchronize_moodle_user(true, $isnew, $strict_match);
 }
示例#3
0
 public function save()
 {
     parent::save();
     if (isset($this->curriculum)) {
         $this->add_course_to_curricula($this->curriculum);
     }
     // Add moodle course template
     if (isset($this->location)) {
         $template = $this->coursetemplate->current();
         $template->location = $this->location;
         $template->templateclass = $this->templateclass;
         $template->courseid = $this->id;
         $template->save();
     } else {
         coursetemplate::delete_records(new field_filter('courseid', $this->id));
     }
     field_data::set_for_context_from_datarecord(CONTEXT_ELIS_COURSE, $this);
 }
示例#4
0
 public function save()
 {
     $isnew = empty($this->id);
     parent::save();
     if (!$isnew) {
         // If this setting is changed, we need to update the existing curriclum expiration values (ELIS-1172)
         if ($rs = $this->_db->get_recordset_select(curriculumstudent::TABLE, "timecompleted = 0 AND curriculumid = {$this->id}", null, 'id, userid')) {
             $timenow = time();
             foreach ($rs as $rec) {
                 $update = new stdClass();
                 $update->id = $rec->id;
                 $update->timeexpired = calculate_curriculum_expiry(NULL, $this->id, $rec->userid);
                 $update->timemodified = $timenow;
                 $this->_db->update_record(curriculumstudent::TABLE, $update);
             }
             $rs->close();
         }
     }
     field_data::set_for_context_from_datarecord(CONTEXT_ELIS_PROGRAM, $this);
 }
示例#5
0
 public function save()
 {
     $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         require_once elis::plugin_file(self::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
     }
     if (!empty($this->id)) {
         // cache the database values, so we can know if the parent changed
         $old = new userset($this->id);
         $old->load();
     }
     // figure out the right depth for the cluster
     if (empty($this->depth) || !empty($this->id)) {
         if ($this->parent == 0) {
             $this->depth = 1;
         } else {
             $this->depth = $this->parentset->depth + 1;
         }
     }
     parent::save();
     if (isset($old) && $this->parent != $old->parent) {
         $cluster_context_instance = \local_elisprogram\context\userset::instance($this->id);
         // find all subclusters and adjust their depth
         $delta_depth = $this->depth - $old->depth;
         $LIKE = $this->_db->sql_like('path', '?');
         $sql = 'UPDATE {' . self::TABLE . "}\n                       SET depth = depth + ?\n                     WHERE id IN (SELECT instanceid\n                                    FROM {context}\n                                   WHERE contextlevel = ?\n                                     AND {$LIKE})";
         $this->_db->execute($sql, array($delta_depth, CONTEXT_ELIS_USERSET, "{$cluster_context_instance->path}/%"));
         // Blank out the depth and path for associated records and child records in context table
         $sql = "UPDATE {context}\n                       SET depth=0, path=NULL\n                     WHERE id=? OR {$LIKE}";
         $this->_db->execute($sql, array($cluster_context_instance->id, "{$cluster_context_instance->path}/%"));
         // Rebuild any blanked out records in context table
         \local_eliscore\context\helper::build_all_paths(false, array(CONTEXT_ELIS_USERSET));
     }
     $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         call_user_func('userset_' . $plugin . '_update', $this);
     }
     if (isset($old)) {
         //signal that the cluster was created
         events_trigger('pm_userset_updated', $this);
     } else {
         events_trigger('pm_userset_created', $this);
     }
 }
示例#6
0
 public function save()
 {
     $isnew = empty($this->id);
     parent::save();
     if (isset($this->track) && is_array($this->track)) {
         $param['classid'] = $this->id;
         $param['courseid'] = $this->courseid;
         foreach ($this->track as $t) {
             if (trackassignment::exists(array(new field_filter('classid', $this->id), new field_filter('trackid', $t)))) {
                 continue;
             }
             $param['trackid'] = $t;
             $trackassignobj = new trackassignment($param);
             $trackassignobj->save();
         }
     }
     if (isset($this->unlink_attached_course) && isset($this->moodlecourseid)) {
         // process unlink moodle course id request
         $return = moodle_detach_class($this->id, $this->moodlecourseid);
         $this->moodlecourseid = 0;
     }
     if ($this->moodlecourseid || $this->autocreate) {
         moodle_attach_class($this->id, $this->moodlecourseid, '', true, true, $this->autocreate);
     }
     if (!$isnew) {
         if (!empty($this->oldmax) && (!$this->maxstudents || $this->oldmax < $this->maxstudents) && ($waiting = waitlist::count_records($this->id)) > 0) {
             $start = student_count_records($this->id);
             $max = $this->maxstudents ? $this->maxstudents : $start + $waiting + 1;
             //error_log("pmclass.class.php::save() oldmax = {$this->oldmax}, start = {$start}, newmax = {$this->maxstudents}, waiting = {$waiting} ... max = {$max}");
             for ($i = $start; $i < $max; $i++) {
                 $next_student = waitlist::get_next($this->id);
                 if (empty($next_student)) {
                     break;
                 }
                 $next_student->enrol();
             }
         }
     }
     field_data::set_for_context_from_datarecord(CONTEXT_ELIS_CLASS, $this);
 }