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 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 | class edit_relationship extends \moodleform { |
||
| 30 | |||
| 31 | public function definition() { |
||
| 32 | |||
| 33 | $mform = $this->_form; |
||
|
0 ignored issues
–
show
|
|||
| 34 | $editoroptions = $this->_customdata['editoroptions']; |
||
| 35 | $relationship = $this->_customdata['data']; |
||
|
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 | |||
| 37 | $mform->addElement('text', 'name', get_string('name', 'local_relationship'), 'maxlength="254" size="50"'); |
||
| 38 | $mform->addRule('name', get_string('required'), 'required', null, 'client'); |
||
| 39 | $mform->setType('name', PARAM_TEXT); |
||
| 40 | |||
| 41 | $mform->addElement('editor', 'description_editor', get_string('description', 'local_relationship'), null, $editoroptions); |
||
| 42 | $mform->setType('description_editor', PARAM_RAW); |
||
| 43 | |||
| 44 | $mform->addElement('tags', 'tags', get_string('tags'), array('display' => 'noofficial')); |
||
| 45 | $mform->setType('tags', PARAM_TEXT); |
||
| 46 | |||
| 47 | $mform->addElement('hidden', 'id'); |
||
| 48 | $mform->setType('id', PARAM_INT); |
||
| 49 | $mform->addElement('hidden', 'contextid'); |
||
| 50 | $mform->setType('contextid', PARAM_INT); |
||
| 51 | |||
| 52 | $this->add_action_buttons(); |
||
| 53 | |||
| 54 | $this->set_data($relationship); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function validation($data, $files) { |
||
| 58 | global $DB; |
||
| 59 | |||
| 60 | $errors = parent::validation($data, $files); |
||
| 61 | |||
| 62 | $name = trim($data['name']); |
||
| 63 | if (empty($name)) { |
||
| 64 | $errors['name'] = get_string('no_name', 'local_relationship'); |
||
| 65 | } else { |
||
| 66 | $params = array('name' => addslashes($name), 'contextid' => $data['contextid']); |
||
| 67 | if ($data['id']) { |
||
| 68 | $where = "id != :id AND"; |
||
|
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...
|
|||
| 69 | $params['id'] = $data['id']; |
||
| 70 | } else { |
||
| 71 | $where = ''; |
||
| 72 | } |
||
| 73 | $sql = "SELECT id FROM {relationship} WHERE {$where} name = :name AND contextid = :contextid"; |
||
| 74 | if ($DB->record_exists_sql($sql, $params)) { |
||
| 75 | $errors['name'] = get_string('relationship_already_exists', 'local_relationship'); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | return $errors; |
||
| 80 | } |
||
| 81 | |||
| 82 | } |
||
| 83 |
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
will produce issues in the first and second line, while this second example
will produce no issues.