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_interactions.
19
 *
20
 * @package    scormreport_interactions
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_interactions\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_interactions.
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(
55
            'scorm_report_interactions_qtext',
56
            'privacy:metadata:preference:scorm_report_interactions_qtext'
57
        );
58
        $collection->add_user_preference(
59
            'scorm_report_interactions_resp',
60
            'privacy:metadata:preference:scorm_report_interactions_resp'
61
        );
62
        $collection->add_user_preference(
63
            'scorm_report_interactions_right',
64
            'privacy:metadata:preference:scorm_report_interactions_right'
65
        );
66
        $collection->add_user_preference(
67
            'scorm_report_interactions_result',
68
            'privacy:metadata:preference:scorm_report_interactions_result'
69
        );
70
 
71
        return $collection;
72
    }
73
 
74
    /**
75
     * Store all user preferences for the plugin.
76
     *
77
     * @param  int $userid The userid of the user whose data is to be exported.
78
     */
79
    public static function export_user_preferences(int $userid) {
80
        static::get_and_export_user_preference($userid, 'scorm_report_pagesize');
81
        static::get_and_export_user_preference($userid, 'scorm_report_interactions_qtext', true);
82
        static::get_and_export_user_preference($userid, 'scorm_report_interactions_resp', true);
83
        static::get_and_export_user_preference($userid, 'scorm_report_interactions_right', true);
84
        static::get_and_export_user_preference($userid, 'scorm_report_interactions_result', true);
85
    }
86
 
87
    /**
88
     * Get and export a user preference.
89
     *
90
     * @param  int     $userid The userid of the user whose data is to be exported.
91
     * @param  string  $userpreference The user preference to export.
92
     * @param  boolean $transform If true, transform value to yesno.
93
     */
94
    protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) {
95
        $prefvalue = get_user_preferences($userpreference, null, $userid);
96
        if ($prefvalue !== null) {
97
            if ($transform) {
98
                $transformedvalue = transform::yesno($prefvalue);
99
            } else {
100
                $transformedvalue = $prefvalue;
101
            }
102
            writer::export_user_preference(
103
                'scormreport_interactions',
104
                $userpreference,
105
                $transformedvalue,
106
                get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_interactions')
107
            );
108
        }
109
    }
110
}