コード例 #1
0
 public function save()
 {
     $isnew = empty($this->id);
     parent::save();
     // TO-DO: not sure how much of code from old data_update_record() is needed here
     if (!$isnew && !empty($this->properties)) {
         $record = new stdClass();
         foreach ($this->properties as $prop => $type) {
             if (!isset($this->{$prop})) {
                 continue;
             }
             if ($prop == 'timemodified') {
                 $record->{$prop} = time();
             } else {
                 switch ($type) {
                     case 'int':
                         $record->{$prop} = $this->_db->clean_int($this->{$prop});
                         break;
                     case 'string':
                         $record->{$prop} = $this->_db->clean_text($this->{$prop});
                         break;
                     case 'html':
                         $record->{$prop} = $this->_db->clean_html($this->{$prop});
                         break;
                 }
             }
         }
         $this->_db->update_record($this->table, $record);
     }
 }
コード例 #2
0
 /**
  * Save the record to the database.  This method is used to both create a
  * new record, and to update an existing record.
  */
 public function save()
 {
     $trigger = false;
     if (!isset($this->id)) {
         $trigger = true;
     }
     parent::save();
     if ($trigger) {
         $usass = new stdClass();
         $usass->userid = $this->userid;
         $usass->clusterid = $this->clusterid;
         events_trigger('cluster_assigned', $usass);
     }
 }
コード例 #3
0
ファイル: student.class.php プロジェクト: jamesmcq/elis
 function save()
 {
     // ELIS-3722 -- We need to prevent duplicate records when adding new student LO grade records
     if ($this->_dbfield_id !== parent::$_unset || $this->_dbfield_id == parent::$_unset && !$this->duplicate_check()) {
         parent::save();
     } else {
         //debugging('student_grade::save() - LO grade already saved!', DEBUG_DEVELOPER);
     }
 }
コード例 #4
0
 /**
  * Perform parent delete
  */
 public function delete()
 {
     parent::delete();
 }
コード例 #5
0
ファイル: workflow.class.php プロジェクト: jamesmcq/elis
 /**
  * Saves (inserts or updates) a workflow data record to the database.
  */
 public function save()
 {
     $this->timemodified = time();
     parent::save();
 }
コード例 #6
0
ファイル: track.class.php プロジェクト: jamesmcq/elis
 /**
  * Assign a class to a track, this function also creates
  * and assigns the class to the curriculum default track
  *
  * @return TODO: add meaningful return value
  */
 function save()
 {
     //add()
     if (empty($this->courseid)) {
         $this->courseid = $this->_db->get_field(pmclass::TABLE, 'courseid', array('id' => $this->classid));
     }
     if ((empty($this->trackid) or empty($this->classid) or empty($this->courseid)) and empty(elis::$config->local_elisprogram->userdefinedtrack)) {
         cm_error('trackid and classid have not been properly initialized');
         return false;
     } else {
         if ((empty($this->courseid) or empty($this->classid)) and elis::$config->local_elisprogram->userdefinedtrack) {
             cm_error('courseid has not been properly initialized');
         }
     }
     if (!isset($this->id) && $this->is_class_assigned_to_track()) {
         //trying to re-add an existing association
         return;
     }
     // Determine whether class is required
     $curcrsobj = new curriculumcourse(array('curriculumid' => $this->track->curid, 'courseid' => $this->courseid));
     // TBV: was $this->classid
     // insert assignment record
     parent::save();
     //updated for ELIS2 from $this->data_insert_record()
     if ($this->autoenrol && $this->is_autoenrollable()) {
         // autoenrol all users in the track
         // ELIS-7582
         @set_time_limit(0);
         $users = usertrack::get_users($this->trackid);
         foreach ($users as $user) {
             // ELIS-3460: Must check pre-requisites ...
             if (!$curcrsobj->prerequisites_satisfied($user->userid)) {
                 //error_log("/local/elisprogram/lib/data/track.class.php:trackassignment::save(); pre-requisites NOT satisfied for course: {$this->courseid}, curriculum: {$this->track->curid}");
                 continue;
             }
             $now = time();
             $stu_record = new object();
             $stu_record->userid = $user->userid;
             $stu_record->user_idnumber = $user->idnumber;
             $stu_record->classid = $this->classid;
             $stu_record->enrolmenttime = $now;
             $enrolment = new student($stu_record);
             // check enrolment limits
             try {
                 $enrolment->save();
             } catch (pmclass_enrolment_limit_validation_exception $e) {
                 // autoenrol into waitlist
                 $wait_record = new object();
                 $wait_record->userid = $user->userid;
                 $wait_record->classid = $this->classid;
                 $wait_record->enrolmenttime = $now;
                 $wait_record->timecreated = $now;
                 $wait_record->position = 0;
                 $wait_list = new waitlist($wait_record);
                 $wait_list->save();
             } catch (Exception $e) {
                 $param = array('message' => $e->getMessage());
                 echo cm_error(get_string('record_not_created_reason', 'local_elisprogram', $param));
             }
         }
     }
     events_trigger('pm_track_class_associated', $this);
 }
コード例 #7
0
ファイル: usertrack.class.php プロジェクト: jamesmcq/elis
 /**
  * Unenrols a user from a track.
  */
 function unenrol()
 {
     //return $this->data_delete_record();
     parent::delete();
 }
コード例 #8
0
ファイル: instructor.class.php プロジェクト: jamesmcq/elis
 /**
  * Perform parent delete and trigger unassigned event.
  */
 public function delete()
 {
     parent::delete();
     events_trigger('crlm_instructor_unassigned', $this);
 }
コード例 #9
0
 public function save()
 {
     $isnew = empty($this->id);
     $now = time();
     if ($isnew) {
         $this->timecreated = $now;
         if (!empty(elis::$config->local_elisprogram->enable_curriculum_expiration) && elis::$config->local_elisprogram->curriculum_expiration_start == CURR_EXPIRE_ENROL_START && $this->_db->get_field(curriculum::TABLE, 'frequency', array('id' => $this->curriculumid))) {
             // We need to load this record from the DB fresh so we don't accidentally overwrite legitimate
             // values with something empty when we update the record.
             $this->timecreated = time();
             $timeexpired = calculate_curriculum_expiry($this);
             if ($timeexpired > 0) {
                 $this->timeexpired = $timeexpired;
             }
         }
     }
     $this->timemodified = $now;
     parent::save();
 }
コード例 #10
0
ファイル: waitlist.class.php プロジェクト: jamesmcq/elis
 /**
  *
  */
 public function save()
 {
     $new = false;
     try {
         validation_helper::is_unique_userid_classid($this);
     } catch (Exception $e) {
         // already on waitlist
         return true;
     }
     if (!isset($this->id)) {
         $new = true;
         if (empty($this->position)) {
             $max = $this->_db->get_field(waitlist::TABLE, 'MAX(position)', array('classid' => $this->classid));
             $this->position = $max + 1;
         }
     }
     parent::save();
     $sendnotification = !empty(elis::$config->local_elisprogram->notify_addedtowaitlist_user) ? true : false;
     if ($new && $sendnotification === true) {
         $subject = get_string('waitlist', self::LANG_FILE);
         $pmclass = new pmclass($this->classid);
         $sparam = new stdClass();
         $sparam->idnumber = $pmclass->idnumber;
         $message = get_string('added_to_waitlist_message', self::LANG_FILE, $sparam);
         $cuser = new user($this->userid);
         $cuser->load();
         $from = get_admin();
         notification::notify($message, $cuser, $from);
         //email_to_user($user, $from, $subject, $message); // *TBD*
     }
 }
コード例 #11
0
ファイル: customfield.class.php プロジェクト: jamesmcq/elis
 function delete()
 {
     //filter used in general
     $filter = new field_filter('categoryid', $this->id);
     //delete fields that belong to this category
     field::delete_records($filter, $this->_db);
     //delete the record associating the category to a context level
     field_category_contextlevel::delete_records($filter, $this->_db);
     //delete the actual category record
     parent::delete();
 }
コード例 #12
0
 public function save()
 {
     parent::save();
     events_trigger('crlm_curriculum_course_associated', $this);
 }
コード例 #13
0
ファイル: clustertrack.class.php プロジェクト: jamesmcq/elis
 /**
  * Disassociates a cluster from a track.
  */
 public function delete()
 {
     if ($this->autounenrol) {
         // ELIS-7582
         @set_time_limit(0);
         // Unenrol all users in the cluster from the track (unless they are
         // in another cluster associated with the track and autoenrolled by
         // that cluster).  Only work on users that were autoenrolled in the
         // track by the cluster.
         // $filter selects all users enrolled in the track due to being in
         // a(nother) cluster associated with the track.  We will left-join
         // with it, and only select non-matching records.
         $params = array();
         $filter = 'SELECT u.userid ' . 'FROM {' . clusterassignment::TABLE . '} u ' . 'INNER JOIN {' . usertrack::TABLE . '} ut ON u.userid = ut.userid ' . 'WHERE ut.trackid = :trackid AND u.autoenrol=\'1\'';
         $params['trackid'] = $this->trackid;
         $sql = 'SELECT usrtrk.id ' . 'FROM {' . clusterassignment::TABLE . '} cu ' . 'INNER JOIN {' . usertrack::TABLE . '} usrtrk ON cu.userid = usrtrk.userid AND usrtrk.trackid = \'' . $this->trackid . '\' ' . 'LEFT OUTER JOIN (' . $filter . ') f ON f.userid = cu.userid ' . 'WHERE cu.clusterid = :clusterid AND cu.autoenrol=\'1\' AND f.userid IS NULL';
         $params['clusterid'] = $this->clusterid;
         $usertracks = $this->_db->get_recordset_sql($sql, $params);
         foreach ($usertracks as $usertrack) {
             $ut = new usertrack($usertrack->id);
             $ut->unenrol();
         }
         unset($usertracks);
     }
     parent::delete();
 }
コード例 #14
0
 protected function _load_data_from_record($rec, $overwrite = false, $field_map = null, $from_db = false, array $extradatafields = array())
 {
     parent::_load_data_from_record($rec, $overwrite, $field_map, $from_db, $extradatafields);
     $this->_load_fields();
     $contextlevel = $this->get_field_context_level();
     foreach (self::$_fields[$contextlevel] as $name => $field) {
         // figure out the name of the field to copy from
         $rec_name = self::CUSTOM_FIELD_PREFIX . $name;
         if (is_string($field_map)) {
             // just a simple prefix
             $rec_name = $field_map . $rec_name;
         } else {
             if (is_array($field_map)) {
                 if (!isset($field_map[$rec_name])) {
                     // field isn't mapped -- skip it
                     continue;
                 }
                 $rec_name = $field_map[$rec_name];
             }
         }
         // set the field from the record if:
         // - we don't have a value already set, or if we want to
         //   overwrite; and
         // - the value is set in the source record
         if ((isset($this->_field_data[$name]) || $overwrite) && isset($rec->{$rec_name})) {
             $this->_field_data[$name] = $rec->{$rec_name};
             if (!$from_db) {
                 $this->_field_changed[$name] = true;
             }
         }
     }
     // TODO: causes problems with custom fields
     //        if ($from_db) {
     //            $this->_fields_loaded = true;
     //        }
 }
コード例 #15
0
 /**
  * Add params fields to the form object
  */
 public function to_object()
 {
     $obj = parent::to_object();
     $fields = array('autoenrol_curricula', 'autoenrol_tracks', 'child_classification', 'autoenrol_groups', 'autoenrol_groupings', 'elis_files_shared_folder');
     foreach ($fields as $field) {
         $field_name = "param_{$field}";
         if (isset($this->{$field_name})) {
             $obj->{$field_name} = $this->{$field_name};
         }
     }
     return $obj;
 }
コード例 #16
0
ファイル: data_object.class.php プロジェクト: jamesmcq/elis
 /**
  * Construct a data object.
  * @param mixed $src record source.  It can be
  * - false: an empty object is created
  * - an integer: loads the record that has record id equal to $src
  * - an object: creates an object with field data taken from the members
  *   of $src
  * - an array: creates an object with the field data taken from the
  *   elements of $src
  * @param mixed $field_map mapping for field names from $src.  If it is a
  * string, then it will be treated as a prefix for field names.  If it is
  * an array, then it is a mapping of destination field names to source
  * field names.
  * @param array $associations pre-fetched associated objects (to avoid
  * needing to re-fetch)
  * @param boolean $from_db whether or not the record source object/array
  * comes from the database
  * @param array $extradatafields extra data from the $src object/array
  * associated with the record that should be kept in the data object (such
  * as counts of related records)
  * @param moodle_database $database database object to use (null for the
  * default database)
  */
 public function __construct($src = false, $field_map = null, array $associations = array(), $from_db = false, array $extradatafields = array(), moodle_database $database = null)
 {
     global $DB;
     if (!isset(self::$_unset)) {
         self::$_unset = new stdClass();
     }
     // mark all the fields as unset
     $reflect = new ReflectionClass(get_class($this));
     $prefix_len = strlen(self::FIELD_PREFIX);
     foreach ($reflect->getProperties() as $prop) {
         if (strncmp($prop->getName(), self::FIELD_PREFIX, $prefix_len) === 0) {
             $field_name = $prop->getName();
             $this->{$field_name} = self::$_unset;
         }
     }
     if ($database === null) {
         $this->_db = $DB;
     } else {
         $this->_db = $database;
     }
     // initialize the object fields
     if ($src === false) {
         $this->_setup_extradata((object) array(), $extradatafields);
     } else {
         if (is_numeric($src)) {
             $this->_dbfield_id = $src;
             $this->_setup_extradata((object) array(), $extradatafields);
         } else {
             if (is_object($src)) {
                 $this->_load_data_from_record($src, false, $field_map, $from_db, $extradatafields);
             } else {
                 if (is_array($src)) {
                     $this->_load_data_from_record((object) $src, false, $field_map, $from_db, $extradatafields);
                 } else {
                     throw new data_object_exception('data_object_construct_invalid_source', 'local_eliscore');
                 }
             }
         }
     }
     $this->_associated_objects = $associations;
 }