| 1 | efrain | 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 |  * Form for selective purging of caches.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    core
 | 
        
           |  |  | 21 |  * @copyright  2018 The Open University
 | 
        
           |  |  | 22 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 23 |  */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | namespace core_admin\form;
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 | require_once($CFG->libdir.'/formslib.php');
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 | /**
 | 
        
           |  |  | 32 |  * Form for selecting which caches to purge on admin/purgecaches.php
 | 
        
           |  |  | 33 |  *
 | 
        
           |  |  | 34 |  * @package   core
 | 
        
           |  |  | 35 |  * @copyright 2018 The Open University
 | 
        
           |  |  | 36 |  * @author    Mark Johnson <mark.johnson@open.ac.uk>
 | 
        
           |  |  | 37 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 38 |  */
 | 
        
           |  |  | 39 | class purge_caches extends \moodleform {
 | 
        
           |  |  | 40 |     /**
 | 
        
           |  |  | 41 |      * Define a "Purge all caches" button, and a fieldset with checkboxes for selectively purging separate caches.
 | 
        
           |  |  | 42 |      */
 | 
        
           |  |  | 43 |     public function definition() {
 | 
        
           |  |  | 44 |         $mform = $this->_form;
 | 
        
           |  |  | 45 |         $mform->addElement('hidden', 'returnurl', $this->_customdata['returnurl']);
 | 
        
           |  |  | 46 |         $mform->setType('returnurl', PARAM_LOCALURL);
 | 
        
           |  |  | 47 |         $mform->addElement('submit', 'all', get_string('purgecaches', 'admin'));
 | 
        
           |  |  | 48 |         $mform->addElement('header', 'purgecacheheader', get_string('purgeselectedcaches', 'admin'));
 | 
        
           |  |  | 49 |         $checkboxes = [
 | 
        
           |  |  | 50 |             $mform->createElement('advcheckbox', 'theme', '', get_string('purgethemecache', 'admin')),
 | 
        
           | 1441 | ariadna | 51 |             $mform->createElement('advcheckbox', 'courses', '', get_string('purgecoursecache', 'admin')),
 | 
        
           | 1 | efrain | 52 |             $mform->createElement('advcheckbox', 'lang', '', get_string('purgelangcache', 'admin')),
 | 
        
           |  |  | 53 |             $mform->createElement('advcheckbox', 'js', '', get_string('purgejscache', 'admin')),
 | 
        
           |  |  | 54 |             $mform->createElement('advcheckbox', 'template', '', get_string('purgetemplates', 'admin')),
 | 
        
           |  |  | 55 |             $mform->createElement('advcheckbox', 'filter', '', get_string('purgefiltercache', 'admin')),
 | 
        
           |  |  | 56 |             $mform->createElement('advcheckbox', 'muc', '', get_string('purgemuc', 'admin')),
 | 
        
           |  |  | 57 |             $mform->createElement('advcheckbox', 'other', '', get_string('purgeothercaches', 'admin'))
 | 
        
           |  |  | 58 |         ];
 | 
        
           |  |  | 59 |         $mform->addGroup($checkboxes, 'purgeselectedoptions');
 | 
        
           |  |  | 60 |         $mform->addElement('submit', 'purgeselectedcaches', get_string('purgeselectedcaches', 'admin'));
 | 
        
           |  |  | 61 |     }
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |     /**
 | 
        
           |  |  | 64 |      * If the "Purge selected caches" button was pressed, ensure at least one cache was selected.
 | 
        
           |  |  | 65 |      *
 | 
        
           |  |  | 66 |      * @param array $data
 | 
        
           |  |  | 67 |      * @param array $files
 | 
        
           |  |  | 68 |      * @return array Error messages
 | 
        
           |  |  | 69 |      */
 | 
        
           |  |  | 70 |     public function validation($data, $files) {
 | 
        
           |  |  | 71 |         $errors = [];
 | 
        
           |  |  | 72 |         if (isset($data['purgeselectedcaches']) && empty(array_filter($data['purgeselectedoptions']))) {
 | 
        
           |  |  | 73 |             $errors['purgeselectedoptions'] = get_string('purgecachesnoneselected', 'admin');
 | 
        
           |  |  | 74 |         }
 | 
        
           |  |  | 75 |         return $errors;
 | 
        
           |  |  | 76 |     }
 | 
        
           |  |  | 77 | }
 |