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

cohorts.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
 * Relationship's Cohorts listing 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($CFG->dirroot.'/local/relationship/lib.php');
26
require_once($CFG->dirroot.'/local/relationship/locallib.php');
27
28
require_login();
29
30
$relationshipid = required_param('relationshipid', PARAM_INT);
31
$relationship = $DB->get_record('relationship', array('id' => $relationshipid), '*', MUST_EXIST);
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...
32
$context = context::instance_by_id($relationship->contextid, MUST_EXIST);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 8 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...
33
34
require_capability('local/relationship:view', $context);
35
$manager = has_capability('local/relationship:manage', $context);
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...
36
$editable = $manager && empty($relationship->component);
37
38
$baseurl = new moodle_url('/local/relationship/cohorts.php', array('relationshipid' => $relationship->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...
39
$returnurl = new moodle_url('/local/relationship/index.php', array('contextid' => $context->id));
40
41
relationship_set_header($context, $baseurl, $relationship, 'cohorts');
42
relationship_set_title($relationship, 'cohorts');
43
44
$relationshipcohorts = relationship_get_cohorts($relationshipid);
45
$data = array();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 16 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...
46
foreach ($relationshipcohorts as $rch) {
47
    $line = array();
48
49
    $line[] = $rch->cohort ? $rch->cohort->name : '?';
50
    $line[] = $rch->cohort ? $DB->count_records('cohort_members', array('cohortid'=>$rch->cohort->id)) : '?';
51
    $line[] = $rch->role_name;
52
    $line[] = $rch->allowdupsingroups ? get_string('yes') : get_string('no');
53
    $line[] = $rch->uniformdistribution ? get_string('yes') : get_string('no');
54
55
    if ($editable) {
56
        $buttons = array();
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...
57
        $buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $rch->id, 'delete' => 1)),
58
                html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'title' => get_string('delete'), 'class' => 'iconsmall')));
59
        $buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $rch->id)),
60
                html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'title' => get_string('edit'), 'class' => 'iconsmall')));
61
        $line[] = implode(' ', $buttons);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 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...
62
    }
63
64
    $data[] = $line;
65
}
66
$table = new html_table();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 13 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...
67
$table->head = array(
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...
68
        get_string('cohort', 'cohort'),
69
        get_string('size'),
70
        get_string('role'),
71
        get_string('allowdupsingroups', 'local_relationship').$OUTPUT->help_icon('allowdupsingroups', 'local_relationship'),
72
        get_string('uniformdistribute', 'local_relationship').$OUTPUT->help_icon('uniformdistribute', 'local_relationship'),
73
        get_string('edit')
74
);
75
$table->colclasses = array(
76
        'leftalign',
77
        'leftalign',
78
        'leftalign',
79
        'centeralign',
80
        'leftalign',
81
        'leftalign'
82
);
83
84
$table->id = 'relationships';
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...
85
$table->attributes['class'] = 'admintable generaltable';
86
$table->data = $data;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 16 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...
87
88
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
89
echo html_writer::table($table);
90
91
if ($editable) {
92
    $cohorts = relationship_get_cohort_options($relationshipid);
93
    foreach ($relationshipcohorts AS $rc) {
94
        unset($cohorts[$rc->cohortid]);
95
    }
96
    if (empty($cohorts)) {
97
        echo $OUTPUT->heading(get_string('nocohorts', 'local_relationship'), 4);
98
    } else {
99
        $add = new single_button(new moodle_url('/local/relationship/edit_cohort.php',
100
                array('relationshipid' => $relationshipid)), get_string('add'));
101
        echo $OUTPUT->render($add);
102
    }
103
} else if ($manager) {
104
    echo $OUTPUT->heading(get_string('noeditable', 'local_relationship', 4));
105
}
106
echo $OUTPUT->box_end();
107
108
echo $OUTPUT->footer();
109