function update_content($recordid, $value, $name = '') { global $DB; if (empty($this->field->param2)) { return false; // auto-increment not required } $select = 'recordid = ? AND fieldid = ? AND content IS NOT NULL AND content != ? AND content != ?'; if ($DB->record_exists_select('data_content', $select, array($recordid, $this->field->id, '', '0'))) { return false; // auto-increment value is already set in DB } $value = $this->get_autoincrement($recordid); return parent::update_content($recordid, $value, $name); }
/** * add/update content for an admin field in a user record * * @return boolean: TRUE if content was sccessfully updated; otherwise FALSE */ function update_content($recordid, $value, $name = '') { global $DB, $USER; if ($this->is_special_field) { if ($this->unapprove) { // override the automatic approval of records created by teachers and admins return $DB->set_field('data_records', 'approved', 0, array('id' => $recordid)); } if ($this->setdefaultvalues) { $profilefields = $this->get_profile_fields(); $params = array('dataid' => $this->data->id); if (!($fields = $DB->get_records_menu('data_fields', $params, 'id', 'id, name'))) { $fields = array(); // shouldn't happen !! } $params = array('recordid' => $recordid); if (!($values = $DB->get_records_menu('data_content', $params, 'fieldid', 'fieldid, content'))) { $values = array(); // shouldn't happen !! } foreach ($fields as $id => $field) { $field = $this->get_profile_field($field); if (in_array($field, $profilefields) && $USER->{$field} == '') { if (array_key_exists($id, $values)) { $value = $values[$id]; if ($field == 'country') { $value = $this->get_country_code($value); } if ($value) { $USER->{$field} = $value; $DB->set_field('user', $field, $value, array('id' => $USER->id)); } } } } } return true; } if ($this->subfield) { return $this->subfield->update_content($recordid, $value, $name); } else { return parent::update_content($recordid, $value, $name); } return false; }