forked from UFSC/moodle-local-relationship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_cohort.php
91 lines (79 loc) · 3.85 KB
/
edit_cohort.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Edit Relationship's Cohort page
* @package local_relationship
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
require($CFG->dirroot.'/local/relationship/lib.php');
require_once($CFG->dirroot.'/local/relationship/locallib.php');
require_login();
if ($relationshipcohortid = optional_param('relationshipcohortid', 0, PARAM_INT)) {
$relationshipcohort = relationship_get_cohort($relationshipcohortid);
$relationship = $DB->get_record('relationship', array('id' => $relationshipcohort->relationshipid), '*', MUST_EXIST);
} else {
$relationshipid = required_param('relationshipid', PARAM_INT);
$relationship = $DB->get_record('relationship', array('id' => $relationshipid), '*', MUST_EXIST);
$relationshipcohort = new stdClass();
$relationshipcohort->id = 0;
$relationshipcohort->relationshipid = $relationshipid;
$relationshipcohort->roleid = 0;
$relationshipcohort->cohortid = 0;
$relationshipcohort->allowdupsingroups = 0;
$relationshipcohort->uniformdistribution = 0;
}
$context = context::instance_by_id($relationship->contextid, MUST_EXIST);
require_capability('local/relationship:manage', $context);
if (!empty($relationship->component)) {
print_error('cantedit', 'local_relationship');
}
$baseurl = new moodle_url('/local/relationship/edit_cohort.php', array('relationshipid' => $relationship->id, 'relationshipcohortid' => $relationshipcohort->id));
$returnurl = new moodle_url('/local/relationship/cohorts.php', array('relationshipid' => $relationship->id));
if (optional_param('confirmedelete', 0, PARAM_BOOL) && confirm_sesskey() && $relationshipcohort->id) {
relationship_delete_cohort($relationshipcohort);
redirect($returnurl);
}
relationship_set_header($context, $baseurl, $relationship, 'cohorts');
if (optional_param('delete', 0, PARAM_BOOL) && $relationshipcohort->id) {
$desc = format_string($relationshipcohort->role_name.'/'.$relationshipcohort->cohort->name);
relationship_set_title($relationship, 'deletecohort', $desc);
echo $OUTPUT->notification(get_string('deletecohortwarning', 'local_relationship'));
$yesurl = new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $relationshipcohort->id, 'relationshipid' => $relationship->id, 'delete' => 1, 'confirmedelete' => 1, 'sesskey' => sesskey()));
$message = get_string('confirmdeleletecohort', 'local_relationship', $desc);
echo $OUTPUT->confirm($message, $yesurl, $returnurl);
echo $OUTPUT->footer();
exit;
}
$editform = new \local_relationship\form\edit_cohort(null, array('data' => $relationshipcohort));
if ($editform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $editform->get_data()) {
if ($data->id) {
relationship_update_cohort($data);
} else {
$id = relationship_add_cohort($data);
}
redirect($returnurl);
}
if ($relationshipcohort->id) {
$desc = format_string($relationshipcohort->role_name.'/'.$relationshipcohort->cohort->name);
relationship_set_title($relationship, 'editcohort', $desc);
} else {
relationship_set_title($relationship, 'addcohort');
}
echo $editform->display();
echo $OUTPUT->footer();