Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402] [Versions 402 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   * Renderable that initialises the grading "app".
  19   *
  20   * @package    mod_assign
  21   * @copyright  2016 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_assign\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use renderer_base;
  30  use renderable;
  31  use templatable;
  32  use stdClass;
  33  
  34  /**
  35   * Grading app renderable.
  36   *
  37   * @package    mod_assign
  38   * @since      Moodle 3.1
  39   * @copyright  2016 Damyon Wiese
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class grading_app implements templatable, renderable {
  43  
  44      /**
  45       * @var $userid - The initial user id.
  46       */
  47      public $userid = 0;
  48  
  49      /**
  50       * @var $groupid - The initial group id.
  51       */
  52      public $groupid = 0;
  53  
  54      /**
  55       * @var $assignment - The assignment instance.
  56       */
  57      public $assignment = null;
  58  
  59      /**
  60       * @var array - List of user records with extra fields.
  61       */
  62      public $participants = [];
  63  
  64      /**
  65       * Constructor for this renderable.
  66       *
  67       * @param int $userid The user we will open the grading app too.
  68       * @param int $groupid If groups are enabled this is the current course group.
  69       * @param \assign $assignment The assignment class
  70       */
  71      public function __construct($userid, $groupid, $assignment) {
  72          $this->userid = $userid;
  73          $this->groupid = $groupid;
  74          $this->assignment = $assignment;
  75          user_preference_allow_ajax_update('assign_filter', PARAM_ALPHA);
  76          user_preference_allow_ajax_update('assign_workflowfilter', PARAM_ALPHA);
  77          user_preference_allow_ajax_update('assign_markerfilter', PARAM_ALPHANUMEXT);
  78          $this->participants = $assignment->list_participants_with_filter_status_and_group($groupid);
  79          if (!$this->userid && count($this->participants)) {
  80              $this->userid = reset($this->participants)->id;
  81          }
  82      }
  83  
  84      /**
  85       * Export this class data as a flat list for rendering in a template.
  86       *
  87       * @param renderer_base $output The current page renderer.
  88       * @return stdClass - Flat list of exported data.
  89       */
  90      public function export_for_template(renderer_base $output) {
  91          global $CFG, $USER;
  92  
  93          $export = new stdClass();
  94          $export->userid = $this->userid;
  95          $export->assignmentid = $this->assignment->get_instance()->id;
  96          $export->cmid = $this->assignment->get_course_module()->id;
  97          $export->contextid = $this->assignment->get_context()->id;
  98          $export->groupid = $this->groupid;
  99          $export->name = $this->assignment->get_context()->get_context_name(true, false, false);
 100          $export->courseid = $this->assignment->get_course()->id;
 101          $export->participants = array();
 102          $export->filters = $this->assignment->get_filters();
 103          $export->markingworkflowfilters = $this->assignment->get_marking_workflow_filters(true);
 104          $export->hasmarkingworkflow = count($export->markingworkflowfilters) > 0;
 105          $export->markingallocationfilters = $this->assignment->get_marking_allocation_filters(true);
 106          $export->hasmarkingallocation = count($export->markingallocationfilters) > 0;
 107  
 108          $num = 1;
 109          foreach ($this->participants as $idx => $record) {
 110              $user = new stdClass();
 111              $user->id = $record->id;
 112              $user->fullname = fullname($record);
 113              $user->requiregrading = $record->requiregrading;
 114              $user->grantedextension = $record->grantedextension;
 115              $user->submitted = $record->submitted;
 116              if (!empty($record->groupid)) {
 117                  $user->groupid = $record->groupid;
 118                  $user->groupname = $record->groupname;
 119              }
 120              if ($record->id == $this->userid) {
 121                  $export->index = $num;
 122                  $user->current = true;
 123              }
 124              $export->participants[] = $user;
 125              $num++;
 126          }
 127  
 128          $feedbackplugins = $this->assignment->get_feedback_plugins();
 129          $showreview = false;
 130          foreach ($feedbackplugins as $plugin) {
 131              if ($plugin->is_enabled() && $plugin->is_visible()) {
 132                  if ($plugin->supports_review_panel()) {
 133                      $showreview = true;
 134                  }
 135              }
 136          }
 137  
 138          $export->actiongrading = 'grading';
 139          $export->viewgrading = get_string('viewgrading', 'mod_assign');
 140  
 141          $export->showreview = $showreview;
 142  
 143          $time = time();
 144          $export->count = count($export->participants);
 145          $export->coursename = $this->assignment->get_course_context()->get_context_name(true, false, false);
 146          $export->caneditsettings = has_capability('mod/assign:addinstance', $this->assignment->get_context());
 147          $export->duedate = $this->assignment->get_instance()->duedate;
 148          $export->duedatestr = userdate($this->assignment->get_instance()->duedate);
 149  
 150          // Time remaining.
 151          $due = '';
 152          if ($export->duedate - $time <= 0) {
 153              $due = get_string('assignmentisdue', 'assign');
 154          } else {
 155              $due = get_string('timeremainingcolon', 'assign', format_time($export->duedate - $time));
 156          }
 157          $export->timeremainingstr = $due;
 158  
 159          if ($export->duedate < $time) {
 160              $export->cutoffdate = $this->assignment->get_instance()->cutoffdate;
 161              $cutoffdate = $export->cutoffdate;
 162              if ($cutoffdate) {
 163                  if ($cutoffdate > $time) {
 164                      $late = get_string('latesubmissionsaccepted', 'assign', userdate($export->cutoffdate));
 165                  } else {
 166                      $late = get_string('nomoresubmissionsaccepted', 'assign');
 167                  }
 168                  $export->cutoffdatestr = $late;
 169              }
 170          }
 171  
 172          $export->defaultsendnotifications = $this->assignment->get_instance()->sendstudentnotifications;
 173          $export->rarrow = $output->rarrow();
 174          $export->larrow = $output->larrow();
 175          // List of identity fields to display (the user info will not contain any fields the user cannot view anyway).
 176          // TODO Does not support custom user profile fields (MDL-70456).
 177          $export->showuseridentity = implode(',', \core_user\fields::get_identity_fields(null, false));
 178          $export->currentuserid = $USER->id;
 179          $helpicon = new \help_icon('sendstudentnotifications', 'assign');
 180          $export->helpicon = $helpicon->export_for_template($output);
 181          return $export;
 182      }
 183  
 184  }