Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]
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 gradereport_grader. 19 * 20 * @package gradereport_grader 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 gradereport_grader\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 require_once $CFG->libdir.'/grade/constants.php'; 34 35 36 /** 37 * Privacy Subsystem for gradereport_grader implementing null_provider. 38 * 39 * @copyright 2018 Sara Arjona <sara@moodle.com> 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class provider implements 43 \core_privacy\local\metadata\provider, 44 \core_privacy\local\request\user_preference_provider { 45 46 /** 47 * Returns meta data about this system. 48 * 49 * @param collection $itemcollection The initialised item collection to add items to. 50 * @return collection A listing of user data stored through this system. 51 */ 52 public static function get_metadata(collection $items) : collection { 53 // There are several user preferences (shared between different courses). 54 // Show/hide toggles preferences. 55 $items->add_user_preference('grade_report_showaverages', 'privacy:metadata:preference:grade_report_showaverages'); 56 $items->add_user_preference('grade_report_showuserimage', 'privacy:metadata:preference:grade_report_showuserimage'); 57 $items->add_user_preference('grade_report_showranges', 'privacy:metadata:preference:grade_report_showranges'); 58 // Special rows preferences. 59 $items->add_user_preference('grade_report_rangesdisplaytype', 'privacy:metadata:preference:grade_report_rangesdisplaytype'); 60 $items->add_user_preference('grade_report_rangesdecimalpoints', 'privacy:metadata:preference:grade_report_rangesdecimalpoints'); 61 $items->add_user_preference('grade_report_averagesdisplaytype', 'privacy:metadata:preference:grade_report_averagesdisplaytype'); 62 $items->add_user_preference('grade_report_averagesdecimalpoints', 'privacy:metadata:preference:grade_report_averagesdecimalpoints'); 63 $items->add_user_preference('grade_report_meanselection', 'privacy:metadata:preference:grade_report_meanselection'); 64 $items->add_user_preference('grade_report_shownumberofgrades', 'privacy:metadata:preference:grade_report_shownumberofgrades'); 65 // General preferences. 66 $items->add_user_preference('grade_report_quickgrading', 'privacy:metadata:preference:grade_report_quickgrading'); 67 $items->add_user_preference('grade_report_studentsperpage', 'privacy:metadata:preference:grade_report_studentsperpage'); 68 $items->add_user_preference('grade_report_showonlyactiveenrol', 'privacy:metadata:preference:grade_report_showonlyactiveenrol'); 69 $items->add_user_preference('grade_report_aggregationposition', 'privacy:metadata:preference:grade_report_aggregationposition'); 70 71 // There is also one user preference which can be defined on each course. 72 $items->add_user_preference('grade_report_grader_collapsed_categories', 'privacy:metadata:preference:grade_report_grader_collapsed_categories'); 73 74 return $items; 75 } 76 77 /** 78 * Store all user preferences for the plugin. 79 * 80 * @param int $userid The userid of the user whose data is to be exported. 81 */ 82 public static function export_user_preferences(int $userid) { 83 $preferences = get_user_preferences(null, null, $userid); 84 foreach ($preferences as $name => $value) { 85 $prefname = null; 86 $prefdescription = null; 87 $transformedvalue = null; 88 switch ($name) { 89 case 'grade_report_showaverages': 90 case 'grade_report_showuserimage': 91 case 'grade_report_showranges': 92 case 'grade_report_shownumberofgrades': 93 case 'grade_report_quickgrading': 94 case 'grade_report_showonlyactiveenrol': 95 case 'grade_report_meanselection': 96 $prefname = $name; 97 switch ($value) { 98 case GRADE_REPORT_MEAN_ALL: 99 $transformedvalue = get_string('meanall', 'grades'); 100 break; 101 case GRADE_REPORT_MEAN_GRADED: 102 $transformedvalue = get_string('meangraded', 'grades'); 103 break; 104 } 105 break; 106 case 'grade_report_rangesdecimalpoints': 107 case 'grade_report_averagesdecimalpoints': 108 case 'grade_report_studentsperpage': 109 $prefname = $name; 110 $transformedvalue = $value; 111 break; 112 case 'grade_report_rangesdisplaytype': 113 case 'grade_report_averagesdisplaytype': 114 $prefname = $name; 115 switch ($value) { 116 case GRADE_REPORT_PREFERENCE_INHERIT: 117 $transformedvalue = get_string('inherit', 'grades'); 118 break; 119 case GRADE_DISPLAY_TYPE_REAL: 120 $transformedvalue = get_string('real', 'grades'); 121 break; 122 case GRADE_DISPLAY_TYPE_PERCENTAGE: 123 $transformedvalue = get_string('percentage', 'grades'); 124 break; 125 case GRADE_DISPLAY_TYPE_LETTER: 126 $transformedvalue = get_string('letter', 'grades'); 127 break; 128 } 129 break; 130 case 'grade_report_aggregationposition': 131 $prefname = $name; 132 switch ($value) { 133 case GRADE_REPORT_AGGREGATION_POSITION_FIRST: 134 $transformedvalue = get_string('positionfirst', 'grades'); 135 break; 136 case GRADE_REPORT_AGGREGATION_POSITION_LAST: 137 $transformedvalue = get_string('positionlast', 'grades'); 138 break; 139 } 140 break; 141 default: 142 if (strpos($name, 'grade_report_grader_collapsed_categories') === 0) { 143 $prefname = 'grade_report_grader_collapsed_categories'; 144 $courseid = substr($name, strlen('grade_report_grader_collapsed_categories')); 145 $transformedvalue = $value; 146 $course = get_course($courseid); 147 $prefdescription = get_string( 148 'privacy:request:preference:'.$prefname, 149 'gradereport_grader', 150 (object) [ 151 'name' => $course->fullname, 152 ] 153 ); 154 } 155 } 156 157 if ($prefname !== null) { 158 if ($prefdescription == null) { 159 $prefdescription = get_string('privacy:metadata:preference:'.$prefname, 'gradereport_grader'); 160 } 161 writer::export_user_preference( 162 'gradereport_grader', 163 $prefname, 164 $transformedvalue, 165 $prefdescription 166 ); 167 } 168 } 169 } 170 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body