Differences Between: [Versions 311 and 402] [Versions 311 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_showcalculations', 'privacy:metadata:preference:grade_report_showcalculations'); 56 $items->add_user_preference('grade_report_showeyecons', 'privacy:metadata:preference:grade_report_showeyecons'); 57 $items->add_user_preference('grade_report_showaverages', 'privacy:metadata:preference:grade_report_showaverages'); 58 $items->add_user_preference('grade_report_showlocks', 'privacy:metadata:preference:grade_report_showlocks'); 59 $items->add_user_preference('grade_report_showuserimage', 'privacy:metadata:preference:grade_report_showuserimage'); 60 $items->add_user_preference('grade_report_showactivityicons', 'privacy:metadata:preference:grade_report_showactivityicons'); 61 $items->add_user_preference('grade_report_showranges', 'privacy:metadata:preference:grade_report_showranges'); 62 $items->add_user_preference('grade_report_showanalysisicon', 'privacy:metadata:preference:grade_report_showanalysisicon'); 63 // Special rows preferences. 64 $items->add_user_preference('grade_report_rangesdisplaytype', 'privacy:metadata:preference:grade_report_rangesdisplaytype'); 65 $items->add_user_preference('grade_report_rangesdecimalpoints', 'privacy:metadata:preference:grade_report_rangesdecimalpoints'); 66 $items->add_user_preference('grade_report_averagesdisplaytype', 'privacy:metadata:preference:grade_report_averagesdisplaytype'); 67 $items->add_user_preference('grade_report_averagesdecimalpoints', 'privacy:metadata:preference:grade_report_averagesdecimalpoints'); 68 $items->add_user_preference('grade_report_meanselection', 'privacy:metadata:preference:grade_report_meanselection'); 69 $items->add_user_preference('grade_report_shownumberofgrades', 'privacy:metadata:preference:grade_report_shownumberofgrades'); 70 // General preferences. 71 $items->add_user_preference('grade_report_quickgrading', 'privacy:metadata:preference:grade_report_quickgrading'); 72 $items->add_user_preference('grade_report_showquickfeedback', 'privacy:metadata:preference:grade_report_showquickfeedback'); 73 $items->add_user_preference('grade_report_studentsperpage', 'privacy:metadata:preference:grade_report_studentsperpage'); 74 $items->add_user_preference('grade_report_showonlyactiveenrol', 'privacy:metadata:preference:grade_report_showonlyactiveenrol'); 75 $items->add_user_preference('grade_report_aggregationposition', 'privacy:metadata:preference:grade_report_aggregationposition'); 76 $items->add_user_preference('grade_report_enableajax', 'privacy:metadata:preference:grade_report_enableajax'); 77 78 // There is also one user preference which can be defined on each course. 79 $items->add_user_preference('grade_report_grader_collapsed_categories', 'privacy:metadata:preference:grade_report_grader_collapsed_categories'); 80 81 return $items; 82 } 83 84 /** 85 * Store all user preferences for the plugin. 86 * 87 * @param int $userid The userid of the user whose data is to be exported. 88 */ 89 public static function export_user_preferences(int $userid) { 90 $preferences = get_user_preferences(null, null, $userid); 91 foreach ($preferences as $name => $value) { 92 $prefname = null; 93 $prefdescription = null; 94 $transformedvalue = null; 95 switch ($name) { 96 case 'grade_report_showcalculations': 97 case 'grade_report_showeyecons': 98 case 'grade_report_showaverages': 99 case 'grade_report_showlocks': 100 case 'grade_report_showuserimage': 101 case 'grade_report_showactivityicons': 102 case 'grade_report_showranges': 103 case 'grade_report_showanalysisicon': 104 case 'grade_report_shownumberofgrades': 105 case 'grade_report_quickgrading': 106 case 'grade_report_showonlyactiveenrol': 107 case 'grade_report_showquickfeedback': 108 case 'grade_report_enableajax': 109 $prefname = $name; 110 $transformedvalue = transform::yesno($value); 111 break; 112 case 'grade_report_meanselection': 113 $prefname = $name; 114 switch ($value) { 115 case GRADE_REPORT_MEAN_ALL: 116 $transformedvalue = get_string('meanall', 'grades'); 117 break; 118 case GRADE_REPORT_MEAN_GRADED: 119 $transformedvalue = get_string('meangraded', 'grades'); 120 break; 121 } 122 break; 123 case 'grade_report_rangesdecimalpoints': 124 case 'grade_report_averagesdecimalpoints': 125 case 'grade_report_studentsperpage': 126 $prefname = $name; 127 $transformedvalue = $value; 128 break; 129 case 'grade_report_rangesdisplaytype': 130 case 'grade_report_averagesdisplaytype': 131 $prefname = $name; 132 switch ($value) { 133 case GRADE_REPORT_PREFERENCE_INHERIT: 134 $transformedvalue = get_string('inherit', 'grades'); 135 break; 136 case GRADE_DISPLAY_TYPE_REAL: 137 $transformedvalue = get_string('real', 'grades'); 138 break; 139 case GRADE_DISPLAY_TYPE_PERCENTAGE: 140 $transformedvalue = get_string('percentage', 'grades'); 141 break; 142 case GRADE_DISPLAY_TYPE_LETTER: 143 $transformedvalue = get_string('letter', 'grades'); 144 break; 145 } 146 break; 147 case 'grade_report_aggregationposition': 148 $prefname = $name; 149 switch ($value) { 150 case GRADE_REPORT_AGGREGATION_POSITION_FIRST: 151 $transformedvalue = get_string('positionfirst', 'grades'); 152 break; 153 case GRADE_REPORT_AGGREGATION_POSITION_LAST: 154 $transformedvalue = get_string('positionlast', 'grades'); 155 break; 156 } 157 break; 158 default: 159 if (strpos($name, 'grade_report_grader_collapsed_categories') === 0) { 160 $prefname = 'grade_report_grader_collapsed_categories'; 161 $courseid = substr($name, strlen('grade_report_grader_collapsed_categories')); 162 $transformedvalue = $value; 163 $course = get_course($courseid); 164 $prefdescription = get_string( 165 'privacy:request:preference:'.$prefname, 166 'gradereport_grader', 167 (object) [ 168 'name' => $course->fullname, 169 ] 170 ); 171 } 172 } 173 174 if ($prefname !== null) { 175 if ($prefdescription == null) { 176 $prefdescription = get_string('privacy:metadata:preference:'.$prefname, 'gradereport_grader'); 177 } 178 writer::export_user_preference( 179 'gradereport_grader', 180 $prefname, 181 $transformedvalue, 182 $prefdescription 183 ); 184 } 185 } 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body