mod_form.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * The main colab configuration form.
  18. *
  19. * @package colab
  20. * @copyright 2020 Your Name <you@example.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  25. /**
  26. * Module instance settings form.
  27. *
  28. * @package colab
  29. * @copyright 2020 Your Name <you@example.com>
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class mod_colab_mod_form extends moodleform_mod {
  33. /**
  34. * Defines forms elements
  35. */
  36. public function definition() {
  37. global $CFG;
  38. $mform = $this->_form;
  39. // Adding the "general" fieldset, where all the common settings are showed.
  40. $mform->addElement('header', 'general', get_string('general', 'form'));
  41. // Adding the standard "name" field.
  42. $mform->addElement('text', 'name', get_string('colabname', 'colab'), array('size' => '64'));
  43. if (!empty($CFG->formatstringstriptags)) {
  44. $mform->setType('name', PARAM_TEXT);
  45. } else {
  46. $mform->setType('name', PARAM_CLEANHTML);
  47. }
  48. $mform->addRule('name', null, 'required', null, 'client');
  49. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  50. $mform->addHelpButton('name', 'colabname', 'colab');
  51. // Adding the standard "intro" and "introformat" fields.
  52. if ($CFG->branch >= 29) {
  53. $this->standard_intro_elements();
  54. } else {
  55. $this->add_intro_editor();
  56. }
  57. // Adding the rest of colab settings, spreading all them into this fieldset
  58. // ... or adding more fieldsets ('header' elements) if needed for better logic.
  59. $mform->addElement('static', 'label1', 'colabsettings', get_string('colabsettings', 'colab'));
  60. $mform->addElement('header', 'colabfieldset', get_string('colabfieldset', 'colab'));
  61. // Add standard grading elements.
  62. $this->standard_grading_coursemodule_elements();
  63. // Add standard elements.
  64. $this->standard_coursemodule_elements();
  65. // Add standard buttons.
  66. $this->add_action_buttons();
  67. }
  68. function validation($data, $files) {
  69. global $COURSE, $DB, $CFG;
  70. echo 'entrada pós_criação';
  71. print_r($data);
  72. echo 'entrada files <br>';
  73. print_r($files);
  74. //encontra a ultma atividade
  75. $params = array('course' => $data->modulename);
  76. $records = $DB->get_record_sql('select max(id)+1 as ultima_ativ from {course}',$params);
  77. echo 'ultima atividade <br>';
  78. echo '1- <br>';
  79. echo $records -> ultima_ativ ;
  80. // deleta caso tenha algum registro anterior
  81. try {
  82. $DB->delete_records("colab_duplas", array('atividade'=>$records -> ultima_ativ));
  83. } catch (Exception $e) {
  84. echo 'Caught exception não foi possivel deletar duplas: ', $e->getMessage(), "\n";
  85. }
  86. //grava as duplas (teste fixo)
  87. try {
  88. $value-> id = 1;
  89. $value-> atividade = $records -> ultima_ativ ;
  90. $value-> par1 = 'user_test_1';
  91. $value-> par2 = 'user_test_2';
  92. $value-> obs = '';
  93. $DB->insert_record("colab_duplas", $value);
  94. } catch (Exception $e) {
  95. echo 'Caught exception não foi possivel gravar registo de dupla: ', $e->getMessage(), "\n";
  96. }
  97. // exit;
  98. return array();
  99. }
  100. }