Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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