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
|
|
|
* The list of featured courses form. |
19
|
|
|
* |
20
|
|
|
* @package block_featuredcourses |
21
|
|
|
* @copyright Daniel Neis <[email protected]> |
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
defined('MOODLE_INTERNAL') || die; |
26
|
|
|
|
27
|
|
|
require_once($CFG->libdir.'/formslib.php'); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The form for handling featured courses. |
31
|
|
|
*/ |
32
|
|
|
class featuredcourses_form extends moodleform { |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Form definition. |
36
|
|
|
*/ |
37
|
|
|
public function definition() { |
38
|
|
|
global $CFG; |
|
|
|
|
39
|
|
|
|
40
|
|
|
$mform = $this->_form; |
41
|
|
|
$availablecourses = $this->_customdata['availablecourses']; |
42
|
|
|
$featuredcourses = $this->_customdata['featuredcourses']; |
43
|
|
|
$availablecourseslist = array(); |
44
|
|
|
foreach ($availablecourses as $c) { |
45
|
|
|
$availablecourseslist[$c->id] = $c->shortname . ' : ' . $c->fullname; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Forms to edit existing featured courses. |
49
|
|
|
foreach ($featuredcourses as $c) { |
50
|
|
|
$mform->addElement('header', 'featured', |
51
|
|
|
get_string('featuredcourse', 'block_featuredcourses', $c->shortname . ' - '. $c->fullname)); |
52
|
|
|
|
53
|
|
|
$mform->addElement('hidden', 'featured['.$c->id.'][id]', null); |
54
|
|
|
$mform->setType('featured['.$c->id.'][id]', PARAM_INT); |
55
|
|
|
$mform->setConstant('featured['.$c->id.'][id]', $c->id); |
56
|
|
|
|
57
|
|
|
$mform->addElement('text', 'featured['.$c->id.'][sortorder]', get_string('sortorder', 'block_featuredcourses')); |
58
|
|
|
$mform->addRule('featured['.$c->id.'][sortorder]', |
59
|
|
|
get_string('missingsortorder', 'block_featuredcourses'), 'required', null, 'client'); |
60
|
|
|
$mform->setType('featured['.$c->id.'][sortorder]', PARAM_INT); |
61
|
|
|
$mform->setDefault('featured['.$c->id.'][sortorder]', $c->sortorder); |
62
|
|
|
|
63
|
|
|
$mform->addElement('static', 'link', |
64
|
|
|
get_string('deletelink', 'block_featuredcourses', |
65
|
|
|
$CFG->wwwroot.'/blocks/featuredcourses/delete_featuredcourse.php?courseid='.$c->id)); |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// Add a new featured course. |
70
|
|
|
$mform->addElement('header', 'add', get_string('addfeaturedcourse', 'block_featuredcourses')); |
71
|
|
|
|
72
|
|
|
$mform->addElement('checkbox', 'doadd', get_string('doadd', 'block_featuredcourses')); |
73
|
|
|
|
74
|
|
|
$mform->addElement('select', 'newfeatured[courseid]', |
75
|
|
|
get_string('courseid', 'block_featuredcourses'), $availablecourseslist); |
76
|
|
|
$mform->addRule('newfeatured[courseid]', get_string('missingcourseid', 'block_featuredcourses'), |
77
|
|
|
'required', null, 'client'); |
78
|
|
|
$mform->disabledIf('newfeatured[courseid]', 'doadd', 'notchecked'); |
79
|
|
|
|
80
|
|
|
$mform->addElement('text', 'newfeatured[sortorder]', get_string('sortorder', 'block_featuredcourses')); |
81
|
|
|
$mform->addRule('newfeatured[sortorder]', get_string('missingsortorder', 'block_featuredcourses'), |
82
|
|
|
'required', null, 'client'); |
83
|
|
|
$mform->setType('newfeatured[sortorder]', PARAM_INT); |
84
|
|
|
$mform->disabledIf('newfeatured[sortorder]', 'doadd', 'notchecked'); |
85
|
|
|
|
86
|
|
|
$mform->addElement('submit', 'save', get_string('savechanges')); |
87
|
|
|
|
88
|
|
|
$mform->closeHeaderBefore('save'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.