public function definition_after_data() { global $DB; parent::definition_after_data(); $mform = $this->_form; // If sharing is turned on, check to see if they can turn it off. if ($mform->elementExists('enablesharing') && $mform->getElementValue('enablesharing')) { // Look for any shared pages that use this id. $subpageid = $mform->getElementValue('instance'); if ($DB->record_exists('sharedsubpage', array('subpageid' => $subpageid))) { $mform->getElement('enablesharing')->freeze(); } } }
public function definition_after_data() { parent::definition_after_data(); $mform = $this->_form; if ($id = $mform->getElementValue('update')) { $dta = $mform->getElementValue('open'); $dt = mktime($dta['hour'][0], $dta['minute'][0], 0, $dta['month'][0], $dta['day'][0], $dta['year'][0]); if ($dt < time()) { $el = $mform->createElement('static', 'openlabel', 'Open', date("D d/m/Y H:i", $dt)); $mform->insertElementBefore($el, 'open'); $mform->removeElement('open'); $mform->addElement('hidden', 'opendt', $dt); } } }
/** * Make fields editable or non-editable depending on the administrator choices * @see moodleform_mod::definition_after_data() */ public function definition_after_data() { parent::definition_after_data(); //$mform =& $this->_form; }
function definition_after_data() { global $COURSE, $DB; parent::definition_after_data(); $mform =& $this->_form; $mainglossaryel =& $mform->getElement('mainglossary'); $mainglossary = $DB->get_record('glossary', array('mainglossary' => 1, 'course' => $COURSE->id)); if ($mainglossary && $mainglossary->id != $mform->getElementValue('instance')) { //secondary glossary, a main one already exists in this course. $mainglossaryel->setValue(0); $mainglossaryel->freeze(); $mainglossaryel->setPersistantFreeze(true); } else { $mainglossaryel->unfreeze(); $mainglossaryel->setPersistantFreeze(false); } }
function definition_after_data() { if ($this->current->instance and $this->current->tobemigrated) { // resource not migrated yet return; } parent::definition_after_data(); }
/** * Set the grade item categories when editing an instance */ public function definition_after_data() { $mform =& $this->_form; if ($id = $mform->getElementValue('update')) { $instance = $mform->getElementValue('instance'); $gradeitems = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => 'workshop', 'iteminstance' => $instance, 'courseid' => $this->course->id)); if (!empty($gradeitems)) { foreach ($gradeitems as $gradeitem) { // here comes really crappy way how to set the value of the fields // gradecategory and gradinggradecategory - grrr QuickForms $decimalpoints = $gradeitem->get_decimals(); if ($gradeitem->itemnumber == 0) { $submissiongradepass = $mform->getElement('submissiongradepass'); $submissiongradepass->setValue(format_float($gradeitem->gradepass, $decimalpoints)); $group = $mform->getElement('submissiongradegroup'); $elements = $group->getElements(); foreach ($elements as $element) { if ($element->getName() == 'gradecategory') { $element->setValue($gradeitem->categoryid); } } } else { if ($gradeitem->itemnumber == 1) { $gradinggradepass = $mform->getElement('gradinggradepass'); $gradinggradepass->setValue(format_float($gradeitem->gradepass, $decimalpoints)); $group = $mform->getElement('gradinggradegroup'); $elements = $group->getElements(); foreach ($elements as $element) { if ($element->getName() == 'gradinggradecategory') { $element->setValue($gradeitem->categoryid); } } } } } } } parent::definition_after_data(); }
function definition_after_data() { parent::definition_after_data(); $mform =& $this->_form; $type =& $mform->getElement('type'); $typevalue = $mform->getElementValue('type'); //we don't want to have these appear as possible selections in the form but //we want the form to display them if they are set. if ($typevalue[0] == 'news') { $type->addOption(get_string('namenews', 'forum'), 'news'); $mform->addHelpButton('type', 'namenews', 'forum'); $type->freeze(); $type->setPersistantFreeze(true); } if ($typevalue[0] == 'social') { $type->addOption(get_string('namesocial', 'forum'), 'social'); $type->freeze(); $type->setPersistantFreeze(true); } }
/** * Set the grade item categories when editing an instance */ public function definition_after_data() { parent::definition_after_data(); }
public function definition_after_data() { parent::definition_after_data(); $mform =& $this->_form; $data = $this->current; $choices = array(); if (!empty($data->id)) { global $DB; /* The method $this->get_submitted_data() does only return values for fields that are already defined->load ids from db -> create fields(values are overwritten by submitted data). */ $choices = $DB->get_records('ratingallocate_choices', array('ratingallocateid' => $data->id), 'title ASC'); } else { $this->newchoicecounter = 2; } // If there is already submitted data? if ($this->is_submitted()) { // Load new_choice_counter. if (property_exists($this->get_submitted_data(), self::NEW_CHOICE_COUNTER)) { $this->newchoicecounter = $this->get_submitted_data()->{self::NEW_CHOICE_COUNTER}; } // Increment new choice counter if add_new_choice button was pressed. if (property_exists($this->get_submitted_data(), self::ADD_CHOICE_ACTION)) { $this->newchoicecounter++; } } for ($i = 0; $i < $this->newchoicecounter; $i++) { $choices[] = $this->create_empty_choice($i + 1); } // Generate array with ids of all choices. $choiceids = array_map(function ($elem) { return (int) $elem->id; }, $choices); // Initialize variable. $deletechoicearray = array(); // If delete choice button was pressed. if ($this->is_submitted()) { // Retrieve ids of choices to be deleted from the static field. if (property_exists($this->get_submitted_data(), self::DELETED_CHOICE_IDS)) { $deletedchoiceids = $this->get_submitted_data()->{self::DELETED_CHOICE_IDS}; } // If the string is not empty the array of choice ids is exploded from it. if (!empty($deletedchoiceids)) { $deletechoicearray = explode(',', $deletedchoiceids); } // Parses all delete choice ids to integers. $integercheck = function ($elem) { return (int) $elem; }; array_map($integercheck, $deletechoicearray); // Retrieve id of choice to be deleted if delete button was pressed. $matches = preg_grep('/' . self::DELETE_CHOICE_ACTION . '([-]?[0-9]+)/', array_keys($mform->getSubmitValues())); // Only proceed if exaclty one delete button was found in the submitted data. if (count($matches) == 1) { // Retrieve the id as an Integer from the button name. $elem = array_pop($matches); $parts = explode('_', $elem); $deletechoiceid = (int) array_pop($parts); // If the id matches one of the choices add it to the choices to be deleted. if (in_array($deletechoiceid, $choiceids)) { $deletechoicearray[] = $deletechoiceid; } } } // Clean array to only contain feasible ids. $deletechoicearray = array_intersect($deletechoicearray, $choiceids); // Create fields for all choices. foreach ($choices as $id => $choice) { if (!in_array($choice->id, $deletechoicearray)) { $this->add_choice_group($mform, $choice); } else { // The nosubmit button has to be added since the form uses it for no_submit_button_pressed(). $mform->registerNoSubmitButton(self::DELETE_CHOICE_ACTION . $choice->id); } } if ($this->is_submitted()) { $subdata = $this->get_submitted_data(); $allstrategyoptions = $subdata->{self::STRATEGY_OPTIONS}; } else { if (isset($data->setting)) { $allstrategyoptions = json_decode($data->setting, true); } } // Add dynamic settings fields. foreach (\strategymanager::get_strategies() as $strategy) { // Load strategy class. $strategyclassp = 'ratingallocate\\' . $strategy . '\\strategy'; /* @var $strategyclass \strategytemplate */ if (isset($allstrategyoptions) && array_key_exists($strategy, $allstrategyoptions)) { $strategyclass = new $strategyclassp($allstrategyoptions[$strategy]); } else { $strategyclass = new $strategyclassp(); } $strategyplaceholder = self::STRATEGY_OPTIONS_PLACEHOLDER . '[' . $strategy . ']'; // Add options fields. $dynamicsettingsfields = $strategyclass->get_dynamic_settingfields(); foreach ($dynamicsettingsfields as $key => $value) { $fieldid = $this->get_settingsfield_identifier($strategy, $key); $this->add_settings_field($fieldid, $value, $strategy, $mform); $mform->insertElementBefore($mform->removeElement($fieldid, false), $strategyplaceholder); } // If any dynamic field is present, add a no submit button to refresh the page. if (count($dynamicsettingsfields) > 0) { $buttonname = self::STRATEGY_OPTIONS . $strategy . 'refresh'; $mform->registerNoSubmitButton($buttonname); $mform->addElement('submit', $buttonname, get_string('refresh')); $mform->insertElementBefore($mform->removeElement($buttonname, false), $strategyplaceholder); } $mform->removeElement($strategyplaceholder); } // UPDATE OF FORM VALUES NEEDS TO BE EXECUTED IN THE END!!! // Update new_choice_counter. $mform->getElement(self::NEW_CHOICE_COUNTER)->setValue($this->newchoicecounter); // Update delete_choice_string. if (!empty($deletechoicearray)) { $deletedchoiceids = implode(',', $deletechoicearray); $mform->getElement(self::DELETED_CHOICE_IDS)->setValue($deletedchoiceids); } }
function definition_after_data() { parent::definition_after_data(); global $COURSE; $mform =& $this->_form; if ($this->clone) { $mform->removeElement('groupmode'); return; } $targetforumid = $mform->getElementValue('removeto'); $targetforumid = $targetforumid[0]; $removeafter = $mform->getElementValue('removeafter'); $removeafter = $removeafter[0]; if ($removeafter && $targetforumid) { $modinfo = get_fast_modinfo($COURSE); if (!array_key_exists($targetforumid, $modinfo->instances['forumng'])) { $mform->getElement('removeto')->addOption(get_string('invalidforum', 'forumng'), $targetforumid); } } }
public function definition_after_data() { parent::definition_after_data(); global $DB; $mform = $this->_form; $cmid = $mform->getElementValue('coursemodule'); $mform->removeElement('groupmode'); // Remove group mode as cutom method is implemented. if (!empty($cmid)) { // The user is updating the instance of the activity. // Remove the file manager as the annotations may not make . // sense if the file they are applied to are changed. $mform->removeElement('files'); // Find out what type of document it was and set selector. $table = "annotation_document"; $results = $DB->get_records($table, array('cmid' => $cmid)); foreach ($results as $result) { $documenttype = $result->documenttype; $groupannotation = $result->groupannotation; $groupannotationsvisible = $result->groupannotationsvisible; $allowfrom = $result->allowfrom; $allowuntil = $result->allowuntil; break; } $mform->setDefault('type', $documenttype); $mform->setDefault('groupannotation', $groupannotation); $mform->setDefault('groupannotationsvisible', $groupannotationsvisible); $mform->setDefault('allowfrom', $allowfrom); $mform->setDefault('allowuntil', $allowuntil); } }
function definition_after_data() { parent::definition_after_data(); global $COURSE; $mform =& $this->_form; $coursemodule =& $mform->getElementValue('coursemodule'); if ($coursemodule) { $mform->hardFreeze('timeopen'); $mform->hardFreeze('timeclose'); $mform->hardFreeze('timeslot'); $mform->hardFreeze('timeblock'); } }