PageRenderTime 37ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/assign/renderable.php

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