/mod/assign/renderable.php

https://bitbucket.org/kudutest1/moodlegit · PHP · 803 lines · 396 code · 50 blank · 357 comment · 6 complexity · 4922954fa95b1347615e5aaaefd69e11 MD5 · raw file

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