1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Customfields checkbox plugin 19 * 20 * @package customfield_checkbox 21 * @copyright 2018 David Matamoros <davidmc@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace customfield_checkbox; 26 27 defined('MOODLE_INTERNAL') || die; 28 29 /** 30 * Class field 31 * 32 * @package customfield_checkbox 33 * @copyright 2018 David Matamoros <davidmc@moodle.com> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class field_controller extends \core_customfield\field_controller { 37 /** 38 * Plugin type 39 */ 40 const TYPE = 'checkbox'; 41 42 /** 43 * Add fields for editing a checkbox field. 44 * 45 * @param \MoodleQuickForm $mform 46 */ 47 public function config_form_definition(\MoodleQuickForm $mform) { 48 $mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_checkbox')); 49 $mform->setExpanded('header_specificsettings', true); 50 51 $mform->addElement('selectyesno', 'configdata[checkbydefault]', get_string('checkedbydefault', 'customfield_checkbox')); 52 $mform->setType('configdata[checkbydefault]', PARAM_BOOL); 53 } 54 55 /** 56 * Validate the data on the field configuration form 57 * 58 * @param array $data from the add/edit profile field form 59 * @param array $files 60 * @return array associative array of error messages 61 */ 62 public function config_form_validation(array $data, $files = array()) : array { 63 $errors = parent::config_form_validation($data, $files); 64 65 if ($data['configdata']['uniquevalues']) { 66 $errors['configdata[uniquevalues]'] = get_string('errorconfigunique', 'customfield_checkbox'); 67 } 68 69 return $errors; 70 } 71 72 /** 73 * Does this custom field type support being used as part of the block_myoverview 74 * custom field grouping? 75 * @return bool 76 */ 77 public function supports_course_grouping(): bool { 78 return true; 79 } 80 81 /** 82 * If this field supports course grouping, then this function needs overriding to 83 * return the formatted values for this. 84 * @param array $values the used values that need formatting 85 * @return array 86 */ 87 public function course_grouping_format_values($values): array { 88 $name = $this->get_formatted_name(); 89 return [ 90 1 => $name.': '.get_string('yes'), 91 BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY => $name.': '.get_string('no'), 92 ]; 93 } 94 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body