PageRenderTime 58ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/assign/extensionform.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 106 lines | 57 code | 11 blank | 38 comment | 12 complexity | aec9f64f5d7a7d1451a3684aa1a7184a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-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 forms to create and edit an instance of this module
  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('Direct access to this script is forbidden.');
  24. require_once($CFG->libdir.'/formslib.php');
  25. require_once($CFG->dirroot . '/mod/assign/locallib.php');
  26. /**
  27. * Assignment extension dates form
  28. *
  29. * @package mod_assign
  30. * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class mod_assign_extension_form extends moodleform {
  34. /** @var array $instance - The data passed to this form */
  35. private $instance;
  36. /**
  37. * Define the form - called by parent constructor
  38. */
  39. public function definition() {
  40. $mform = $this->_form;
  41. list($coursemoduleid, $userid, $batchusers, $instance, $data) = $this->_customdata;
  42. // Instance variable is used by the form validation function.
  43. $this->instance = $instance;
  44. if ($batchusers) {
  45. $listusersmessage = get_string('grantextensionforusers', 'assign', count(explode(',', $batchusers)));
  46. $mform->addElement('static', 'applytoselectedusers', '', $listusersmessage);
  47. }
  48. if ($instance->allowsubmissionsfromdate) {
  49. $mform->addElement('static', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'),
  50. userdate($instance->allowsubmissionsfromdate));
  51. }
  52. if ($instance->duedate) {
  53. $mform->addElement('static', 'duedate', get_string('duedate', 'assign'), userdate($instance->duedate));
  54. $finaldate = $instance->duedate;
  55. }
  56. if ($instance->cutoffdate) {
  57. $mform->addElement('static', 'cutoffdate', get_string('cutoffdate', 'assign'), userdate($instance->cutoffdate));
  58. $finaldate = $instance->cutoffdate;
  59. }
  60. $mform->addElement('date_time_selector', 'extensionduedate',
  61. get_string('extensionduedate', 'assign'), array('optional'=>true));
  62. $mform->setDefault('extensionduedate', $finaldate);
  63. $mform->addElement('hidden', 'id', $coursemoduleid);
  64. $mform->setType('id', PARAM_INT);
  65. $mform->addElement('hidden', 'userid', $userid);
  66. $mform->setType('userid', PARAM_INT);
  67. $mform->addElement('hidden', 'selectedusers', $batchusers);
  68. $mform->setType('selectedusers', PARAM_SEQUENCE);
  69. $mform->addElement('hidden', 'action', 'saveextension');
  70. $mform->setType('action', PARAM_ALPHA);
  71. $this->add_action_buttons(true, get_string('savechanges', 'assign'));
  72. if ($data) {
  73. $this->set_data($data);
  74. }
  75. }
  76. /**
  77. * Perform validation on the extension form
  78. * @param array $data
  79. * @param array $files
  80. */
  81. public function validation($data, $files) {
  82. $errors = parent::validation($data, $files);
  83. if ($this->instance->duedate && $data['extensionduedate']) {
  84. if ($this->instance->duedate > $data['extensionduedate']) {
  85. $errors['extensionduedate'] = get_string('extensionnotafterduedate', 'assign');
  86. }
  87. }
  88. if ($this->instance->allowsubmissionsfromdate && $data['extensionduedate']) {
  89. if ($this->instance->allowsubmissionsfromdate > $data['extensionduedate']) {
  90. $errors['extensionduedate'] = get_string('extensionnotafterfromdate', 'assign');
  91. }
  92. }
  93. return $errors;
  94. }
  95. }