Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Backups filtering class
19
 *
20
 * @package    report_allbackups
21
 * @copyright  2020 Catalyst IT
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace report_allbackups\output;
26
use report_allbackups\filters\coursecategoryfilter;
27
defined('MOODLE_INTERNAL') || die();
28
 
29
require_once($CFG->dirroot.'/user/filters/lib.php');
30
 
31
/**
32
 * Class filtering based on core user_filtering class, with extra filter for filename.
33
 *
34
 * @package    report_allbackups
35
 * @copyright  2020 Catalyst IT
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class filtering extends \user_filtering {
39
 
40
    /**
41
     * Adds handling for custom fieldnames.
42
     * @param string $fieldname
43
     * @param boolean $advanced
44
     * @return object filter
45
     */
46
    public function get_field($fieldname, $advanced) {
47
        if ($fieldname == 'filename') {
48
            return new \user_filter_text('filename', get_string('filename', 'report_allbackups'), $advanced, 'filename');
49
        }
50
        if ($fieldname == 'timecreated') {
51
            return new \user_filter_date('timecreated', get_string('date'), $advanced, 'f.timecreated');
52
        }
53
        if ($fieldname == 'filearea') {
54
            return new \user_filter_simpleselect('filearea', get_string('filearea', 'report_allbackups'),
55
                $advanced, 'f.filearea', $this->getfileareas());
56
        }
57
        if ($fieldname == 'coursecategory') {
58
            return new coursecategoryfilter('coursecategory', get_string('coursecategory', 'report_allbackups'),
59
                $advanced, 'c.category', \core_course_category::make_categories_list());
60
        }
61
        return parent::get_field($fieldname, $advanced);
62
    }
63
 
64
    /**
65
     * Helper function to get list of fileareas to use in filter.
66
     *
67
     * @return array
68
     * @throws \dml_exception
69
     */
70
    private static function getfileareas() {
71
        global $DB;
72
        $sql = "SELECT DISTINCT filearea, filearea as name
73
                 FROM {files}
74
                 WHERE filename like '%.mbz' and component <> 'tool_recyclebin' and filearea <> 'draft'";
75
        return $DB->get_records_sql_menu($sql);
76
    }
77
}