PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/alert_form.php

https://github.com/NigelCunningham/moodle-mod_forumng
PHP | 100 lines | 52 code | 22 blank | 26 comment | 8 complexity | d9d1a9c36be9125a189e3064cf0dac17 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. require_once($CFG->libdir.'/formslib.php');
  17. /**
  18. * Form for user to report inappropriate posts.
  19. * @package mod
  20. * @subpackage forumng
  21. * @copyright 2011 The Open University
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. class mod_forumng_alert_form extends moodleform {
  25. function definition() {
  26. global $CFG, $USER;
  27. $mform = $this->_form;
  28. // Add all the check boxes
  29. $mform->addElement('static', 'alert_intro', '',
  30. get_string('alert_info', 'forumng'));
  31. $checkboxarray = array();
  32. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition1',
  33. '', get_string('alert_condition1', 'forumng'));
  34. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition2',
  35. '', get_string('alert_condition2', 'forumng'));
  36. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition3',
  37. '', get_string('alert_condition3', 'forumng'));
  38. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition4',
  39. '', get_string('alert_condition4', 'forumng'));
  40. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition5',
  41. '', get_string('alert_condition5', 'forumng'));
  42. $checkboxarray[] =& $mform->createElement('checkbox', 'alert_condition6',
  43. '', get_string('alert_condition6', 'forumng'));
  44. $mform->addGroup($checkboxarray, get_string('alert_reasons', 'forumng'),
  45. get_string('alert_reasons', 'forumng'), '<br />', false);
  46. //plain text field
  47. $mform->addElement('textarea', 'alert_conditionmore',
  48. get_string('alert_conditionmore', 'forumng'), array('cols'=>50,
  49. 'rows'=> 15));
  50. $mform->setType('alert_conditionmore', PARAM_RAW);
  51. $mform->addElement('static', '', '',
  52. get_string('alert_reporterinfo', 'forumng'));
  53. $mform->addElement('static', '', '',
  54. get_string('alert_reporterdetail', 'forumng', $this->_customdata));
  55. //Add submit and cancel buttons
  56. $this->add_action_buttons(true, get_string('alert_submit', 'forumng'));
  57. //Add postid as hidden field
  58. $mform->addElement('hidden', 'p', $this->_customdata->postid);
  59. $mform->addElement('hidden', 'clone', $this->_customdata->cloneid);
  60. }
  61. function validation($data, $files) {
  62. $errors = parent::validation($data, $files);
  63. //Error if all fields are empty
  64. if (empty($data['alert_condition1']) && empty($data['alert_condition2']) &&
  65. empty($data['alert_condition3']) && empty($data['alert_condition4']) &&
  66. empty($data['alert_condition5']) && empty($data['alert_condition6']) &&
  67. empty($data['alert_conditionmore'])) {
  68. $errors['alert_intro'] = get_string('invalidalert', 'forumng');
  69. }
  70. if (empty($data['alert_condition1']) && empty($data['alert_condition2']) &&
  71. empty($data['alert_condition3']) && empty($data['alert_condition4']) &&
  72. empty($data['alert_condition5']) && empty($data['alert_condition6']) &&
  73. !empty($data['alert_conditionmore'])) {
  74. $errors['alert_intro'] = get_string('invalidalertcheckbox', 'forumng');
  75. }
  76. return $errors;
  77. }
  78. }