|
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
|
|
|
* deletes a featured course |
|
19
|
|
|
* |
|
20
|
|
|
* @package block_featuredcourses |
|
21
|
|
|
* @author Daniel Neis |
|
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
require_once("../../config.php"); |
|
26
|
|
|
require_once($CFG->dirroot.'/blocks/featuredcourses/delete_featuredcourse_form.php'); |
|
27
|
|
|
|
|
28
|
|
|
$courseid = required_param('courseid', PARAM_INT); |
|
29
|
|
|
|
|
30
|
|
|
$PAGE->set_url('/blocks/featuredcourses/delete_featuredcourse.php', array('courseid' => $courseid)); |
|
31
|
|
|
$context = context_system::instance(); |
|
32
|
|
|
$PAGE->set_context($context); |
|
33
|
|
|
|
|
34
|
|
|
require_login(); |
|
35
|
|
|
|
|
36
|
|
|
require_capability('block/featuredcourses:addinstance', $context); |
|
37
|
|
|
|
|
38
|
|
|
$mform = new block_featuredcourses_delete_featuredcourse_form(); |
|
39
|
|
|
$newformdata = array('courseid' => $courseid, 'confirmdelete' => '1'); |
|
40
|
|
|
$mform->set_data($newformdata); |
|
41
|
|
|
$formdata = $mform->get_data(); |
|
42
|
|
|
|
|
43
|
|
|
if ($mform->is_cancelled()) { |
|
44
|
|
|
redirect($CFG->wwwroot.'/blocks/featuredcourses/featuredcourses.php'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) { |
|
|
|
|
|
|
48
|
|
|
require_once($CFG->dirroot.'/blocks/moodleblock.class.php'); |
|
49
|
|
|
require_once($CFG->dirroot.'/blocks/featuredcourses/block_featuredcourses.php'); |
|
50
|
|
|
block_featuredcourses::delete_featuredcourse($formdata->courseid); |
|
51
|
|
|
redirect($CFG->wwwroot.'/blocks/featuredcourses/featuredcourses.php'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$title = get_string('delete_featuredcourse', 'block_featuredcourses'); |
|
55
|
|
|
|
|
56
|
|
|
$PAGE->navbar->add($title); |
|
57
|
|
|
$PAGE->set_heading($title); |
|
58
|
|
|
$PAGE->set_title($title); |
|
59
|
|
|
|
|
60
|
|
|
echo $OUTPUT->header(), |
|
61
|
|
|
|
|
62
|
|
|
$OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal'), |
|
63
|
|
|
html_writer::tag('p', get_string('confirmdelete', 'block_featuredcourses'), array('class' => 'bold')); |
|
64
|
|
|
|
|
65
|
|
|
$mform->display(); |
|
66
|
|
|
|
|
67
|
|
|
echo $OUTPUT->box_end(), |
|
68
|
|
|
$OUTPUT->footer(); |
|
69
|
|
|
|
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.