See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [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 * This file contains the mod_assign assign_plugin_request_data class 19 * 20 * For assign plugin privacy data to fulfill requests. 21 * 22 * @package mod_assign 23 * @copyright 2018 Adrian Greeve <adrian@moodle.com> 24 * 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 namespace mod_assign\privacy; 28 29 defined('MOODLE_INTERNAL') || die(); 30 31 /** 32 * An object for fulfilling an assign plugin data request. 33 * 34 * @copyright 2018 Adrian Greeve <adrian@moodle.com> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class assign_plugin_request_data { 38 39 /** @var context The context that we are dealing with. */ 40 protected $context; 41 42 /** @var object For submisisons the submission object, for feedback the grade object. */ 43 protected $pluginobject; 44 45 /** @var array The path or location that we are exporting data to. */ 46 protected $subcontext; 47 48 /** @var object If set then only export data related directly to this user. */ 49 protected $user; 50 51 /** @var array The user IDs of the users that will be affected. */ 52 protected $userids; 53 54 /** @var array The submissions related to the users added. */ 55 protected $submissions = []; 56 57 /** @var array The grades related to the users added. */ 58 protected $grades = []; 59 60 /** @var assign The assign object */ 61 protected $assign; 62 63 /** 64 * Object creator for assign plugin request data. 65 * 66 * @param \context $context Context object. 67 * @param \stdClass $pluginobject The grade object. 68 * @param array $subcontext Directory / file location. 69 * @param \stdClass $user The user object. 70 * @param \assign $assign The assign object. 71 */ 72 public function __construct(\context $context, \assign $assign, \stdClass $pluginobject = null, array $subcontext = [], 73 \stdClass $user = null) { 74 $this->context = $context; 75 $this->pluginobject = $pluginobject; 76 $this->subcontext = $subcontext; 77 $this->user = $user; 78 $this->assign = $assign; 79 } 80 81 /** 82 * Method for adding an array of user IDs. This will do a query to populate the submissions and grades 83 * for these users. 84 * 85 * @param array $userids User IDs to do something with. 86 */ 87 public function set_userids(array $userids) { 88 $this->userids = $userids; 89 } 90 91 /** 92 * Getter for this attribute. 93 * 94 * @return context Context 95 */ 96 public function get_context() { 97 return $this->context; 98 } 99 100 /** 101 * Getter for this attribute. 102 * 103 * @return object The assign plugin object 104 */ 105 public function get_pluginobject() { 106 return $this->pluginobject; 107 } 108 109 /** 110 * Getter for this attribute. 111 * 112 * @return array The location (path) that this data is being writter to. 113 */ 114 public function get_subcontext() { 115 return $this->subcontext; 116 } 117 118 /** 119 * Getter for this attribute. 120 * 121 * @return object The user id. If set then only information directly related to this user ID will be returned. 122 */ 123 public function get_user() { 124 return $this->user; 125 } 126 127 /** 128 * Getter for this attribute. 129 * 130 * @return assign The assign object. 131 */ 132 public function get_assign() { 133 return $this->assign; 134 } 135 136 /** 137 * A method to conveniently fetch the assign id. 138 * 139 * @return int The assign id. 140 */ 141 public function get_assignid() { 142 return $this->assign->get_instance()->id; 143 } 144 145 /** 146 * Get all of the user IDs 147 * 148 * @return array User IDs 149 */ 150 public function get_userids() { 151 return $this->userids; 152 } 153 154 /** 155 * Returns all of the submission IDs 156 * 157 * @return array submission IDs 158 */ 159 public function get_submissionids() { 160 return array_keys($this->submissions); 161 } 162 163 /** 164 * Returns the submissions related to the user IDs 165 * 166 * @return array User submissions. 167 */ 168 public function get_submissions() { 169 return $this->submissions; 170 } 171 172 /** 173 * Returns the grade IDs related to the user IDs 174 * 175 * @return array User grade IDs. 176 */ 177 public function get_gradeids() { 178 return array_keys($this->grades); 179 } 180 181 /** 182 * Returns the grades related to the user IDs 183 * 184 * @return array User grades. 185 */ 186 public function get_grades() { 187 return $this->grades; 188 } 189 190 /** 191 * Fetches all of the submissions and grades related to the User IDs provided. Use get_grades, get_submissions etc to 192 * retrieve this information. 193 */ 194 public function populate_submissions_and_grades() { 195 global $DB; 196 197 if (empty($this->get_userids())) { 198 throw new \coding_exception('Please use set_userids() before calling this method.'); 199 } 200 201 list($sql, $params) = $DB->get_in_or_equal($this->get_userids(), SQL_PARAMS_NAMED); 202 $params['assign'] = $this->get_assign()->get_instance()->id; 203 $this->submissions = $DB->get_records_select('assign_submission', "assignment = :assign AND userid $sql", $params); 204 $this->grades = $DB->get_records_select('assign_grades', "assignment = :assign AND userid $sql", $params); 205 } 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body