forked from ned-code/moodle-block_sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse.php
59 lines (49 loc) · 1.62 KB
/
course.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Ned SideBar block page. Dummy blank page to display course context block
*/
// Include required files.
require_once(dirname(__FILE__) . '/../../config.php');
global $DB, $PAGE, $OUTPUT;
// Gather form data.
$courseid = required_param('courseid', PARAM_INT);
// Determine course and context.
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
// Set up page parameters.
$PAGE->set_course($course);
$PAGE->requires->css('/blocks/side_bar/styles.css');
$PAGE->set_url(
'/blocks/side_bar/course.php',
array(
'courseid' => $courseid,
)
);
$context = context_course::instance($course->id);
$PAGE->set_course($course);
$PAGE->set_context($context);
$title = $course->shortname . get_string('pagetitle', 'block_side_bar');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add($title);
$PAGE->set_pagelayout('standard');
// Check user is logged in and capable of grading.
require_login($course, false);
$blockmanager = $PAGE->blocks;
$blockmanager->add_region('content');
$blockmanager->load_blocks(true);
// Check if block instance does not yet exist
$gsexists = false;
foreach ($blockmanager->get_regions() as $region) {
foreach ($blockmanager->get_blocks_for_region($region) as $block) {
if ($block->instance->blockname == "side_bar") {
$gsexists = true;
}
}
}
if (!$gsexists && !$blockmanager->is_block_present('side_bar')) {
$blockmanager->add_block('side_bar', 'content', -10, 0, 'blocks-side_bar-course');
}
// Start page output.
echo $OUTPUT->header();
echo $OUTPUT->custom_block_region('content');
echo $OUTPUT->footer();