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

classes/form/autogroup.php (4 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 Autogroup form definition
19
 *
20
 * @package local_relationship
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
24
namespace local_relationship\form;
25
defined('MOODLE_INTERNAL') || die();
26
27
require_once($CFG->dirroot.'/lib/formslib.php');
28
29
/**
30
 * Auto group form class
31
 *
32
 * @package enrol_relationship
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class autogroup extends \moodleform {
36
37
    /**
38
     * Form Definition
39
     */
40
    function definition() {
41
        global $DB;
42
43
        $mform =& $this->_form;
44
45
        $relationshipid = $this->_customdata['relationshipid'];
46
47
        $mform->addElement('text', 'namingscheme', get_string('namingscheme', 'local_relationship'));
48
        $mform->addHelpButton('namingscheme', 'namingscheme', 'local_relationship');
49
        $mform->addRule('namingscheme', get_string('required'), 'required', null, 'client');
50
        $mform->setType('namingscheme', PARAM_TEXT);
51
        $mform->setDefault('namingscheme', get_string('grouptemplate', 'group'));
52
53
        $mform->addElement('text', 'userlimit', get_string('userlimit', 'local_relationship'), 'maxlength="5" size="4"');
54
        $mform->setType('userlimit', PARAM_INT);
55
        $mform->addRule('userlimit', null, 'numeric', null, 'client');
56
        $mform->setDefault('userlimit', 0);
57
        $mform->addHelpButton('userlimit', 'userlimit', 'local_relationship');
58
59
        $mform->addElement('text', 'number', get_string('numbergroups', 'local_relationship'), 'maxlength="4" size="4"');
60
        $mform->setType('number', PARAM_INT);
61
        $mform->addRule('number', null, 'numeric', null, 'client');
62
        $mform->setDefault('number', 0);
63
        $mform->disabledIf('number', 'relationshipcohortid', 'gt', 0);
64
65
        $sql = "SELECT rc.id, rc.cohortid, rc.roleid, ch.name
66
                  FROM {relationship_cohorts} rc
67
                  JOIN {cohort} ch ON (ch.id = rc.cohortid)
68
                 WHERE rc.relationshipid = :relationshipid
69
              ORDER BY ch.name";
70
        $rcs = $DB->get_records_sql($sql, array('relationshipid' => $relationshipid));
71
        if ($rcs) {
72
            $options = array(0 => get_string('none'));
73
            $r = get_string('role');
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...
74
            foreach ($rcs AS $rc) {
75
                $role = $DB->get_record('role', array('id' => $rc->roleid));
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...
76
                $role_name = role_get_name($role);
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...
77
                $options[$rc->id] = "{$rc->name}  ({$r}: {$role_name})";
78
            }
79
            $mform->addElement('select', 'relationshipcohortid', get_string('fromcohort', 'local_relationship'), $options);
80
            $mform->setDefault('relationshipcohortid', '0');
81
            $mform->addHelpButton('relationshipcohortid', 'fromcohort', 'local_relationship');
82
            $mform->disabledIf('relationshipcohortid', 'number', 'gt', 0);
83
        } else {
84
            $mform->addElement('hidden', 'relationshipcohortid');
85
            $mform->setType('relationshipcohortid', PARAM_INT);
86
            $mform->setConstant('relationshipcohortid', '0');
87
        }
88
89
        $mform->addElement('hidden', 'relationshipid');
90
        $mform->setType('relationshipid', PARAM_INT);
91
92
        $buttonarray = 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...
93
        $buttonarray[] = & $mform->createElement('submit', 'preview', get_string('preview', 'local_relationship'));
94
        $buttonarray[] = & $mform->createElement('submit', 'submitbutton', get_string('creategroups', 'local_relationship'));
95
        $buttonarray[] = & $mform->createElement('cancel');
96
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
97
        $mform->closeHeaderBefore('buttonar');
98
    }
99
100
    /**
101
     * Performs validation of the form information
102
     *
103
     * @param array $data
104
     * @param array $files
105
     * @return array $errors An array of $errors
106
     */
107
    function validation($data, $files) {
108
        $errors = parent::validation($data, $files);
109
110
        return $errors;
111
    }
112
}
113