/** * Adds elements for this field type to the edit form. * @param moodleform $mform */ public function edit_field_add($mform) { // Create the form field. $mform->addElement('editor', $this->inputname, format_string($this->field->name), null, null); $mform->setType($this->inputname, PARAM_RAW); // We MUST clean this before display! }
/** * Updates the provided users profile picture based upon the expected fields * returned from the edit or edit_advanced forms. * * @global moodle_database $DB * @param stdClass $usernew An object that contains some information about the user being updated * @param moodleform $userform The form that was submitted to edit the form * @return bool True if the user was updated, false if it stayed the same. */ function useredit_update_picture(stdClass $usernew, moodleform $userform) { global $CFG, $DB; require_once("$CFG->libdir/gdlib.php"); $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST); // This will hold the value to set to the user's picture field at the end of // this function $picturetouse = null; if (!empty($usernew->deletepicture)) { // The user has chosen to delete the selected users picture $fs = get_file_storage(); $fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas $picturetouse = 0; } else if ($iconfile = $userform->save_temp_file('imagefile')) { // There is a new image that has been uploaded // Process the new image and set the user to make use of it. // NOTE: This may be overridden by Gravatar if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) { $picturetouse = 1; } // Delete the file that has now been processed @unlink($iconfile); } // If we have a picture to set we can now do so. Note this will still be NULL // unless the user has changed their picture or caused a change by selecting // to delete their picture or use gravatar if (!is_null($picturetouse)) { $DB->set_field('user', 'picture', $picturetouse, array('id' => $usernew->id)); return true; } return false; }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data used to set default values of the form */ public function config_form_display(&$mform, $data = null) { $mform->addElement('checkbox', 'criteria_role[' . $data->id . ']', $this->get_title($data)); if ($this->id) { $mform->setDefault('criteria_role[' . $data->id . ']', 1); } }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data Form data */ public function config_form_display(&$mform, $data = null) { $mform->addElement('checkbox', 'criteria_self', get_string('enable')); if ($this->id) { $mform->setDefault('criteria_self', 1); } }
/** * Add elements for creating/editing a textarea profile field. * @param moodleform $form */ public function define_form_specific($form) { // Default data. $form->addElement('editor', 'defaultdata', get_string('profiledefaultdata', 'admin')); $form->setType('defaultdata', PARAM_RAW); // We have to trust person with capability to edit this default description. }
/** * Renders the list of available steps according to the submitted filters * * @param string $stepsdefinitions HTML from behat with the available steps * @param moodleform $form * @return string HTML code */ public function render_stepsdefinitions($stepsdefinitions, $form) { $title = get_string('pluginname', 'tool_behat'); // Header. $html = $this->output->header(); $html .= $this->output->heading($title); // Info. $installurl = behat_command::DOCS_URL . '#Installation'; $installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank')); $writetestsurl = behat_command::DOCS_URL . '#Writting_features'; $writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank')); $writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions'; $writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank')); $infos = array(get_string('installinfo', 'tool_behat', $installlink), get_string('newtestsinfo', 'tool_behat', $writetestslink), get_string('newstepsinfo', 'tool_behat', $writestepslink)); // List of steps $html .= $this->output->box_start(); $html .= html_writer::tag('h1', 'Info'); $html .= html_writer::empty_tag('div'); $html .= html_writer::empty_tag('ul'); $html .= html_writer::empty_tag('li'); $html .= implode(html_writer::end_tag('li') . html_writer::empty_tag('li'), $infos); $html .= html_writer::end_tag('li'); $html .= html_writer::end_tag('ul'); $html .= html_writer::end_tag('div'); $html .= $this->output->box_end(); // Form. ob_start(); $form->display(); $html .= ob_get_contents(); ob_end_clean(); // Steps definitions. $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions')); $html .= $this->output->footer(); return $html; }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data Form data */ public function config_form_display(&$mform, $data = null) { $mform->addElement('checkbox', 'criteria_unenrol', get_string('completiononunenrolment', 'completion')); if ($this->id) { $mform->setDefault('criteria_unenrol', 1); } }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data details of various modules */ public function config_form_display(&$mform, $data = null) { $mform->addElement('checkbox', 'criteria_activity[' . $data->id . ']', ucfirst(self::get_mod_name($data->module)) . ' - ' . $data->name); if ($this->id) { $mform->setDefault('criteria_activity[' . $data->id . ']', 1); } }
/** * Updates the provided users profile picture based upon the expected fields * returned from the edit or edit_advanced forms. * * @global moodle_database $DB * @param stdClass $usernew An object that contains some information about the user being updated * @param moodleform $userform The form that was submitted to edit the form * @return bool True if the user was updated, false if it stayed the same. */ function useredit_update_picture(stdClass $usernew, moodleform $userform) { global $CFG, $DB; require_once "{$CFG->libdir}/gdlib.php"; $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST); $user = $DB->get_record('user', array('id' => $usernew->id), 'id, picture', MUST_EXIST); $newpicture = $user->picture; if (!empty($usernew->deletepicture)) { // The user has chosen to delete the selected users picture $fs = get_file_storage(); $fs->delete_area_files($context->id, 'user', 'icon'); // drop all images in area $newpicture = 0; } else { if ($iconfile = $userform->save_temp_file('imagefile')) { // There is a new image that has been uploaded // Process the new image and set the user to make use of it. // NOTE: Uploaded images always take over Gravatar $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile); // Delete the file that has now been processed @unlink($iconfile); } } if ($newpicture != $user->picture) { $DB->set_field('user', 'picture', $newpicture, array('id' => $user->id)); return true; } else { return false; } }
/** * Render a formslib form. * @param moodleform $form * @return string the HTML to output. */ protected function capability_form(moodleform $form) { ob_start(); $form->display(); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Adds controls specific to this filter in the form. * @param moodleform $mform a MoodleForm object to setup */ public function setupForm(&$mform) { $choices = array('' => get_string('anyvalue', 'filters')) + $this->_options; $mform->addElement('select', $this->_name, $this->_label, $choices); if ($this->_advanced) { $mform->setAdvanced($this->_name); } }
/** * Use this since we can't fetch the output of a moodle form * @param moodleform $mform * @return type string HTML */ protected function moodleform(moodleform $mform) { ob_start(); $mform->display(); $o = ob_get_contents(); ob_end_clean(); return $o; }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data details of various modules */ public function config_form_display(&$mform, $data = null) { $modnames = get_module_types_names(); $mform->addElement('checkbox', 'criteria_activity[' . $data->id . ']', $modnames[self::get_mod_name($data->module)] . ' - ' . format_string($data->name)); if ($this->id) { $mform->setDefault('criteria_activity[' . $data->id . ']', 1); } }
/** * Add elements for creating/editing a checkbox profile field. * * @param moodleform $form */ public function define_form_specific($form) { // Select whether or not this should be checked by default. $form->addElement('selectyesno', 'defaultdata', get_string('profiledefaultchecked', 'admin')); $form->setDefault('defaultdata', 0); // Defaults to 'no'. $form->setType('defaultdata', PARAM_BOOL); }
/** * Prints out the form snippet for the part of creating or * editing a profile field specific to the current data type * * @param moodleform $form reference to moodleform for adding elements. */ function define_form_specific(&$form) { //Add elements, set defualt value and define type of data $form->addElement('radio', 'defaultdata', get_string('mystring', 'profilefield_myprofilefield')); $form->setDefault('defaultdata', 1); // defaults to 'yes' $form->setType('defaultdata', PARAM_BOOL); }
/** * Adds elements to the form for creating/editing this type of profile field. * @param moodleform $form */ public function define_form_specific($form) { // Param 1 for menu type contains the options. $form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40)); $form->setType('param1', PARAM_TEXT); // Default data. $form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"'); $form->setType('defaultdata', PARAM_TEXT); }
/** * Add fields for editing a text profile field. * @param moodleform $mform */ public function edit_field_add($mform) { $size = $this->field->param1; $maxlength = $this->field->param2; $fieldtype = $this->field->param3 == 1 ? 'password' : 'text'; // Create the form field. $mform->addElement($fieldtype, $this->inputname, format_string($this->field->name), 'maxlength="' . $maxlength . '" size="' . $size . '" '); $mform->setType($this->inputname, PARAM_TEXT); }
public function render_course_enrolment_users_table(course_enrolment_users_table $table, moodleform $mform) { $table->initialise_javascript(); // Added for the Bootstrap theme. Make this table responsive. $table->attributes['class'] .= ' table table-responsive'; $buttons = $table->get_manual_enrol_buttons(); $buttonhtml = ''; if (count($buttons) > 0) { $buttonhtml .= html_writer::start_tag('div', array('class' => 'enrol_user_buttons')); foreach ($buttons as $button) { $buttonhtml .= $this->render($button); } $buttonhtml .= html_writer::end_tag('div'); } $content = ''; if (!empty($buttonhtml)) { $content .= $buttonhtml; } $content .= $mform->render(); $content .= $this->output->render($table->get_paging_bar()); // Check if the table has any bulk operations. If it does we want to wrap the table in a // form so that we can capture and perform any required bulk operations. if ($table->has_bulk_user_enrolment_operations()) { $content .= html_writer::start_tag('form', array('action' => new moodle_url('/enrol/bulkchange.php'), 'method' => 'post')); foreach ($table->get_combined_url_params() as $key => $value) { if ($key == 'action') { continue; } $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value)); } $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'bulkchange')); $content .= html_writer::table($table); $content .= html_writer::start_tag('div', array('class' => 'singleselect bulkuserop')); $content .= html_writer::start_tag('select', array('name' => 'bulkuserop')); $content .= html_writer::tag('option', get_string('withselectedusers', 'enrol'), array('value' => '')); $options = array('' => get_string('withselectedusers', 'enrol')); foreach ($table->get_bulk_user_enrolment_operations() as $operation) { $content .= html_writer::tag('option', $operation->get_title(), array('value' => $operation->get_identifier())); } $content .= html_writer::end_tag('select'); $content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go'))); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('form'); } else { // Added for the Bootstrap theme, a no-overflow wrapper. $content .= html_writer::start_tag('div', array('class' => 'no-overflow')); $content .= html_writer::table($table); $content .= html_writer::end_tag('div'); } $content .= $this->output->render($table->get_paging_bar()); if (!empty($buttonhtml)) { $content .= $buttonhtml; } return $content; }
/** * Renders the list of available steps according to the submitted filters. * * @param mixed $stepsdefinitions Available steps array. * @param moodleform $form * @return string HTML code */ public function render_stepsdefinitions($stepsdefinitions, $form) { $title = get_string('pluginname', 'tool_behat'); // Header. $html = $this->output->header(); $html .= $this->output->heading($title); // Info. $installurl = behat_command::DOCS_URL . '#Installation'; $installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank')); $writetestsurl = behat_command::DOCS_URL . '#Writting_features'; $writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank')); $writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions'; $writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank')); $infos = array(get_string('installinfo', 'tool_behat', $installlink), get_string('newtestsinfo', 'tool_behat', $writetestslink), get_string('newstepsinfo', 'tool_behat', $writestepslink)); // List of steps. $html .= $this->output->box_start(); $html .= html_writer::tag('h1', get_string('infoheading', 'tool_behat')); $html .= html_writer::tag('div', get_string('aim', 'tool_behat')); $html .= html_writer::start_tag('div'); $html .= html_writer::start_tag('ul'); $html .= html_writer::start_tag('li'); $html .= implode(html_writer::end_tag('li') . html_writer::start_tag('li'), $infos); $html .= html_writer::end_tag('li'); $html .= html_writer::end_tag('ul'); $html .= html_writer::end_tag('div'); $html .= $this->output->box_end(); // Form. ob_start(); $form->display(); $html .= ob_get_contents(); ob_end_clean(); if (empty($stepsdefinitions)) { $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat'); } else { $stepsdefinitions = implode('', $stepsdefinitions); // Replace text selector type arguments with a user-friendly select. $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) { return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid()); }, $stepsdefinitions); // Replace selector type arguments with a user-friendly select. $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) { return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid()); }, $stepsdefinitions); // Replace simple OR options. $regex = '#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#'; $stepsdefinitions = preg_replace_callback($regex, function ($matches) { return html_writer::select(explode('|', $matches[1]), uniqid()); }, $stepsdefinitions); } // Steps definitions. $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions')); $html .= $this->output->footer(); return $html; }
/** * Add elements for editing the profile field value. * @param moodleform $mform */ public function edit_field_add($mform) { // Create the form field. $checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name)); if ($this->data == '1') { $checkbox->setChecked(true); } $mform->setType($this->inputname, PARAM_BOOL); if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) { $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client'); } }
/** * Adds controls specific to this filter in the form. * * @param moodleform $mform a MoodleQuickForm object in which element will be added */ public function setupForm(&$mform) { $mform->addElement('checkbox', $this->_name, $this->_label, ''); if ($this->_advanced) { $mform->setAdvanced($this->_name); } // Check if disable if options are set. if yes then set rules. if (!empty($this->disableelements) && is_array($this->disableelements)) { foreach ($this->disableelements as $disableelement) { $mform->disabledIf($disableelement, $this->_name, 'checked'); } } }
/** * Add appropriate form elements to the critieria form * * @param moodleform $mform Moodle forms object * @param stdClass $data not used */ public function config_form_display(&$mform, $data = null) { $mform->addElement('checkbox', 'criteria_duration', get_string('enable')); $thresholdmenu = array(); for ($i = 1; $i <= 30; $i++) { $seconds = $i * 86400; $thresholdmenu[$seconds] = get_string('numdays', '', $i); } $mform->addElement('select', 'criteria_duration_days', get_string('daysafterenrolment', 'completion'), $thresholdmenu); if ($this->id) { $mform->setDefault('criteria_duration', 1); $mform->setDefault('criteria_duration_days', $this->enrolperiod); } }
function organizer_display_form(moodleform $mform, $title, $addcalendar = true) { global $OUTPUT; if ($addcalendar) { organizer_add_calendar(); } echo $OUTPUT->header(); echo $OUTPUT->heading($title); echo $OUTPUT->box_start('', 'organizer_main_cointainer'); $mform->display(); echo $OUTPUT->box_end(); echo $OUTPUT->footer(); die; }
/** * Renders the list of available steps according to the submitted filters. * * @param mixed $stepsdefinitions Available steps array. * @param moodleform $form * @return string HTML code */ public function render_stepsdefinitions($stepsdefinitions, $form) { $html = $this->generic_info(); // Form. ob_start(); $form->display(); $html .= ob_get_contents(); ob_end_clean(); if (empty($stepsdefinitions)) { $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat'); } else { $stepsdefinitions = implode('', $stepsdefinitions); // Replace text selector type arguments with a user-friendly select. $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/', function ($matches) { return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid()); }, $stepsdefinitions ); // Replace selector type arguments with a user-friendly select. $stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/', function ($matches) { return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid()); }, $stepsdefinitions ); // Replace simple OR options. $regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#'; $stepsdefinitions = preg_replace_callback($regex, function($matches){ return html_writer::select(explode('|', $matches[1]), uniqid()); }, $stepsdefinitions ); } // Steps definitions. $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions')); $html .= $this->output->footer(); return $html; }
/** * Adds controls specific to this filter in the form. * * @param moodleform $mform a MoodleQuickForm object in which element will be added */ public function setupForm(&$mform) { $objs = array(); $objs[] = $mform->createElement('checkbox', $this->_name, null, ''); $grp = $mform->addElement('group', $this->_name . '_grp', $this->_label, $objs, '', false); if ($this->_advanced) { $mform->setAdvanced($this->_name . '_grp'); } // Check if disable if options are set. if yes then set rules. if (!empty($this->disableelements) && is_array($this->disableelements)) { foreach ($this->disableelements as $disableelement) { $mform->disabledIf($disableelement, $this->_name, 'checked'); } } }
/** * Adds controls specific to this filter in the form. * @param moodleform $mform a MoodleForm object to setup */ public function setupForm(&$mform) { $objs = array(); $objs['role'] = $mform->createElement('select', $this->_name . '_rl', null, $this->get_roles()); $objs['role']->setLabel(get_string('courserole', 'filters')); $objs['category'] = $mform->createElement('select', $this->_name . '_ct', null, $this->get_course_categories()); $objs['category']->setLabel(get_string('coursecategory', 'filters')); $objs['value'] = $mform->createElement('text', $this->_name, null); $objs['value']->setLabel(get_string('coursevalue', 'filters')); $grp =& $mform->addElement('group', $this->_name . '_grp', $this->_label, $objs, '', false); $mform->setType($this->_name, PARAM_TEXT); if ($this->_advanced) { $mform->setAdvanced($this->_name . '_grp'); } }
function validation($data, $files) { global $COURSE, $CFG; $errors = parent::validation($data, $files); $textlib = textlib_get_instance(); $name = trim(stripslashes($data['name'])); if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) { if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) { if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } } if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) { // enforce password policy only if changing password $errmsg = ''; if (!check_password_policy($data['enrolmentkey'], $errmsg)) { $errors['enrolmentkey'] = $errmsg; } } } else { if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } } return $errors; }
/** * Form validation * * @param array $data * @param array $files * @return array $errors An array of validataion errors for the form. */ function validation($data, $files) { global $COURSE, $DB; $errors = parent::validation($data, $files); $name = trim($data['name']); if (isset($data['idnumber'])) { $idnumber = trim($data['idnumber']); } else { $idnumber = ''; } if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) { if (core_text::strtolower($grouping->name) != core_text::strtolower($name)) { if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupingnameexists', 'group', $name); } } if (!empty($idnumber) && $grouping->idnumber != $idnumber) { if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) { $errors['idnumber'] = get_string('idnumbertaken'); } } } else { if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupingnameexists', 'group', $name); } else { if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) { $errors['idnumber'] = get_string('idnumbertaken'); } } } return $errors; }
/** * Validates the add instance form data * * @param array $data * @param array $files * @return array */ public function validation($data, $files) { $errors = parent::validation($data, $files); if (!array_key_exists('name', $errors)) { if (!preg_match('#^[a-zA-Z0-9\\-_ ]+$#', $data['name'])) { $errors['name'] = get_string('storenameinvalid', 'cache'); } else { if (empty($this->_customdata['store'])) { $stores = cache_administration_helper::get_store_instance_summaries(); if (array_key_exists($data['name'], $stores)) { $errors['name'] = get_string('storenamealreadyused', 'cache'); } } } } if (method_exists($this, 'configuration_validation')) { $newerrors = $this->configuration_validation($data, $files, $errors); // We need to selectiviliy merge here foreach ($newerrors as $element => $error) { if (!array_key_exists($element, $errors)) { $errors[$element] = $error; } } } return $errors; }
function validation($data, $files) { global $USER; if ($errors = parent::validation($data, $files)) { return $errors; } $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['importfile'], 'id', false))) { $errors['importfile'] = get_string('required'); return $errors; } else { $file = reset($files); if ($file->get_mimetype() != 'application/zip') { $errors['importfile'] = get_string('invalidfiletype', 'error', $file->get_filename()); // better delete current file, it is not usable anyway $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['importfile']); } else { if (!($chpterfiles = toolbook_importhtml_get_chapter_files($file, $data['type']))) { $errors['importfile'] = get_string('errornochapters', 'booktool_importhtml'); } } } return $errors; }