Added a timemodified field to the customcert_elements table which is used to collapse the form elements that have already been modified by the user

Note: I did not create a db/upgrade.php script to add the new database column as this module should not be currently used by anyone.
This commit is contained in:
Mark Nelson 2013-04-24 17:24:57 +08:00
parent 3d0b62c25d
commit 7781024377
3 changed files with 16 additions and 8 deletions

View file

@ -61,6 +61,7 @@
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/> <FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/> <FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/> <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_elements"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_elements"/>

View file

@ -252,6 +252,13 @@ class mod_customcert_edit_form extends moodleform {
// Add element header. // Add element header.
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " . $mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
get_string('pluginname', 'customcertelement_' . $element->element)); get_string('pluginname', 'customcertelement_' . $element->element));
// We do not need to expand these elements if the modified time is greater than the created time as it
// means the values have already been altered by the user - ie. the element has not just been created.
if ($element->timemodified > $element->timecreated) {
$mform->setExpanded('headerelement_' . $element->id, false);
} else {
$mform->setExpanded('headerelement_' . $element->id, true);
}
// Only display the move up arrow if it is not the first. // Only display the move up arrow if it is not the first.
if ($element->sequence > 1) { if ($element->sequence > 1) {
$url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $this->_customdata['cmid'], 'emoveup' => $element->id)); $url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $this->_customdata['cmid'], 'emoveup' => $element->id));

View file

@ -54,6 +54,9 @@ class customcert_element_base {
public static function add_element($element, $pageid) { public static function add_element($element, $pageid) {
global $DB; global $DB;
// Set the time as a variable.
$time = time();
$data = new stdClass(); $data = new stdClass();
$data->pageid = $pageid; $data->pageid = $pageid;
$data->element = $element; $data->element = $element;
@ -63,7 +66,8 @@ class customcert_element_base {
$data->posx = '250'; $data->posx = '250';
$data->posy = '250'; $data->posy = '250';
$data->sequence = customcert_element_base::get_element_sequence($pageid); $data->sequence = customcert_element_base::get_element_sequence($pageid);
$data->timecreated = time(); $data->timecreated = $time;
$data->timemodified = $time;
$DB->insert_record('customcert_elements', $data); $DB->insert_record('customcert_elements', $data);
} }
@ -119,11 +123,6 @@ class customcert_element_base {
$mform->setType('posx_' . $id, PARAM_INT); $mform->setType('posx_' . $id, PARAM_INT);
$mform->setType('posy_' . $id, PARAM_INT); $mform->setType('posy_' . $id, PARAM_INT);
// Add some rules.
$mform->addRule('colour_' . $id, $strrequired, 'required', null, 'client');
$mform->addRule('posx_' . $id, $strrequired, 'required', null, 'client');
$mform->addRule('posy_' . $id, $strrequired, 'required', null, 'client');
// Set the values of these elements. // Set the values of these elements.
$mform->setDefault('font_' . $id, $this->element->font); $mform->setDefault('font_' . $id, $this->element->font);
$mform->setDefault('size_' . $id, $this->element->size); $mform->setDefault('size_' . $id, $this->element->size);
@ -164,7 +163,7 @@ class customcert_element_base {
$posx = 'posx_' . $id; $posx = 'posx_' . $id;
$posxdata = $data[$posx]; $posxdata = $data[$posx];
// Check if posx is not numeric or less than 0. // Check if posx is not numeric or less than 0.
if ((!is_numeric($posxdata)) || ($posxdata < 0)) { if (empty($posxdata) || (!is_numeric($posxdata)) || ($posxdata < 0)) {
$errors[$posx] = get_string('invalidposition', 'customcert', 'X'); $errors[$posx] = get_string('invalidposition', 'customcert', 'X');
} }
@ -172,7 +171,7 @@ class customcert_element_base {
$posy = 'posy_' . $id; $posy = 'posy_' . $id;
$posydata = $data[$posy]; $posydata = $data[$posy];
// Check if posy is not numeric or less than 0. // Check if posy is not numeric or less than 0.
if ((!is_numeric($posydata)) || ($posydata < 0)) { if (empty($posydata) || (!is_numeric($posydata)) || ($posydata < 0)) {
$errors[$posy] = get_string('invalidposition', 'customcert', 'Y'); $errors[$posy] = get_string('invalidposition', 'customcert', 'Y');
} }
@ -208,6 +207,7 @@ class customcert_element_base {
$element->colour = (!empty($data->$colour)) ? $data->$colour : null; $element->colour = (!empty($data->$colour)) ? $data->$colour : null;
$element->posx = (!empty($data->$posx)) ? $data->$posx : null; $element->posx = (!empty($data->$posx)) ? $data->$posx : null;
$element->posy = (!empty($data->$posy)) ? $data->$posy : null; $element->posy = (!empty($data->$posy)) ? $data->$posy : null;
$element->timemodified = time();
// Ok, now update record in the database. // Ok, now update record in the database.
$DB->update_record('customcert_elements', $element); $DB->update_record('customcert_elements', $element);