PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/assign/renderable.php

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