| 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 | 
            * This file contains the mod_assign useridlist
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * This is for collecting a list of user IDs
  | 
        
        
            | 
            | 
           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 collecting user IDs related to a teacher.
  | 
        
        
            | 
            | 
           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 useridlist {
  | 
        
        
            | 
            | 
           38 | 
              | 
        
        
            | 
            | 
           39 | 
               /** @var int The ID of the teacher. */
  | 
        
        
            | 
            | 
           40 | 
               protected $teacherid;
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
               /** @var int The ID of the assignment object. */
  | 
        
        
            | 
            | 
           43 | 
               protected $assignid;
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /** @var array A collection of user IDs (students). */
  | 
        
        
            | 
            | 
           46 | 
               protected $userids = [];
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
               /**
  | 
        
        
            | 
            | 
           49 | 
                * Create this object.
  | 
        
        
            | 
            | 
           50 | 
                *
  | 
        
        
            | 
            | 
           51 | 
                * @param int $teacherid The teacher ID.
  | 
        
        
            | 
            | 
           52 | 
                * @param int $assignid The assignment ID.
  | 
        
        
            | 
            | 
           53 | 
                */
  | 
        
        
            | 
            | 
           54 | 
               public function __construct($teacherid, $assignid) {
  | 
        
        
            | 
            | 
           55 | 
                   $this->teacherid = $teacherid;
  | 
        
        
            | 
            | 
           56 | 
                   $this->assignid = $assignid;
  | 
        
        
            | 
            | 
           57 | 
               }
  | 
        
        
            | 
            | 
           58 | 
              | 
        
        
            | 
            | 
           59 | 
               /**
  | 
        
        
            | 
            | 
           60 | 
                * Returns the teacher ID.
  | 
        
        
            | 
            | 
           61 | 
                *
  | 
        
        
            | 
            | 
           62 | 
                * @return int The teacher ID.
  | 
        
        
            | 
            | 
           63 | 
                */
  | 
        
        
            | 
            | 
           64 | 
               public function get_teacherid() {
  | 
        
        
            | 
            | 
           65 | 
                   return $this->teacherid;
  | 
        
        
            | 
            | 
           66 | 
               }
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
               /**
  | 
        
        
            | 
            | 
           69 | 
                * Returns the assign ID.
  | 
        
        
            | 
            | 
           70 | 
                *
  | 
        
        
            | 
            | 
           71 | 
                * @return int The assign ID.
  | 
        
        
            | 
            | 
           72 | 
                */
  | 
        
        
            | 
            | 
           73 | 
               public function get_assignid() {
  | 
        
        
            | 
            | 
           74 | 
                   return $this->assignid;
  | 
        
        
            | 
            | 
           75 | 
               }
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
               /**
  | 
        
        
            | 
            | 
           78 | 
                * Returns the user IDs.
  | 
        
        
            | 
            | 
           79 | 
                *
  | 
        
        
            | 
            | 
           80 | 
                * @return array User IDs.
  | 
        
        
            | 
            | 
           81 | 
                */
  | 
        
        
            | 
            | 
           82 | 
               public function get_userids() {
  | 
        
        
            | 
            | 
           83 | 
                   return $this->userids;
  | 
        
        
            | 
            | 
           84 | 
               }
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
               /**
  | 
        
        
            | 
            | 
           87 | 
                * Add sql and params to return user IDs.
  | 
        
        
            | 
            | 
           88 | 
                *
  | 
        
        
            | 
            | 
           89 | 
                * @param string $sql The sql string to return user IDs.
  | 
        
        
            | 
            | 
           90 | 
                * @param array $params Parameters for the sql statement.
  | 
        
        
            | 
            | 
           91 | 
                */
  | 
        
        
            | 
            | 
           92 | 
               public function add_from_sql($sql, $params) {
  | 
        
        
            | 
            | 
           93 | 
                   global $DB;
  | 
        
        
            | 
            | 
           94 | 
                   $userids = $DB->get_records_sql($sql, $params);
  | 
        
        
            | 
            | 
           95 | 
                   if (!empty($userids)) {
  | 
        
        
            | 
            | 
           96 | 
                       $this->userids = array_merge($this->userids, $userids);
  | 
        
        
            | 
            | 
           97 | 
                   }
  | 
        
        
            | 
            | 
           98 | 
               }
  | 
        
        
            | 
            | 
           99 | 
           }
  |