1 |
efrain |
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 |
/**
|
|
|
18 |
* this file contains the cohort selection form to exclude cohorts
|
|
|
19 |
*
|
|
|
20 |
* File cohort.php
|
|
|
21 |
* Encoding UTF-8
|
|
|
22 |
* @copyright Sebsoft.nl
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace tool_usersuspension\forms\exclude;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die;
|
|
|
29 |
|
|
|
30 |
require_once($CFG->libdir . '/formslib.php');
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* tool_usersuspension\forms\cohort
|
|
|
34 |
*
|
|
|
35 |
* @package tool_usersuspension
|
|
|
36 |
*
|
|
|
37 |
* @copyright Sebsoft.nl
|
|
|
38 |
* @author R.J. van Dongen <rogier@sebsoft.nl>
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
|
|
41 |
class cohort extends \moodleform {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* form definition
|
|
|
45 |
*/
|
|
|
46 |
public function definition() {
|
|
|
47 |
global $DB;
|
|
|
48 |
$mform = $this->_form;
|
|
|
49 |
|
|
|
50 |
$pfx = \tool_usersuspension\util::get_prefix();
|
|
|
51 |
$excludedcohorts = $DB->get_fieldset_select('tool_usersuspension_excl', 'refid',
|
|
|
52 |
"type = :{$pfx}type", array("{$pfx}type" => 'cohort'));
|
|
|
53 |
list($sqlin, $params) = $DB->get_in_or_equal($excludedcohorts, SQL_PARAMS_QM, 'param', false, true);
|
|
|
54 |
$cohorts = $DB->get_records_sql_menu('SELECT id,name FROM {cohort} WHERE id '. $sqlin, $params);
|
|
|
55 |
if (count($cohorts) == 0) {
|
|
|
56 |
$mform->addElement('static', 'xstat1', '', get_string('info:no-exclusion-cohorts', 'tool_usersuspension'));
|
|
|
57 |
} else {
|
|
|
58 |
$size = min(10, max(0, count($cohorts)));
|
|
|
59 |
$select1 = $mform->addElement('select', 'cohort', get_string('cohort', 'cohort'), $cohorts, array('size' => $size));
|
|
|
60 |
$select1->setMultiple(true);
|
|
|
61 |
$mform->addRule('cohort', get_string('required'), 'required', null, 'client');
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
$this->add_action_buttons(true, get_string('button:continue', 'tool_usersuspension'));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Process the posted form
|
|
|
69 |
*
|
|
|
70 |
* @throws \moodle_exception
|
|
|
71 |
*/
|
|
|
72 |
public function process() {
|
|
|
73 |
global $DB;
|
|
|
74 |
$data = $this->get_data();
|
|
|
75 |
if ($data === null) {
|
|
|
76 |
return false;
|
|
|
77 |
\tool_usersuspension\util::print_notification(get_string('msg:exclusion:cohort:none-selected',
|
|
|
78 |
'tool_usersuspension'), 'success');
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
if (!empty($data->cohort)) {
|
|
|
82 |
foreach ($data->cohort as $cohortid) {
|
|
|
83 |
$cohort = $DB->get_record('cohort', array('id' => $cohortid));
|
|
|
84 |
$record = (object) array('type' => 'cohort',
|
|
|
85 |
'refid' => $cohortid, 'timecreated' => time());
|
|
|
86 |
$DB->insert_record('tool_usersuspension_excl', $record);
|
|
|
87 |
\tool_usersuspension\util::print_notification(get_string('msg:exclusion:record:cohort:inserted',
|
|
|
88 |
'tool_usersuspension', $cohort), 'success');
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
}
|