forked from TheGlobalATeam/moodle-block_chessblock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_chessblock.php
121 lines (98 loc) · 3.96 KB
/
block_chessblock.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
<?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/>.
/**
* The main blockplugin file
*
* This file contains the initalizing of the chessblock plugin,
* mainly defining the Html of the view.
*
* @package block_chessblock
* @copyright 2016 Global A-Team
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* MOODLE_INTERNAL - object, moodles intenral object.
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/pagelib.php');
/**
* This is the main block class, extending block_base.
*
* The main class for chessblock plugin containing
* the creating of the view and setting uup js files.
*
* @package block_chessblock
* @copyright 2016 Global A-Team
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_chessblock extends block_base {
/** @var boolean This variable checks if js is loaded */
private $jsloaded = false;
/**
* Initalizing the block plugin.
*/
public function init() {
GLOBAL $PAGE;
$this->title = get_string('chessblock', 'block_chessblock');
}
/**
* The applicable_formats function
*/
public function applicable_formats() {
return array('all' => true);
}
/**
* Returns the content og the block.
*
* @return stdClass containing html for the plugin view.
*/
public function get_content() {
global $CFG, $OUTPUT, $USER, $DB, $PAGE, $USER;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = "";
//load the html file and use the Mustache_Engine as a template engine
$mustache = new Mustache_Engine;
$htmlFile = file_get_contents('index.html', true);
$mustacheParserData = array(
'wat' => "lool",
'trans_blocktitle' => get_string('blocktitle', 'block_chessblock'),
'trans_newgamebutton' => get_string('newgamebutton', 'block_chessblock'),
'trans_loadgamebutton' => get_string('loadgamebutton', 'block_chessblock'),
'trans_openMultiplayerButton' => get_string('openMultiplayerButton', 'block_chessblock'),
'trans_gamestatus' => get_string('gamestatus', 'block_chessblock'),
'loading_gif' => $CFG->wwwroot . '/blocks/chessblock/loading.gif',
);
//do the actuall load!
$this->content->text .= $mustache->render($htmlFile, $mustacheParserData);
if (!$this->jsloaded) {
$this->jsloaded = true;
$PAGE->requires->css('/blocks/chessblock/chessboardjs/css/chessboard-0.3.0.css?'.rand());
$PAGE->requires->css('/blocks/chessblock/main.css?'.rand());
$PAGE->requires->js('/blocks/chessblock/chessboardjs/js/chessboard-0.3.0.js?'.rand());
$PAGE->requires->js('/blocks/chessblock/chessboardjs/js/chess.js?'.rand());
$PAGE->requires->js('/blocks/chessblock/main.js?'.rand());
$PAGE->requires->js('/blocks/chessblock/multiplayerNotificatin.js?'.rand());
$stringmanager = get_string_manager();
$strings = $stringmanager->load_component_strings('block_chessblock', current_language());
$PAGE->requires->js_init_call('loadLanguage', array($strings));
}
$this->content->footer = get_string('userid', 'block_chessblock') . ': ' . $USER->id;
return $this->content;
}
}