Skip to content
Snippets Groups Projects
evaluserexport.php 3.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    // This file is part of Moodle - https://moodle.org/
    //
    // Moodle is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // (at your option) any later version.
    //
    // Moodle is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with Moodle.  If not, see <https://www.gnu.org/licenses/>.
    
    /**
     * Plugin version and other meta-data are defined here.
     *
     * @package     local_hshexport
     * @copyright   2024 Elke Kreim elke.kreim@hs-hannover.de
     * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     */
    
    namespace local_hshexport\form;
    
    use moodleform;
    
    defined('MOODLE_INTERNAL') || die();
    
    class evaluserexport extends moodleform {
    
        public function definition()
        {
            $mform = $this->_form;
    
            $introtext = get_string('evaluserexport_form_into', 'local_hshexport');
            $mform->addElement('html', '<div id="intor">' . $introtext . '</div>');
    
            $courseid = $this->_customdata['courseid'];
            $coursecontext = $this->_customdata['coursecontext'];
    
            $viewableroles = get_roles_used_in_context($coursecontext, false);
    
            $roles = role_fix_names($viewableroles, $coursecontext, ROLENAME_ALIAS);
            $options = [];
            foreach ($roles as $role) {
                $options[$role->id] = $role->localname;
            }
    
    
            $placeholder = get_string('course_code_placeholder', 'local_hshexport');
    
    Elke Kreim's avatar
    Elke Kreim committed
            $mform->addElement('text', 'course_code', get_string('course_code', 'local_hshexport'), 'maxlength="150" size="50" placeholder="'.$placeholder.'"');
            $mform->setType('course_code', PARAM_TEXT);
    
            $mform->addHelpButton('course_code', 'course_code', 'local_hshexport');
            $mform->setDefault('course_code', null);
    
            $roles = role_fix_names($viewableroles, $coursecontext, ROLENAME_ALIAS);
    
    Elke Kreim's avatar
    Elke Kreim committed
    
            $roles_checkboxes = [];
    
    
            foreach ($roles as $role) {
    
    Elke Kreim's avatar
    Elke Kreim committed
                $roles_checkboxes[] =& $mform->createElement('advcheckbox', 'role_'.$role->id, $role->localname, null, ['group' => 1], [null, $role->id]);
    
    Elke Kreim's avatar
    Elke Kreim committed
            $mform->addGroup($roles_checkboxes, 'roles', get_string('select_roles', 'local_hshexport'), ['<br/>'], true);
    
    Elke Kreim's avatar
    Elke Kreim committed
            $mform->addHelpButton('roles', 'select_roles', 'local_hshexport');
            $mform->addGroupRule(
                'roles',
                get_string('noselectedroles', 'local_hshexport'),
                'required',
                null,
                1,
                'client'
            );
    
            $this->add_checkbox_controller(
                1,
                get_string("checkall", "local_hshexport")
            );
    
    
            $mform->addElement('hidden', 'courseid', $courseid);
            $mform->setType('courseid', PARAM_INT);
    
            $mform->addElement('hidden', 'coursecontextid', $coursecontext->id);
            $mform->setType('coursecontextid', PARAM_INT);
    
            $submitlabel = get_string('csvdownload', 'local_hshexport');
            $this->add_action_buttons(false, $submitlabel);
    
        }
    
    
    Elke Kreim's avatar
    Elke Kreim committed
        function validation($data, $files)
        {
            $errors = parent::validation($data, $files); // TODO: Change the autogenerated stub
            return $errors;
        }