/** * items in the form */ public function definition() { global $CURMAN, $CFG; parent::definition(); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $mform->addElement('text', 'name', get_string('cluster_name', 'block_curr_admin') . ':'); $mform->addRule('name', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('name', array('clusterform/name', get_string('cluster_name', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'display', get_string('cluster_description', 'block_curr_admin') . ':', array('cols' => 40, 'rows' => 2)); $mform->setHelpButton('display', array('clusterform/display', get_string('cluster_description', 'block_curr_admin'), 'block_curr_admin')); $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : ''; //obtain the non-child clusters that we could become the child of, with availability //determined based on the edit capability $contexts = clusterpage::get_contexts('block/curr_admin:cluster:edit'); $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts); //parent dropdown $mform->addElement('select', 'parent', get_string('cluster_parent', 'block_curr_admin') . ':', $non_child_clusters); $mform->setHelpButton('parent', array('clusterform/parent', get_string('cluster_parent', 'block_curr_admin'), 'block_curr_admin')); // allow plugins to add their own fields $plugins = get_list_of_plugins('curriculum/cluster'); $mform->addElement('header', 'userassociationfieldset', get_string('userassociation', 'block_curr_admin')); foreach ($plugins as $plugin) { require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php'; call_user_func('cluster_' . $plugin . '_edit_form', $this); } // custom fields $fields = field::get_for_context_level('cluster'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
/** * Method to add ELIS entity's custom fields to entity forms * * @param string $entity ELIS entity name: Eg. 'curriculum', 'track', 'course', 'class', 'cluster', 'user' * @param string $editcap The required edit capability * @param string $viewcap The required view capability * @param string $parententity The entity name of the parent object (optional) */ function add_custom_fields($entity, $editcap, $viewcap, $parententity = '') { $mform =& $this->_form; $fields = field::get_for_context_level($entity); $fields = $fields ? $fields : array(); if (isset($this->_customdata['obj'])) { if (isset($this->_customdata['obj']->id)) { // Use the current (existing) entity's context instance $contextlevel = \local_eliscore\context\helper::get_level_from_name($entity); $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel); $context = $contextclass::instance($this->_customdata['obj']->id); } else { if (isset($this->_customdata['obj']->parent) && $parententity != '') { // ELIS-6498 -- Specify the parent entity type to get the correct parent context instance as we are // adding a new "child" entity $contextlevel = \local_eliscore\context\helper::get_level_from_name($parententity); $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel); $context = $contextclass::instance($this->_customdata['obj']->parent); } else { if (isset($this->_customdata['obj']->courseid) && $parententity == 'course') { // ELIS-6498 -- Special handling of the course -> class hierarchy is required here $context = \local_elisprogram\context\course::instance($this->_customdata['obj']->courseid); } else { $context = context_system::instance(); } } } } else { $context = context_system::instance(); } require_once elis::plugin_file('elisfields_manual', 'custom_fields.php'); $lastcat = null; $entityid = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : 0; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } // Capabilities for editing / viewing this context if (manual_field_is_view_or_editable($field, $context, $editcap, $viewcap, $entity, $entityid) != MANUAL_FIELD_NO_VIEW_OR_EDIT) { if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $mform, $context, $this->_customdata, $field, true, $editcap, $viewcap, $entity, $entityid); } } }
/** * items in the form * * @uses $USER */ public function definition() { global $USER; $this->set_data($this->_customdata['obj']); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $curs = array(); if (!empty($USER->id)) { // TBD: and/or capability 'block/curr_admin:curriculum:edit|view' ? // WAS: 'block/curr_admin:track:create' ??? $contexts = get_contexts_by_capability_for_user('curriculum', 'block/curr_admin:curriculum:view', $USER->id); $curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts); } if (empty($this->_customdata['obj']->id)) { $curid_options = array(); if (!empty($curs)) { foreach ($curs as $cur) { $curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name; } } $mform->addElement('select', 'curid', get_string('curriculum', 'block_curr_admin') . ':', $curid_options); $mform->addRule('curid', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('curid', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin')); } else { // Track editing, do not allow the user to change curriculum $mform->addElement('static', 'curidstatic', get_string('curriculum', 'block_curr_admin') . ':', $curs[$this->_customdata['obj']->curid]->name); $mform->setHelpButton('curidstatic', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('hidden', 'curid'); } $mform->addElement('text', 'idnumber', get_string('track_idnumber', 'block_curr_admin') . ':'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client'); $mform->addRule('idnumber', null, 'maxlength', 100); $mform->setHelpButton('idnumber', array('trackform/idnumber', get_string('track_idnumber', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'name', get_string('track_name', 'block_curr_admin') . ':'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'maxlength', 255); $mform->addRule('name', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('name', array('trackform/name', get_string('track_name', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'description', get_string('track_description', 'block_curr_admin') . ':'); $mform->setType('description', PARAM_CLEAN); $mform->setHelpButton('description', array('trackform/description', get_string('track_description', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'block_curr_admin') . ':', array('optional' => true)); $mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'block_curr_admin') . ':', array('optional' => true)); $mform->setHelpButton('startdate', array('trackform/startdate', get_string('startdate', 'block_curr_admin'), 'block_curr_admin')); if (!empty($this->_customdata['obj']->id)) { $trackassignobj = new trackassignmentclass(array('trackid' => $this->_customdata['obj']->id)); } // Only show auto-create checkbox if the track does not have any classes assigned if (!isset($trackassignobj) or 0 == $trackassignobj->count_assigned_classes_from_track()) { $mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'block_curr_admin') . ':'); $mform->setHelpButton('autocreate', array('trackform/autocreate', get_string('track_autocreate', 'block_curr_admin'), 'block_curr_admin')); } // custom fields $fields = field::get_for_context_level('track'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('track', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
function definition() { global $USER, $CFG, $COURSE, $CURMAN; parent::definition(); if (!empty($this->_customdata['obj'])) { $obj = $this->_customdata['obj']; if (empty($obj->startdate) || $obj->startdate == 0) { $this->set_data(array('disablestart' => '1')); } if (empty($obj->enddate) || $obj->enddate == 0) { $this->set_data(array('disableend' => '1')); } if (isset($obj->starttimeminute) && isset($obj->starttimehour)) { $this->set_data(array('starttime' => array('minute' => $obj->starttimeminute, 'hour' => $obj->starttimehour))); } if (isset($obj->endtimeminute) && isset($obj->endtimehour)) { $this->set_data(array('endtime' => array('minute' => $obj->endtimeminute, 'hour' => $obj->endtimehour))); } } $mform =& $this->_form; $mform->addElement('hidden', 'id'); // If there is no custom data for the course, create some if (empty($this->_customdata['obj']->course->name) || empty($this->_customdata['obj']->id)) { $courses = array(); if (!empty($USER->id)) { $contexts = get_contexts_by_capability_for_user('course', 'block/curr_admin:class:create', $USER->id); // get listing of available ELIS courses $courses = course_get_listing('name', 'ASC', 0, 0, '', '', $contexts); } // Add course select $attributes = array('onchange' => 'update_trk_multiselect(); '); $selections = array(); if (!empty($courses)) { foreach ($courses as $course) { $selections[$course->id] = '(' . $course->idnumber . ')' . $course->name; } } $mform->addElement('select', 'courseid', get_string('course', 'block_curr_admin') . ':', $selections, $attributes); $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin')); $firstcourse = reset($courses); $this->firstcourse = $firstcourse; if (false !== $firstcourse && empty($this->_customdata['obj']->id)) { $this->add_track_multi_select($firstcourse->id); } elseif (!empty($courses)) { $this->add_track_multi_select($this->_customdata['obj']->courseid); } } else { $extra_params = array(); $mform->addElement('static', 'courseid', get_string('course', 'block_curr_admin') . ':'); // Get current action and set param accordingly $current_action = optional_param('action', 'view', PARAM_ALPHA); $extra_params['action'] = $current_action; $extra_params['s'] = 'crs'; // Want to set the url for the course $extra_params['id'] = $this->_customdata['obj']->courseid; // Course id $course_url = $this->get_moodle_url($extra_params); $course_name = '(' . $this->_customdata['obj']->course->idnumber . ')' . '<a href="' . $course_url . '" >' . $this->_customdata['obj']->course->name . '</a>'; $this->set_data(array('courseid' => $course_name)); $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin')); $this->add_track_multi_select($this->_customdata['obj']->courseid); } if (!empty($this->_customdata['obj']->courseid)) { $mform->freeze('courseid'); } else { $mform->addRule('courseid', get_string('required'), 'required', NULL, 'client'); } // Done adding course select //get_string('general'); $mform->addElement('text', 'idnumber', get_string('class_idnumber', 'block_curr_admin') . ':'); $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client'); $mform->setType('idnumber', PARAM_TEXT); $mform->setHelpButton('idnumber', array('cmclassform/idnumber', get_string('class_idnumber', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'startdate', get_string('class_startdate', 'block_curr_admin') . ':', array('optional' => true, 'disabled' => 'disabled')); $mform->setHelpButton('startdate', array('cmclassform/startdate', get_string('class_startdate', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'enddate', get_string('class_enddate', 'block_curr_admin') . ':', array('optional' => true)); // They may very likely be a much better way of checking for this... if (empty($obj->starttimehour) and empty($obj->starttimeminute)) { $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h)); } else { $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h)); } $mform->setHelpButton('starttime', array('cmclassform/starttime', get_string('class_starttime', 'block_curr_admin'), 'block_curr_admin')); // Do the same thing for the endtime if (empty($obj->endtimehour) and empty($obj->endtimeminute)) { $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h)); } else { $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h)); } $mform->addElement('text', 'maxstudents', get_string('class_maxstudents', 'block_curr_admin') . ':'); $mform->setType('maxstudents', PARAM_INT); $mform->setHelpButton('maxstudents', array('cmclassform/maxstudents', get_string('class_maxstudents', 'block_curr_admin'), 'block_curr_admin')); // Environment selector $envs = environment_get_listing(); $envs = $envs ? $envs : array(); $o_envs = array(get_string('none', 'block_curr_admin')); foreach ($envs as $env) { $o_envs[$env->id] = $env->name; } $mform->addElement('select', 'environmentid', get_string('environment', 'block_curr_admin') . ':', $o_envs); $mform->setHelpButton('environmentid', array('cmclassform/environment', get_string('environment', 'block_curr_admin'), 'block_curr_admin')); // Course selector if (empty($this->_customdata['obj']->moodlecourseid)) { $this->add_moodle_course_select(); } else { global $CURMAN; $coursename = $CURMAN->db->get_field('course', 'fullname', 'id', $this->_customdata['obj']->moodlecourseid); $mform->addElement('static', 'class_attached_course', get_string('class_attached_course', 'block_curr_admin') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->_customdata['obj']->moodlecourseid}\">{$coursename}</a>"); $mform->setHelpButton('class_attached_course', array('cmclassform/moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('hidden', 'moodlecourseid'); } $mform->addElement('checkbox', 'enrol_from_waitlist', get_string('waitlistenrol', 'block_curr_admin') . ':'); $mform->setHelpButton('enrol_from_waitlist', array('cmclassform/waitlistenrol', get_string('waitlistenrol', 'block_curr_admin'), 'block_curr_admin')); // custom fields $fields = field::get_for_context_level('class'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('class', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
public function definition() { global $USER, $CFG, $COURSE; if ($this->_customdata['obj']) { $this->set_data($this->_customdata['obj']); $disabled = true; } else { $disabled = false; } $mform =& $this->_form; $strgeneral = get_string('general'); $strrequired = get_string('required'); $bundle = NULL; /// Add some extra hidden fields $mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'search'); $mform->addElement('text', 'idnumber', get_string('idnumber')); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', null, 'maxlength', 255); $mform->setHelpButton('idnumber', array('userform/idnumber', get_string('idnumber'), 'block_curr_admin')); $username_group = array(); if (empty($disabled)) { $mform->addRule('idnumber', null, 'required', null, 'client'); $username_group[] =& $mform->createElement('text', 'username', get_string('username')); $username_group[] =& $mform->createElement('checkbox', 'id_same_user', null, get_string('id_same_as_user', 'block_curr_admin')); $mform->disabledIf('username_group', 'id_same_user', 'checked'); $mform->addGroup($username_group, 'username_group', get_string('username'), ' ', false); $mform->addRule('username_group', $strrequired, 'required', null, 'client'); } else { $mform->freeze('idnumber'); $username_group[] =& $mform->createElement('static', 'username'); $mform->addGroup($username_group, 'username_group', get_string('username'), ' ', false); $mform->freeze('username_group'); } $mform->addGroupRule('username_group', array('username' => array(array(null, 'maxlength', 100)))); $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword')); $mform->setType('newpassword', PARAM_TEXT); $mform->addRule('newpassword', null, 'maxlength', 25); $mform->addElement('text', 'firstname', get_string('userfirstname', 'block_curr_admin')); $mform->setType('firstname', PARAM_TEXT); $mform->addRule('firstname', $strrequired, 'required', null, 'client'); $mform->addRule('firstname', null, 'maxlength', 100); $mform->addElement('text', 'lastname', get_string('userlastname', 'block_curr_admin')); $mform->setType('lastname', PARAM_TEXT); $mform->addRule('lastname', $strrequired, 'required', null, 'client'); $mform->addRule('lastname', null, 'maxlength', 100); $mform->addElement('text', 'mi', get_string('usermi', 'block_curr_admin')); $mform->setType('mi', PARAM_TEXT); $mform->addRule('mi', null, 'maxlength', 100); $mform->addElement('text', 'email', get_string('email', 'block_curr_admin')); $mform->setType('email', PARAM_TEXT); $mform->addRule('email', null, 'email', null, 'client'); $mform->addRule('email', null, 'required', null, 'client'); $mform->addRule('email', null, 'maxlength', 100); $mform->addElement('text', 'email2', get_string('email2', 'block_curr_admin')); $mform->setType('email2', PARAM_TEXT); $mform->addRule('email2', null, 'email', null, 'client'); $mform->addRule('email2', null, 'maxlength', 100); $mform->addElement('text', 'address', get_string('useraddress', 'block_curr_admin')); $mform->setType('address', PARAM_TEXT); $mform->addRule('address', null, 'maxlength', 100); $mform->addElement('text', 'address2', get_string('useraddress2', 'block_curr_admin')); $mform->setType('address2', PARAM_TEXT); $mform->addRule('address2', null, 'maxlength', 100); $mform->addElement('text', 'city', get_string('usercity', 'block_curr_admin')); $mform->setType('city', PARAM_TEXT); $mform->addRule('city', null, 'maxlength', 100); $mform->addElement('text', 'state', get_string('userstate', 'block_curr_admin')); $mform->setType('state', PARAM_TEXT); $mform->addRule('state', null, 'maxlength', 100); $mform->addElement('text', 'postalcode', get_string('userpostalcode', 'block_curr_admin')); $mform->setType('postalcode', PARAM_TEXT); $mform->addRule('postalcode', null, 'maxlength', 32); $country = cm_get_list_of_countries(); $default_country[''] = get_string('selectacountry'); $country = array_merge($default_country, $country); $mform->addElement('select', 'country', get_string('country'), $country); $mform->addRule('country', $strrequired, 'required', null, 'client'); $mform->addElement('text', 'phone', get_string('phone')); $mform->setType('phone', PARAM_TEXT); $mform->addRule('phone', null, 'maxlength', 100); $mform->addElement('text', 'phone2', get_string('phone2', 'block_curr_admin')); $mform->setType('phone2', PARAM_TEXT); $mform->addRule('phone2', null, 'maxlength', 100); $mform->addElement('text', 'fax', get_string('fax', 'block_curr_admin')); $mform->setType('fax', PARAM_TEXT); $mform->addRule('fax', null, 'maxlength', 100); $bdaygroup = array(); $days[''] = get_string('selectdays', 'block_curr_admin'); for ($i = 1; $i <= 31; $i++) { $days[$i] = $i; } $months[''] = get_string('selectmonths', 'block_curr_admin'); for ($i = 1; $i <= 12; $i++) { $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), "%B"); } $years[''] = get_string('selectyears', 'block_curr_admin'); for ($i = 1900; $i <= 2020; $i++) { $years[$i] = $i; } $bdaygroup[] =& $mform->createElement('select', 'birthday', get_string('day', 'block_curr_admin'), $days, '', true); $bdaygroup[] =& $mform->createElement('select', 'birthmonth', get_string('month', 'block_curr_admin'), $months, '', true); $bdaygroup[] =& $mform->createElement('select', 'birthyear', get_string('year', 'block_curr_admin'), $years, '', true); $mform->addGroup($bdaygroup, 'birthdate', get_string('userbirthdate', 'block_curr_admin'), ' ', false); // $mform->addElement('date_selector', 'birthdate', get_string('userbirthdate', 'block_curr_admin')); //TODO: the bdaygroup stuff with this but need to update the pages as well $radioarray = array(); $radioarray[] =& $mform->createElement('radio', 'gender', '', get_string('male', 'block_curr_admin'), 'M'); $radioarray[] =& $mform->createElement('radio', 'gender', '', get_string('female', 'block_curr_admin'), 'F'); $mform->addGroup($radioarray, 'gender', get_string('usergender', 'block_curr_admin'), ' ', false); $language = cm_get_list_of_languages(); $mform->addElement('select', 'language', get_string('userlanguage', 'block_curr_admin'), $language); $mform->setDefault('language', 'English'); $mform->setHelpButton('language', array('userform/language', get_string('userlanguage', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'transfercredits', get_string('transfercredits', 'block_curr_admin')); $mform->setType('transfercredits', PARAM_INT); $mform->setHelpButton('transfercredits', array('userform/transfercredits', get_string('transfercredits', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'comments', get_string('usercomments', 'block_curr_admin')); $mform->setType('comments', PARAM_CLEAN); $mform->setHelpButton('comments', array('userform/comments', get_string('usercomments', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'notes', get_string('notes', 'block_curr_admin')); $mform->setType('notes', PARAM_CLEAN); $mform->setHelpButton('notes', array('userform/notes', get_string('notes', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('advcheckbox', 'inactive', get_string('inactive', 'block_curr_admin')); $mform->setType('inactive', PARAM_TEXT); $mform->setHelpButton('inactive', array('userform/inactive', get_string('inactive', 'block_curr_admin'), 'block_curr_admin')); $fields = field::get_for_context_level('user'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field, !$field->multivalued); // ELIS-4000: Multi-valued fields require custom validation in form } if ($this->_customdata['obj']) { $this->set_data($this->_customdata['obj']); } $this->add_action_buttons(); }
/** * Validate error handling for incorrectly-specified context view capability. */ public function test_field_not_added_when_view_context_capability_not_specified() { // Setup. $this->init_config(); $coursecontext = $this->init_category_and_course(); $field = $this->init_field_and_owner('moodle/user:update', ''); $this->init_user(); // Attempt to add the field. $form = new custom_field_permissions_form(); $mform = $form->get_mform(); manual_field_add_form_element($form, $mform, $coursecontext, array(), $field, false); // Validation. $this->assertFalse($mform->elementExists('field_field')); }
/** * defines items in the form */ public function definition() { global $CURMAN; $configData = array('title'); if ($this->_customdata['obj']) { // FIXME: This is probably not be the right place for set_data. Move it. $this->set_data($this->_customdata['obj']); } $mform =& $this->_form; $mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'courseid'); $mform->addElement('text', 'idnumber', get_string('curriculum_idnumber', 'block_curr_admin') . ':'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', null, 'required', null, 'client'); $mform->addRule('idnumber', null, 'maxlength', 100); $mform->setHelpButton('idnumber', array('curriculaform/idnumber', get_string('curriculum_idnumber', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'name', get_string('curriculum_name', 'block_curr_admin') . ':'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', null, 'maxlength', 64); $mform->setHelpButton('name', array('curriculaform/name', get_string('curriculum_name', 'block_curr_admin'), 'block_curr_admin')); $attributes = array('rows' => '2', 'cols' => '40'); $mform->addElement('textarea', 'description', get_string('curriculum_description', 'block_curr_admin') . ':', $attributes); $mform->setType('description', PARAM_CLEAN); $mform->setHelpButton('description', array('curriculaform/description', get_string('curriculum_description', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'reqcredits', get_string('required_credits', 'block_curr_admin') . ':'); $mform->setType('reqcredits', PARAM_NUMBER); $mform->addRule('reqcredits', null, 'maxlength', 10); $mform->setHelpButton('reqcredits', array('curriculaform/reqcredits', get_string('required_credits', 'block_curr_admin'), 'block_curr_admin')); $choices = range(0, 10); $mform->addElement('select', 'priority', get_string('priority', 'block_curr_admin') . ':', $choices); $mform->setHelpButton('priority', array('curriculaform/priority', get_string('priority', 'block_curr_admin'), 'block_curr_admin')); //because moodle forms will not allow headers within headers $mform->addElement('header', 'editform', get_string('time_settings', 'block_curr_admin')); // Time to complete $mform->addElement('text', 'timetocomplete', get_string('time_to_complete', 'block_curr_admin') . ':'); $mform->setType('timetocomplete', PARAM_TEXT); $mform->addRule('timetocomplete', null, 'maxlength', 64); $mform->setHelpButton('timetocomplete', array('curriculaform/timetocomplete', get_string('time_to_complete', 'block_curr_admin'), 'block_curr_admin')); //$mform->addElement('html', '<small>' . get_string('tips_time_to_complete', 'block_curr_admin') . '</small><br /><br />'); // Frequency (only display if curriculum expiration is currently enabled). if (!empty($CURMAN->config->enable_curriculum_expiration)) { $mform->addElement('text', 'frequency', get_string('expiration', 'block_curr_admin') . ':'); $mform->setType('frequency', PARAM_TEXT); $mform->addRule('frequency', null, 'maxlength', 64); $mform->setHelpButton('frequency', array('curriculaform/frequency', get_string('expiration', 'block_curr_admin'), 'block_curr_admin')); } else { $mform->addElement('hidden', 'frequency'); } //$mform->addElement('html', '<small>' . get_string('tips_time_to_redo', 'block_curr_admin') . '</small><br /><br />'); $mform->addElement('static', '', '', '<small>' . get_string('tips_time_format', 'block_curr_admin') . '</small>'); // custom fields $fields = field::get_for_context_level('curriculum'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
public function definition() { if (isset($this->_customdata['obj']->id)) { $id = $this->_customdata['obj']->id; } global $CFG, $CURMAN; require_js($CFG->wwwroot . '/curriculum/js/courseform.js'); $this->set_data($this->_customdata['obj']); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $mform->addElement('text', 'name', get_string('course_name', 'block_curr_admin') . ':'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', get_string('required_field', 'block_curr_admin', get_string('course_name', 'block_curr_admin')), 'required', null, 'client'); $mform->addRule('name', null, 'maxlength', 255); $mform->setHelpButton('name', array('courseform/name', get_string('course_name', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'code', get_string('course_code', 'block_curr_admin') . ':'); $mform->setType('code', PARAM_TEXT); $mform->addRule('code', null, 'maxlength', 100); $mform->setHelpButton('code', array('courseform/code', get_string('course_code', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'idnumber', get_string('course_idnumber', 'block_curr_admin') . ':'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', get_string('required_field', 'block_curr_admin', get_string('course_idnumber', 'block_curr_admin')), 'required', null, 'client'); $mform->addRule('idnumber', null, 'maxlength', 100); $mform->setHelpButton('idnumber', array('courseform/idnumber', get_string('course_idnumber', 'block_curr_admin'), 'block_curr_admin')); $attributes = array('cols' => 40, 'rows' => 2); $mform->addElement('textarea', 'syllabus', get_string('course_syllabus', 'block_curr_admin') . ':', $attributes); $mform->setType('syllabus', PARAM_CLEAN); $mform->setHelpButton('syllabus', array('courseform/description', get_string('course_syllabus', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'lengthdescription', get_string('length_description', 'block_curr_admin')); $mform->setType('lengthdescription', PARAM_TEXT); $mform->addRule('lengthdescription', null, 'maxlength', 100); $mform->setHelpButton('lengthdescription', array('courseform/lengthdescription', get_string('length_description', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'length', get_string('duration', 'block_curr_admin') . ':'); $mform->setType('length', PARAM_INT); $mform->setHelpButton('length', array('courseform/duration', get_string('duration', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'credits', get_string('credits', 'block_curr_admin') . ':'); $mform->setType('credits', PARAM_TEXT); $mform->addRule('credits', null, 'maxlength', 10); $mform->setHelpButton('credits', array('courseform/credits', get_string('credits', 'block_curr_admin'), 'block_curr_admin')); $grades = range(0, 100, 1); $mform->addElement('select', 'completion_grade', get_string('completion_grade', 'block_curr_admin') . ':', $grades); $mform->setHelpButton('completion_grade', array('courseform/completion_grade', get_string('completion_grade', 'block_curr_admin'), 'block_curr_admin')); $environments = array('- ' . get_string('none', 'block_curr_admin') . ' -'); $envs = environment_get_listing(); if (empty($envs)) { $envs = array(); } foreach ($envs as $e) { $environments[$e->id] = $e->name; } $mform->addElement('select', 'environmentid', get_string('environment', 'block_curr_admin'), $environments); $mform->setHelpButton('environmentid', array('courseform/environmentid', get_string('environment', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'cost', get_string('cost', 'block_curr_admin') . ':'); $mform->setType('cost', PARAM_TEXT); $mform->addRule('cost', null, 'maxlength', 10); $mform->setHelpButton('cost', array('courseform/cost', get_string('cost', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'version', get_string('course_version', 'block_curr_admin') . ':'); $mform->setType('version', PARAM_TEXT); $mform->addRule('version', null, 'maxlength', 100); $mform->setHelpButton('version', array('courseform/version', get_string('course_version', 'block_curr_admin'), 'block_curr_admin')); // Print form items for course template browsing $mform->addElement('html', '<br />'); $mform->addElement('hidden', 'templateclass', 'moodlecourseurl', array('id' => 'id_templateclass')); if (optional_param('action', '', PARAM_CLEAN) == 'view' && !empty($this->_customdata['obj']->locationlabel)) { $mform->addElement('static', 'locationlabellink', get_string('coursetemplate', 'block_curr_admin') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->_customdata['obj']->locationid}\">{$this->_customdata['obj']->locationlabel}</a>"); $mform->setHelpButton('locationlabellink', array('courseform/coursetemplate', get_string('coursetemplate', 'block_curr_admin'), 'block_curr_admin')); } else { $mform->addElement('text', 'locationlabel', get_string('coursetemplate', 'block_curr_admin') . ':', array('readonly' => 'readonly')); $mform->setType('locationlabel', PARAM_TEXT); $mform->setHelpButton('locationlabel', array('courseform/coursetemplate', get_string('coursetemplate', 'block_curr_admin'), 'block_curr_admin')); } if (empty($id)) { $mform->addElement('hidden', 'location', '', array('id' => 'id_location')); $mform->addElement('hidden', 'temptype', '', array('id' => 'tempid')); } else { global $CURMAN; $template = new coursetemplate($id); $mform->addElement('hidden', 'location', $template->location, array('id' => 'id_location')); $mform->addElement('hidden', 'tempid', $template->id, array('id' => 'tempid')); } $templateButtons = array(); $templateButtons[] =& $mform->createElement('button', 'submit1', get_string('browse', 'block_curr_admin'), array('onClick' => 'openNewWindow();')); $templateButtons[] =& $mform->createElement('button', 'submit1', get_string('clear', 'block_curr_admin'), array('onClick' => 'cleartext();')); $mform->addGroup($templateButtons, 'templateButtons', '', '', false); // Multi select box for choosing curricula (only when creating a course) if (!isset($this->_customdata['obj'])) { $mform->addElement('html', '<br />'); $cur_listings = curriculum_get_listing(); $cur_listings = $cur_listings ? $cur_listings : array(); $values = array(); foreach ($cur_listings as $key => $val) { $values[$key] = $val->name; } $strcur = get_string("curricula", "block_curr_admin"); // Set an explicit width if the select box will have no elements. $attributes = empty($values) ? array('style' => 'width: 200px;') : array(); $multiSelect =& $mform->addElement('select', 'curriculum', $strcur . ':', $values, $attributes); $multiSelect->setMultiple(true); $mform->setHelpButton('curriculum', array('courseform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('submit', 'makecurcourse', get_string('makecurcourse', 'block_curr_admin')); } // custom fields $fields = field::get_for_context_level('course'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('course', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }