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
 * Privacy Subsystem implementation for scormreport_basic.
19
 *
20
 * @package    scormreport_basic
21
 * @copyright  2018 Sara Arjona <sara@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace scormreport_basic\privacy;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
use \core_privacy\local\metadata\collection;
30
use \core_privacy\local\request\transform;
31
use \core_privacy\local\request\writer;
32
 
33
/**
34
 * Privacy Subsystem for scormreport_basic.
35
 *
36
 * @copyright  2018 Sara Arjona <sara@moodle.com>
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class provider implements
40
    \core_privacy\local\metadata\provider,
41
    \core_privacy\local\request\user_preference_provider {
42
 
43
    /**
44
     * Returns meta data about this system.
45
     *
46
     * @param  collection $collection The initialised item collection to add items to.
47
     * @return collection A listing of user data stored through this system.
48
     */
49
    public static function get_metadata(collection $collection): collection {
50
        // User preferences shared between different scorm reports.
51
        $collection->add_user_preference('scorm_report_pagesize', 'privacy:metadata:preference:scorm_report_pagesize');
52
 
53
        // User preferences specific for this scorm report.
54
        $collection->add_user_preference('scorm_report_detailed', 'privacy:metadata:preference:scorm_report_detailed');
55
 
56
        return $collection;
57
    }
58
 
59
    /**
60
     * Store all user preferences for the plugin.
61
     *
62
     * @param  int $userid The userid of the user whose data is to be exported.
63
     */
64
    public static function export_user_preferences(int $userid) {
65
        static::get_and_export_user_preference($userid, 'scorm_report_pagesize');
66
        static::get_and_export_user_preference($userid, 'scorm_report_detailed', true);
67
    }
68
 
69
    /**
70
     * Get and export a user preference.
71
     *
72
     * @param  int     $userid The userid of the user whose data is to be exported.
73
     * @param  string  $userpreference The user preference to export.
74
     * @param  boolean $transform If true, transform value to yesno.
75
     */
76
    protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) {
77
        $prefvalue = get_user_preferences($userpreference, null, $userid);
78
        if ($prefvalue !== null) {
79
            if ($transform) {
80
                $transformedvalue = transform::yesno($prefvalue);
81
            } else {
82
                $transformedvalue = $prefvalue;
83
            }
84
            writer::export_user_preference(
85
                'scormreport_basic',
86
                $userpreference,
87
                $transformedvalue,
88
                get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_basic')
89
            );
90
        }
91
    }
92
}