Passed
Push — master ( 4ffe03...5d5113 )
by Roberto
02:32
created

edit_cohort.php (11 issues)

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's Cohort page
19
 * @package local_relationship
20
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
22
23
require_once(__DIR__.'/../../config.php');
24
require($CFG->dirroot.'/local/relationship/lib.php');
25
require_once($CFG->dirroot.'/local/relationship/locallib.php');
26
27
require_login();
28
29
if ($relationshipcohortid = optional_param('relationshipcohortid', 0, PARAM_INT)) {
30
    $relationshipcohort = relationship_get_cohort($relationshipcohortid);
31
    $relationship = $DB->get_record('relationship', array('id' => $relationshipcohort->relationshipid), '*', MUST_EXIST);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
32
} else {
33
    $relationshipid = required_param('relationshipid', PARAM_INT);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 26 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
    $relationship = $DB->get_record('relationship', array('id' => $relationshipid), '*', MUST_EXIST);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 28 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
    $relationshipcohort = new stdClass();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 22 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
    $relationshipcohort->id = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 18 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
37
    $relationshipcohort->relationshipid = $relationshipid;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
    $relationshipcohort->roleid = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
39
    $relationshipcohort->cohortid = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40
    $relationshipcohort->allowdupsingroups = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41
    $relationshipcohort->uniformdistribution = 0;
42
}
43
44
$context = context::instance_by_id($relationship->contextid, MUST_EXIST);
45
require_capability('local/relationship:manage', $context);
46
if (!empty($relationship->component)) {
47
    print_error('cantedit', 'local_relationship');
48
}
49
50
$baseurl = new moodle_url('/local/relationship/edit_cohort.php', array('relationshipid' => $relationship->id, 'relationshipcohortid' => $relationshipcohort->id));
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51
$returnurl = new moodle_url('/local/relationship/cohorts.php', array('relationshipid' => $relationship->id));
52
53
if (optional_param('confirmedelete', 0, PARAM_BOOL) && confirm_sesskey() && $relationshipcohort->id) {
54
    relationship_delete_cohort($relationshipcohort);
55
    redirect($returnurl);
56
}
57
58
relationship_set_header($context, $baseurl, $relationship, 'cohorts');
59
60
if (optional_param('delete', 0, PARAM_BOOL) && $relationshipcohort->id) {
61
    $desc = format_string($relationshipcohort->role_name.'/'.$relationshipcohort->cohort->name);
62
    relationship_set_title($relationship, 'deletecohort', $desc);
63
    echo $OUTPUT->notification(get_string('deletecohortwarning', 'local_relationship'));
64
    $yesurl = new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $relationshipcohort->id, 'relationshipid' => $relationship->id, 'delete' => 1, 'confirmedelete' => 1, 'sesskey' => sesskey()));
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
65
    $message = get_string('confirmdeleletecohort', 'local_relationship', $desc);
66
    echo $OUTPUT->confirm($message, $yesurl, $returnurl);
67
    echo $OUTPUT->footer();
68
    exit;
69
}
70
71
$editform = new \local_relationship\form\edit_cohort(null, array('data' => $relationshipcohort));
72
73
if ($editform->is_cancelled()) {
74
    redirect($returnurl);
75
} else if ($data = $editform->get_data()) {
76
    if ($data->id) {
77
        relationship_update_cohort($data);
78
    } else {
79
        $id = relationship_add_cohort($data);
80
    }
81
    redirect($returnurl);
82
}
83
84
if ($relationshipcohort->id) {
85
    $desc = format_string($relationshipcohort->role_name.'/'.$relationshipcohort->cohort->name);
86
    relationship_set_title($relationship, 'editcohort', $desc);
87
} else {
88
    relationship_set_title($relationship, 'addcohort');
89
}
90
echo $editform->display();
91
echo $OUTPUT->footer();
92