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
 * Class for loading/storing data categories from the DB.
19
 *
20
 * @package    tool_dataprivacy
21
 * @copyright  2018 David Monllao
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
namespace tool_dataprivacy;
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');
28
 
29
/**
30
 * Class for loading/storing data categories from the DB.
31
 *
32
 * @copyright  2018 David Monllao
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class category extends \core\persistent {
36
 
37
    /**
38
     * Database table.
39
     */
40
    const TABLE = 'tool_dataprivacy_category';
41
 
42
    /**
43
     * Return the definition of the properties of this model.
44
     *
45
     * @return array
46
     */
47
    protected static function define_properties() {
48
        return array(
49
            'name' => array(
50
                'type' => PARAM_TEXT,
51
                'description' => 'The category name.',
52
            ),
53
            'description' => array(
54
                'type' => PARAM_RAW,
55
                'description' => 'The category description.',
56
                'null' => NULL_ALLOWED,
57
                'default' => '',
58
            ),
59
            'descriptionformat' => array(
60
                'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
61
                'type' => PARAM_INT,
62
                'default' => FORMAT_HTML
63
            ),
64
        );
65
    }
66
 
67
    /**
68
     * Is this category used?.
69
     *
70
     * @return null
71
     */
72
    public function is_used() {
73
 
74
        if (\tool_dataprivacy\contextlevel::is_category_used($this->get('id')) ||
75
                \tool_dataprivacy\context_instance::is_category_used($this->get('id'))) {
76
            return true;
77
        }
78
 
79
        $pluginconfig = get_config('tool_dataprivacy');
80
        $levels = \context_helper::get_all_levels();
81
        foreach ($levels as $level => $classname) {
82
 
83
            list($unused, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname);
84
            if (!empty($pluginconfig->{$categoryvar}) && $pluginconfig->{$categoryvar} == $this->get('id')) {
85
                return true;
86
            }
87
        }
88
 
89
        return false;
90
    }
91
}