Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [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 definition for the renderable classes for the assignment
  19   *
  20   * @package   mod_assign
  21   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use \mod_assign\output\assign_submission_status;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * This class wraps the submit for grading confirmation page
  31   * @package   mod_assign
  32   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class assign_submit_for_grading_page implements renderable {
  36      /** @var array $notifications is a list of notification messages returned from the plugins */
  37      public $notifications = array();
  38      /** @var int $coursemoduleid */
  39      public $coursemoduleid = 0;
  40      /** @var moodleform $confirmform */
  41      public $confirmform = null;
  42  
  43      /**
  44       * Constructor
  45       * @param string $notifications - Any mesages to display
  46       * @param int $coursemoduleid
  47       * @param moodleform $confirmform
  48       */
  49      public function __construct($notifications, $coursemoduleid, $confirmform) {
  50          $this->notifications = $notifications;
  51          $this->coursemoduleid = $coursemoduleid;
  52          $this->confirmform = $confirmform;
  53      }
  54  
  55  }
  56  
  57  /**
  58   * Implements a renderable message notification
  59   * @package   mod_assign
  60   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  61   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  62   */
  63  class assign_gradingmessage implements renderable {
  64      /** @var string $heading is the heading to display to the user */
  65      public $heading = '';
  66      /** @var string $message is the message to display to the user */
  67      public $message = '';
  68      /** @var int $coursemoduleid */
  69      public $coursemoduleid = 0;
  70      /** @var int $gradingerror should be set true if there was a problem grading */
  71      public $gradingerror = null;
  72  
  73      /**
  74       * Constructor
  75       * @param string $heading This is the heading to display
  76       * @param string $message This is the message to display
  77       * @param bool $gradingerror Set to true to display the message as an error.
  78       * @param int $coursemoduleid
  79       * @param int $page This is the current quick grading page
  80       */
  81      public function __construct($heading, $message, $coursemoduleid, $gradingerror = false, $page = null) {
  82          $this->heading = $heading;
  83          $this->message = $message;
  84          $this->coursemoduleid = $coursemoduleid;
  85          $this->gradingerror = $gradingerror;
  86          $this->page = $page;
  87      }
  88  
  89  }
  90  
  91  /**
  92   * Implements a renderable grading options form
  93   * @package   mod_assign
  94   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  95   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  96   */
  97  class assign_form implements renderable {
  98      /** @var moodleform $form is the edit submission form */
  99      public $form = null;
 100      /** @var string $classname is the name of the class to assign to the container */
 101      public $classname = '';
 102      /** @var string $jsinitfunction is an optional js function to add to the page requires */
 103      public $jsinitfunction = '';
 104  
 105      /**
 106       * Constructor
 107       * @param string $classname This is the class name for the container div
 108       * @param moodleform $form This is the moodleform
 109       * @param string $jsinitfunction This is an optional js function to add to the page requires
 110       */
 111      public function __construct($classname, moodleform $form, $jsinitfunction = '') {
 112          $this->classname = $classname;
 113          $this->form = $form;
 114          $this->jsinitfunction = $jsinitfunction;
 115      }
 116  
 117  }
 118  
 119  /**
 120   * Implements a renderable user summary
 121   * @package   mod_assign
 122   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 123   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 124   */
 125  class assign_user_summary implements renderable {
 126      /** @var stdClass $user suitable for rendering with user_picture and fullname(). */
 127      public $user = null;
 128      /** @var int $courseid */
 129      public $courseid;
 130      /** @var bool $viewfullnames */
 131      public $viewfullnames = false;
 132      /** @var bool $blindmarking */
 133      public $blindmarking = false;
 134      /** @var int $uniqueidforuser */
 135      public $uniqueidforuser;
 136      /** @var array $extrauserfields */
 137      public $extrauserfields;
 138      /** @var bool $suspendeduser */
 139      public $suspendeduser;
 140  
 141      /**
 142       * Constructor
 143       * @param stdClass $user
 144       * @param int $courseid
 145       * @param bool $viewfullnames
 146       * @param bool $blindmarking
 147       * @param int $uniqueidforuser
 148       * @param array $extrauserfields
 149       * @param bool $suspendeduser
 150       */
 151      public function __construct(stdClass $user,
 152                                  $courseid,
 153                                  $viewfullnames,
 154                                  $blindmarking,
 155                                  $uniqueidforuser,
 156                                  $extrauserfields,
 157                                  $suspendeduser = false) {
 158          $this->user = $user;
 159          $this->courseid = $courseid;
 160          $this->viewfullnames = $viewfullnames;
 161          $this->blindmarking = $blindmarking;
 162          $this->uniqueidforuser = $uniqueidforuser;
 163          $this->extrauserfields = $extrauserfields;
 164          $this->suspendeduser = $suspendeduser;
 165      }
 166  }
 167  
 168  /**
 169   * Implements a renderable feedback plugin feedback
 170   * @package   mod_assign
 171   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 172   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 173   */
 174  class assign_feedback_plugin_feedback implements renderable {
 175      /** @var int SUMMARY */
 176      const SUMMARY                = 10;
 177      /** @var int FULL */
 178      const FULL                   = 20;
 179  
 180      /** @var assign_submission_plugin $plugin */
 181      public $plugin = null;
 182      /** @var stdClass $grade */
 183      public $grade = null;
 184      /** @var string $view */
 185      public $view = self::SUMMARY;
 186      /** @var int $coursemoduleid */
 187      public $coursemoduleid = 0;
 188      /** @var string returnaction The action to take you back to the current page */
 189      public $returnaction = '';
 190      /** @var array returnparams The params to take you back to the current page */
 191      public $returnparams = array();
 192  
 193      /**
 194       * Feedback for a single plugin
 195       *
 196       * @param assign_feedback_plugin $plugin
 197       * @param stdClass $grade
 198       * @param string $view one of feedback_plugin::SUMMARY or feedback_plugin::FULL
 199       * @param int $coursemoduleid
 200       * @param string $returnaction The action required to return to this page
 201       * @param array $returnparams The params required to return to this page
 202       */
 203      public function __construct(assign_feedback_plugin $plugin,
 204                                  stdClass $grade,
 205                                  $view,
 206                                  $coursemoduleid,
 207                                  $returnaction,
 208                                  $returnparams) {
 209          $this->plugin = $plugin;
 210          $this->grade = $grade;
 211          $this->view = $view;
 212          $this->coursemoduleid = $coursemoduleid;
 213          $this->returnaction = $returnaction;
 214          $this->returnparams = $returnparams;
 215      }
 216  
 217  }
 218  
 219  /**
 220   * Implements a renderable submission plugin submission
 221   * @package   mod_assign
 222   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 223   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 224   */
 225  class assign_submission_plugin_submission implements renderable {
 226      /** @var int SUMMARY */
 227      const SUMMARY                = 10;
 228      /** @var int FULL */
 229      const FULL                   = 20;
 230  
 231      /** @var assign_submission_plugin $plugin */
 232      public $plugin = null;
 233      /** @var stdClass $submission */
 234      public $submission = null;
 235      /** @var string $view */
 236      public $view = self::SUMMARY;
 237      /** @var int $coursemoduleid */
 238      public $coursemoduleid = 0;
 239      /** @var string returnaction The action to take you back to the current page */
 240      public $returnaction = '';
 241      /** @var array returnparams The params to take you back to the current page */
 242      public $returnparams = array();
 243  
 244      /**
 245       * Constructor
 246       * @param assign_submission_plugin $plugin
 247       * @param stdClass $submission
 248       * @param string $view one of submission_plugin::SUMMARY, submission_plugin::FULL
 249       * @param int $coursemoduleid - the course module id
 250       * @param string $returnaction The action to return to the current page
 251       * @param array $returnparams The params to return to the current page
 252       */
 253      public function __construct(assign_submission_plugin $plugin,
 254                                  stdClass $submission,
 255                                  $view,
 256                                  $coursemoduleid,
 257                                  $returnaction,
 258                                  $returnparams) {
 259          $this->plugin = $plugin;
 260          $this->submission = $submission;
 261          $this->view = $view;
 262          $this->coursemoduleid = $coursemoduleid;
 263          $this->returnaction = $returnaction;
 264          $this->returnparams = $returnparams;
 265      }
 266  }
 267  
 268  /**
 269   * Renderable feedback status
 270   * @package   mod_assign
 271   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 272   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 273   */
 274  class assign_feedback_status implements renderable {
 275  
 276      /** @var string $gradefordisplay the student grade rendered into a format suitable for display */
 277      public $gradefordisplay = '';
 278      /** @var mixed the graded date (may be null) */
 279      public $gradeddate = 0;
 280      /** @var mixed the grader (may be null) */
 281      public $grader = null;
 282      /** @var array feedbackplugins - array of feedback plugins */
 283      public $feedbackplugins = array();
 284      /** @var stdClass assign_grade record */
 285      public $grade = null;
 286      /** @var int coursemoduleid */
 287      public $coursemoduleid = 0;
 288      /** @var string returnaction */
 289      public $returnaction = '';
 290      /** @var array returnparams */
 291      public $returnparams = array();
 292      /** @var bool canviewfullnames */
 293      public $canviewfullnames = false;
 294      /** @var string gradingcontrollergrade The grade information rendered by a grade controller */
 295      public $gradingcontrollergrade;
 296  
 297      /**
 298       * Constructor
 299       * @param string $gradefordisplay
 300       * @param mixed $gradeddate
 301       * @param mixed $grader
 302       * @param array $feedbackplugins
 303       * @param mixed $grade
 304       * @param int $coursemoduleid
 305       * @param string $returnaction The action required to return to this page
 306       * @param array $returnparams The list of params required to return to this page
 307       * @param bool $canviewfullnames
 308       * @param string $gradingcontrollergrade The grade information rendered by a grade controller
 309       */
 310      public function __construct($gradefordisplay,
 311                                  $gradeddate,
 312                                  $grader,
 313                                  $feedbackplugins,
 314                                  $grade,
 315                                  $coursemoduleid,
 316                                  $returnaction,
 317                                  $returnparams,
 318                                  $canviewfullnames,
 319                                  $gradingcontrollergrade = '') {
 320          $this->gradefordisplay = $gradefordisplay;
 321          $this->gradeddate = $gradeddate;
 322          $this->grader = $grader;
 323          $this->feedbackplugins = $feedbackplugins;
 324          $this->grade = $grade;
 325          $this->coursemoduleid = $coursemoduleid;
 326          $this->returnaction = $returnaction;
 327          $this->returnparams = $returnparams;
 328          $this->canviewfullnames = $canviewfullnames;
 329          $this->gradingcontrollergrade = $gradingcontrollergrade;
 330      }
 331  }
 332  
 333  /**
 334   * Renderable submission status
 335   * @package   mod_assign
 336   * @copyright 2016 Damyon Wiese
 337   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 338   */
 339  class assign_submission_status_compact extends assign_submission_status implements renderable {
 340      // Compact view of the submission status. Not in a table etc.
 341  }
 342  
 343  /**
 344   * Used to output the attempt history for a particular assignment.
 345   *
 346   * @package mod_assign
 347   * @copyright 2012 Davo Smith, Synergy Learning
 348   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 349   */
 350  class assign_attempt_history implements renderable {
 351  
 352      /** @var array submissions - The list of previous attempts */
 353      public $submissions = array();
 354      /** @var array grades - The grades for the previous attempts */
 355      public $grades = array();
 356      /** @var array submissionplugins - The list of submission plugins to render the previous attempts */
 357      public $submissionplugins = array();
 358      /** @var array feedbackplugins - The list of feedback plugins to render the previous attempts */
 359      public $feedbackplugins = array();
 360      /** @var int coursemoduleid - The cmid for the assignment */
 361      public $coursemoduleid = 0;
 362      /** @var string returnaction - The action for the next page. */
 363      public $returnaction = '';
 364      /** @var string returnparams - The params for the next page. */
 365      public $returnparams = array();
 366      /** @var bool cangrade - Does this user have grade capability? */
 367      public $cangrade = false;
 368      /** @var string useridlistid - Id of the useridlist stored in cache, this plus rownum determines the userid */
 369      public $useridlistid = 0;
 370      /** @var int rownum - The rownum of the user in the useridlistid - this plus useridlistid determines the userid */
 371      public $rownum = 0;
 372  
 373      /**
 374       * Constructor
 375       *
 376       * @param array $submissions
 377       * @param array $grades
 378       * @param array $submissionplugins
 379       * @param array $feedbackplugins
 380       * @param int $coursemoduleid
 381       * @param string $returnaction
 382       * @param array $returnparams
 383       * @param bool $cangrade
 384       * @param int $useridlistid
 385       * @param int $rownum
 386       */
 387      public function __construct($submissions,
 388                                  $grades,
 389                                  $submissionplugins,
 390                                  $feedbackplugins,
 391                                  $coursemoduleid,
 392                                  $returnaction,
 393                                  $returnparams,
 394                                  $cangrade,
 395                                  $useridlistid,
 396                                  $rownum) {
 397          $this->submissions = $submissions;
 398          $this->grades = $grades;
 399          $this->submissionplugins = $submissionplugins;
 400          $this->feedbackplugins = $feedbackplugins;
 401          $this->coursemoduleid = $coursemoduleid;
 402          $this->returnaction = $returnaction;
 403          $this->returnparams = $returnparams;
 404          $this->cangrade = $cangrade;
 405          $this->useridlistid = $useridlistid;
 406          $this->rownum = $rownum;
 407      }
 408  }
 409  
 410  /**
 411   * Used to output the attempt history chooser for a particular assignment.
 412   *
 413   * @package mod_assign
 414   * @copyright 2016 Damyon Wiese
 415   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 416   */
 417  class assign_attempt_history_chooser implements renderable, templatable {
 418  
 419      /** @var array submissions - The list of previous attempts */
 420      public $submissions = array();
 421      /** @var array grades - The grades for the previous attempts */
 422      public $grades = array();
 423      /** @var int coursemoduleid - The cmid for the assignment */
 424      public $coursemoduleid = 0;
 425      /** @var int userid - The current userid */
 426      public $userid = 0;
 427  
 428      /**
 429       * Constructor
 430       *
 431       * @param array $submissions
 432       * @param array $grades
 433       * @param int $coursemoduleid
 434       * @param int $userid
 435       */
 436      public function __construct($submissions,
 437                                  $grades,
 438                                  $coursemoduleid,
 439                                  $userid) {
 440          $this->submissions = $submissions;
 441          $this->grades = $grades;
 442          $this->coursemoduleid = $coursemoduleid;
 443          $this->userid = $userid;
 444      }
 445  
 446      /**
 447       * Function to export the renderer data in a format that is suitable for a
 448       * mustache template.
 449       *
 450       * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
 451       * @return stdClass|array
 452       */
 453      public function export_for_template(renderer_base $output) {
 454          // Show newest to oldest.
 455          $export = (object) $this;
 456          $export->submissions = array_reverse($export->submissions);
 457          $export->submissioncount = count($export->submissions);
 458  
 459          foreach ($export->submissions as $i => $submission) {
 460              $grade = null;
 461              foreach ($export->grades as $onegrade) {
 462                  if ($onegrade->attemptnumber == $submission->attemptnumber) {
 463                      $submission->grade = $onegrade;
 464                      break;
 465                  }
 466              }
 467              if (!$submission) {
 468                  $submission = new stdClass();
 469              }
 470  
 471              $editbtn = '';
 472  
 473              if ($submission->timemodified) {
 474                  $submissionsummary = userdate($submission->timemodified);
 475              } else {
 476                  $submissionsummary = get_string('nosubmission', 'assign');
 477              }
 478  
 479              $attemptsummaryparams = array('attemptnumber' => $submission->attemptnumber + 1,
 480                                            'submissionsummary' => $submissionsummary);
 481              $submission->attemptsummary = get_string('attemptheading', 'assign', $attemptsummaryparams);
 482              $submission->statussummary = get_string('submissionstatus_' . $submission->status, 'assign');
 483  
 484          }
 485  
 486          return $export;
 487      }
 488  }
 489  
 490  /**
 491   * Renderable header related to an individual subplugin
 492   * @package   mod_assign
 493   * @copyright 2014 Henning Bostelmann
 494   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 495   */
 496  class assign_plugin_header implements renderable {
 497      /** @var assign_plugin $plugin */
 498      public $plugin = null;
 499  
 500      /**
 501       * Header for a single plugin
 502       *
 503       * @param assign_plugin $plugin
 504       */
 505      public function __construct(assign_plugin $plugin) {
 506          $this->plugin = $plugin;
 507      }
 508  }
 509  
 510  /**
 511   * Renderable grading summary
 512   * @package   mod_assign
 513   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 514   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 515   */
 516  class assign_grading_summary implements renderable {
 517      /** @var int participantcount - The number of users who can submit to this assignment */
 518      public $participantcount = 0;
 519      /** @var bool submissiondraftsenabled - Allow submission drafts */
 520      public $submissiondraftsenabled = false;
 521      /** @var int submissiondraftscount - The number of submissions in draft status */
 522      public $submissiondraftscount = 0;
 523      /** @var bool submissionsenabled - Allow submissions */
 524      public $submissionsenabled = false;
 525      /** @var int submissionssubmittedcount - The number of submissions in submitted status */
 526      public $submissionssubmittedcount = 0;
 527      /** @var int submissionsneedgradingcount - The number of submissions that need grading */
 528      public $submissionsneedgradingcount = 0;
 529      /** @var int duedate - The assignment due date (if one is set) */
 530      public $duedate = 0;
 531      /** @var int cutoffdate - The assignment cut off date (if one is set) */
 532      public $cutoffdate = 0;
 533      /** @var int timelimit - The assignment time limit (if one is set) */
 534      public $timelimit = 0;
 535      /** @var int coursemoduleid - The assignment course module id */
 536      public $coursemoduleid = 0;
 537      /** @var boolean teamsubmission - Are team submissions enabled for this assignment */
 538      public $teamsubmission = false;
 539      /** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
 540      public $warnofungroupedusers = false;
 541      /** @var boolean relativedatesmode - Is the course a relative dates mode course or not */
 542      public $courserelativedatesmode = false;
 543      /** @var int coursestartdate - start date of the course as a unix timestamp*/
 544      public $coursestartdate;
 545      /** @var boolean cangrade - Can the current user grade students? */
 546      public $cangrade = false;
 547      /** @var boolean isvisible - Is the assignment's context module visible to students? */
 548      public $isvisible = true;
 549      /** @var cm_info $cm - The course module object. */
 550      public $cm = null;
 551  
 552      /** @var string no warning needed about group submissions */
 553      const WARN_GROUPS_NO = false;
 554      /** @var string warn about group submissions, as groups are required */
 555      const WARN_GROUPS_REQUIRED = 'warnrequired';
 556      /** @var string warn about group submissions, as some will submit as 'Default group' */
 557      const WARN_GROUPS_OPTIONAL = 'warnoptional';
 558  
 559      /**
 560       * constructor
 561       *
 562       * @param int $participantcount
 563       * @param bool $submissiondraftsenabled
 564       * @param int $submissiondraftscount
 565       * @param bool $submissionsenabled
 566       * @param int $submissionssubmittedcount
 567       * @param int $cutoffdate
 568       * @param int $duedate
 569       * @param int $timelimit
 570       * @param int $coursemoduleid
 571       * @param int $submissionsneedgradingcount
 572       * @param bool $teamsubmission
 573       * @param string $warnofungroupedusers
 574       * @param bool $courserelativedatesmode true if the course is using relative dates, false otherwise.
 575       * @param int $coursestartdate unix timestamp representation of the course start date.
 576       * @param bool $cangrade
 577       * @param bool $isvisible
 578       * @param cm_info|null $cm The course module object.
 579       */
 580      public function __construct($participantcount,
 581                                  $submissiondraftsenabled,
 582                                  $submissiondraftscount,
 583                                  $submissionsenabled,
 584                                  $submissionssubmittedcount,
 585                                  $cutoffdate,
 586                                  $duedate,
 587                                  $timelimit,
 588                                  $coursemoduleid,
 589                                  $submissionsneedgradingcount,
 590                                  $teamsubmission,
 591                                  $warnofungroupedusers,
 592                                  $courserelativedatesmode,
 593                                  $coursestartdate,
 594                                  $cangrade = true,
 595                                  $isvisible = true,
 596                                  cm_info $cm = null) {
 597          $this->participantcount = $participantcount;
 598          $this->submissiondraftsenabled = $submissiondraftsenabled;
 599          $this->submissiondraftscount = $submissiondraftscount;
 600          $this->submissionsenabled = $submissionsenabled;
 601          $this->submissionssubmittedcount = $submissionssubmittedcount;
 602          $this->duedate = $duedate;
 603          $this->cutoffdate = $cutoffdate;
 604          $this->timelimit = $timelimit;
 605          $this->coursemoduleid = $coursemoduleid;
 606          $this->submissionsneedgradingcount = $submissionsneedgradingcount;
 607          $this->teamsubmission = $teamsubmission;
 608          $this->warnofungroupedusers = $warnofungroupedusers;
 609          $this->courserelativedatesmode = $courserelativedatesmode;
 610          $this->coursestartdate = $coursestartdate;
 611          $this->cangrade = $cangrade;
 612          $this->isvisible = $isvisible;
 613          $this->cm = $cm;
 614      }
 615  }
 616  
 617  /**
 618   * Renderable course index summary
 619   * @package   mod_assign
 620   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 621   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 622   */
 623  class assign_course_index_summary implements renderable {
 624      /** @var array assignments - A list of course module info and submission counts or statuses */
 625      public $assignments = array();
 626      /** @var boolean usesections - Does this course format support sections? */
 627      public $usesections = false;
 628      /** @var string courseformat - The current course format name */
 629      public $courseformatname = '';
 630  
 631      /**
 632       * constructor
 633       *
 634       * @param boolean $usesections - True if this course format uses sections
 635       * @param string $courseformatname - The id of this course format
 636       */
 637      public function __construct($usesections, $courseformatname) {
 638          $this->usesections = $usesections;
 639          $this->courseformatname = $courseformatname;
 640      }
 641  
 642      /**
 643       * Add a row of data to display on the course index page
 644       *
 645       * @param int $cmid - The course module id for generating a link
 646       * @param string $cmname - The course module name for generating a link
 647       * @param string $sectionname - The name of the course section (only if $usesections is true)
 648       * @param int $timedue - The due date for the assignment - may be 0 if no duedate
 649       * @param string $submissioninfo - A string with either the number of submitted assignments, or the
 650       *                                 status of the current users submission depending on capabilities.
 651       * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
 652       * @param bool cangrade - Does this user have grade capability?
 653       */
 654      public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo, $cangrade = false) {
 655          $this->assignments[] = ['cmid' => $cmid,
 656                                 'cmname' => $cmname,
 657                                 'sectionname' => $sectionname,
 658                                 'timedue' => $timedue,
 659                                 'submissioninfo' => $submissioninfo,
 660                                 'gradeinfo' => $gradeinfo,
 661                                 'cangrade' => $cangrade];
 662      }
 663  
 664  
 665  }
 666  
 667  
 668  /**
 669   * An assign file class that extends rendererable class and is used by the assign module.
 670   *
 671   * @package   mod_assign
 672   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 673   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 674   */
 675  class assign_files implements renderable {
 676      /** @var context $context */
 677      public $context;
 678      /** @var string $context */
 679      public $dir;
 680      /** @var MoodleQuickForm $portfolioform */
 681      public $portfolioform;
 682      /** @var stdClass $cm course module */
 683      public $cm;
 684      /** @var stdClass $course */
 685      public $course;
 686  
 687      /**
 688       * The constructor
 689       *
 690       * @param context $context
 691       * @param int $sid
 692       * @param string $filearea
 693       * @param string $component
 694       * @param stdClass $course
 695       * @param stdClass $cm
 696       */
 697      public function __construct(context $context, $sid, $filearea, $component, $course = null, $cm = null) {
 698          global $CFG;
 699          if (empty($course) || empty($cm)) {
 700              list($context, $course, $cm) = get_context_info_array($context->id);
 701          }
 702  
 703          $this->context = $context;
 704          $this->cm = $cm;
 705          $this->course = $course;
 706          $fs = get_file_storage();
 707          $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid);
 708  
 709          $files = $fs->get_area_files($this->context->id,
 710                                       $component,
 711                                       $filearea,
 712                                       $sid,
 713                                       'timemodified',
 714                                       false);
 715  
 716          if (!empty($CFG->enableportfolios)) {
 717              require_once($CFG->libdir . '/portfoliolib.php');
 718              if (count($files) >= 1 && !empty($sid) &&
 719                      has_capability('mod/assign:exportownsubmission', $this->context)) {
 720                  $button = new portfolio_add_button();
 721                  $callbackparams = array('cmid' => $this->cm->id,
 722                                          'sid' => $sid,
 723                                          'area' => $filearea,
 724                                          'component' => $component);
 725                  $button->set_callback_options('assign_portfolio_caller',
 726                                                $callbackparams,
 727                                                'mod_assign');
 728                  $button->reset_formats();
 729                  $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
 730              }
 731  
 732          }
 733  
 734          $this->preprocess($this->dir, $filearea, $component);
 735      }
 736  
 737      /**
 738       * Preprocessing the file list to add the portfolio links if required.
 739       *
 740       * @param array $dir
 741       * @param string $filearea
 742       * @param string $component
 743       * @return void
 744       */
 745      public function preprocess($dir, $filearea, $component) {
 746          global $CFG;
 747  
 748          foreach ($dir['subdirs'] as $subdir) {
 749              $this->preprocess($subdir, $filearea, $component);
 750          }
 751          foreach ($dir['files'] as $file) {
 752              $file->portfoliobutton = '';
 753  
 754              $file->timemodified = userdate(
 755                  $file->get_timemodified(),
 756                  get_string('strftimedatetime', 'langconfig')
 757              );
 758  
 759              if (!empty($CFG->enableportfolios)) {
 760                  require_once($CFG->libdir . '/portfoliolib.php');
 761                  $button = new portfolio_add_button();
 762                  if (has_capability('mod/assign:exportownsubmission', $this->context)) {
 763                      $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id());
 764                      $button->set_callback_options('assign_portfolio_caller',
 765                                                    $portfolioparams,
 766                                                    'mod_assign');
 767                      $button->set_format_by_file($file);
 768                      $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
 769                  }
 770              }
 771              $path = '/' .
 772                      $this->context->id .
 773                      '/' .
 774                      $component .
 775                      '/' .
 776                      $filearea .
 777                      '/' .
 778                      $file->get_itemid() .
 779                      $file->get_filepath() .
 780                      $file->get_filename();
 781              $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true);
 782              $filename = $file->get_filename();
 783              $file->fileurl = html_writer::link($url, $filename, [
 784                      'target' => '_blank',
 785                  ]);
 786          }
 787      }
 788  }