Completed
Push — master ( 189151...5aefc8 )
by Roberto
18:39 queued 17:09
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * Edit Relationship page
19
 *
20
 * @package local_relationship
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
24
require_once(__DIR__.'/../../config.php');
25
require_once($CFG->libdir.'/filelib.php');
26
require($CFG->dirroot.'/local/relationship/lib.php');
27
require_once($CFG->dirroot.'/local/relationship/locallib.php');
28
29
require_login();
30
31
$relationshipid = optional_param('relationshipid', 0, PARAM_INT);
32
if ($relationshipid) {
33
    $relationship = relationship_get_relationship($relationshipid);
34
    $context = context::instance_by_id($relationship->contextid, MUST_EXIST);
35
} else {
36
    $contextid = optional_param('contextid', 0, PARAM_INT);
37
    $context = context::instance_by_id($contextid, MUST_EXIST);
38
    $relationship = new stdClass();
39
    $relationship->id = 0;
40
    $relationship->contextid = $context->id;
41
    $relationship->name = '';
42
    $relationship->description = '';
43
    $relationship->tags = array();
44
}
45
46
require_capability('local/relationship:manage', $context);
47
if (!empty($relationship->component)) {
48
    print_error('cantedit', 'local_relationship');
49
}
50
51
$baseurl = new moodle_url('/local/relationship/edit.php', array('relationshipid' => $relationship->id, 'contextid' => $context->id));
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
52
$returnurl = new moodle_url('/local/relationship/index.php', array('contextid' => $context->id));
53
54
if (optional_param('confirmdelete', 0, PARAM_BOOL) && confirm_sesskey() && $relationship->id) {
55
    $res = relationship_delete_relationship($relationship);
56
    if($res == -1) {
57
        print_error('has_cohorts', 'local_relationship');
58
    }
59
    redirect($returnurl);
60
}
61
62
if (optional_param('delete', 0, PARAM_BOOL) && $relationship->id) {
63
    relationship_set_header($context, $baseurl, $relationship);
64
    relationship_set_title($relationship, 'deleterelationship');
65
    $yesurl = new moodle_url('/local/relationship/edit.php', array('relationshipid' => $relationship->id, 'confirmdelete' => 1, 'sesskey' => sesskey()));
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 153 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
66
    $message = get_string('confirmdelete', 'local_relationship', format_string($relationship->name));
67
    echo $OUTPUT->confirm($message, $yesurl, $returnurl);
68
    echo $OUTPUT->footer();
69
    die;
70
}
71
72
relationship_set_header($context, $baseurl, $relationship);
73
74
$editoroptions = array('maxfiles' => 0, 'context' => $context);
75
76
$relationship_editor = file_prepare_standard_editor($relationship, 'description', $editoroptions, $context);
77
$editform = new \local_relationship\form\edit_relationship(null, array('editoroptions' => $editoroptions, 'data' => $relationship_editor));
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
78
79
if ($editform->is_cancelled()) {
80
    redirect($returnurl);
81
} else if ($data = $editform->get_data()) {
82
    $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context);
83
    if ($data->id) {
84
        relationship_update_relationship($data);
85
    } else {
86
        relationship_add_relationship($data);
87
    }
88
    redirect($returnurl);
89
}
90
91
$action = $relationship_editor->id ? 'editrelationship' : 'addrelationship';
92
relationship_set_title($relationship_editor, $action);
93
echo $editform->display();
94
echo $OUTPUT->footer();
95