-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_tour_guide.php
126 lines (100 loc) · 4.12 KB
/
block_tour_guide.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Block Class
*
* @package block_tour_guide
* @copyright 2014 Thomas Threadgold - LearningWorks Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_tour_guide extends block_base {
// Initialises the block.
public function init() {
global $PAGE, $CFG;
$PAGE->requires->jquery();
$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/blocks/tour_guide/js/scripts.js') );
$this->title = get_string('block_title', 'block_tour_guide');
}
// Outputs the block content.
public function get_content() {
if ($this->content !== null) {
return $this->content;
}
// Output the content of the block.
$this->content = new stdClass;
// Get the text for the tour guide button.
if (isset($this->config->button)) {
$this->content->text = '<input type="button" class="tour_guide_trigger" value=' . json_encode($this->config->button) . '>';
} else {
$this->content->text = '<input type="button" class="tour_guide_trigger" value=' . json_encode(get_string('blockbutton_text', 'block_tour_guide')) . '>';
}
// Output a JS Array with the block instance settings.
$this->content->footer = '<script type="text/javascript">var tour_guide_content = [';
// Set tipcount to zero if it is not defined. There are no tips.
if (isset($this->config->tip_count)) {
// Loop through all the object settings.
for ($i = 1; $i <= (int) $this->config->tip_count; $i++) {
$selector = 'tip_' . $i . '_selector';
// Check that the selector has been set.
if (!isset($this->config->$selector)) {
break;
}
if(strlen($this->config->$selector) > 0) {
$theSelector = $this->config->$selector;
} else {
$theSelector = 'html';
}
// Add the content.
$content = 'tip_' . $i . '_content';
$the_content = $this->config->$content;
// Output the settings as a JS Object.
$this->content->footer .= '
{
"selector" : ' . json_encode($theSelector) . ',
"content" : ' . json_encode($the_content['text']);
if( $i !== (int) $this->config->tip_count) {
$this->content->footer .= '
},';
} else {
$this->content->footer .= '
}';
}
}
}
$this->content->footer .= "];";
$highlight_colour = get_config('block_tour_guide', 'highlight_colour');
if (empty($highlight_colour)) {
$this->content->footer .= "var tour_guide_highlight_color = false;";
}
else {
$this->content->footer .= "var tour_guide_highlight_color = " . json_encode($highlight_colour) . ";";
}
$this->content->footer .= "</script>";
return $this->content;
}
//Enable global block settings.
function has_config() {
return true;
}
// Hide the block header.
public function hide_header() {
return true;
}
// Define which page formats the block can be used.
public function applicable_formats() {
return array('all' => true);
}
}