1 |
efrain |
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 cesa_notes block
|
|
|
19 |
*
|
|
|
20 |
* @package block_cesa_notes
|
|
|
21 |
* @author Gautam Kumar Das<gautam.arg@gmail.com>
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
defined('MOODLE_INTERNAL') || die();
|
|
|
25 |
|
|
|
26 |
require_once($CFG->dirroot . '/blocks/cesa_notes/lib.php');
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* cesa_notes block.
|
|
|
30 |
*
|
|
|
31 |
* @package block_cesa_notes
|
|
|
32 |
*
|
|
|
33 |
*/
|
965 |
ariadna |
34 |
class block_cesa_notes extends block_base
|
|
|
35 |
{
|
1 |
efrain |
36 |
|
965 |
ariadna |
37 |
public function init()
|
|
|
38 |
{
|
1 |
efrain |
39 |
$this->title = get_string('pluginname', 'block_cesa_notes');
|
|
|
40 |
}
|
|
|
41 |
|
965 |
ariadna |
42 |
public function has_config()
|
|
|
43 |
{
|
1 |
efrain |
44 |
return true;
|
|
|
45 |
}
|
|
|
46 |
|
965 |
ariadna |
47 |
public function applicable_formats()
|
|
|
48 |
{
|
1 |
efrain |
49 |
return array('all' => true);
|
|
|
50 |
}
|
|
|
51 |
|
965 |
ariadna |
52 |
public function instance_allow_multiple()
|
|
|
53 |
{
|
1 |
efrain |
54 |
return false;
|
|
|
55 |
}
|
|
|
56 |
|
1046 |
ariadna |
57 |
function specialization()
|
|
|
58 |
{
|
|
|
59 |
global $CFG, $DB;
|
|
|
60 |
if (empty($this->config)) {
|
|
|
61 |
$this->instance->defaultregion = 'side-pre';
|
|
|
62 |
$this->instance->region = 'side-pre';
|
|
|
63 |
$DB->update_record('block_instances', $this->instance);
|
|
|
64 |
|
|
|
65 |
$this->title = 'Apuntes y resumen';
|
|
|
66 |
} else {
|
|
|
67 |
$this->title = get_string('pluginname', 'block_cesa_notes');
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
1 |
efrain |
71 |
/**
|
|
|
72 |
* The content object.
|
|
|
73 |
*
|
|
|
74 |
* @return stdObject
|
|
|
75 |
*/
|
965 |
ariadna |
76 |
public function get_content()
|
|
|
77 |
{
|
1 |
efrain |
78 |
global $CFG, $PAGE;
|
965 |
ariadna |
79 |
|
1 |
efrain |
80 |
static $jscount = 0;
|
|
|
81 |
if ($this->content !== null) {
|
|
|
82 |
return $this->content;
|
|
|
83 |
} else {
|
|
|
84 |
$this->content = new \stdClass();
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
if (!isloggedin() or isguestuser()) {
|
|
|
88 |
return ''; // Never useful unless you are logged in as real users
|
|
|
89 |
}
|
965 |
ariadna |
90 |
|
1 |
efrain |
91 |
if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
|
|
|
92 |
return '';
|
|
|
93 |
}
|
965 |
ariadna |
94 |
|
1 |
efrain |
95 |
$this->content = new stdClass();
|
965 |
ariadna |
96 |
|
966 |
ariadna |
97 |
if (!empty($this->config->title)) {
|
|
|
98 |
$this->content->title = format_text($this->config->title, FORMAT_HTML, array('filter' => true));
|
|
|
99 |
} else {
|
|
|
100 |
$this->content->title = get_string('cesa_notes', 'block_cesa_notes');
|
|
|
101 |
}
|
|
|
102 |
|
965 |
ariadna |
103 |
$this->content->text = '<div class="inline-cesa_notes-opener">' . get_string('showcesa_notes', 'block_cesa_notes') . '</div>';
|
1 |
efrain |
104 |
$this->content->footer = '';
|
965 |
ariadna |
105 |
|
967 |
ariadna |
106 |
if (empty($this->instance)) {
|
|
|
107 |
return $this->content;
|
|
|
108 |
}
|
|
|
109 |
|
1 |
efrain |
110 |
if ($jscount == 0) {
|
|
|
111 |
$this->block_cesa_notes_get_required_javascript();
|
|
|
112 |
$jscount++;
|
|
|
113 |
}
|
967 |
ariadna |
114 |
|
1 |
efrain |
115 |
return $this->content;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/*
|
|
|
119 |
* load JS that requires into the page.
|
|
|
120 |
*/
|
965 |
ariadna |
121 |
private function block_cesa_notes_get_required_javascript()
|
|
|
122 |
{
|
|
|
123 |
global $PAGE, $CFG;
|
1 |
efrain |
124 |
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
|
|
|
125 |
$config = get_config('block_cesa_notes');
|
965 |
ariadna |
126 |
|
1 |
efrain |
127 |
$mm = new block_cesa_notes_manager();
|
|
|
128 |
$currenttabindex = $mm->get_current_tab($context, $PAGE);
|
965 |
ariadna |
129 |
$arguments = array(
|
|
|
130 |
'arg' => array(
|
|
|
131 |
'instanceid' => $this->instance->id,
|
|
|
132 |
'editing' => ($PAGE->user_is_editing()),
|
|
|
133 |
'editingicon_pos' => ($PAGE->user_is_editing()) ? 'cesa_notes-pos-inline' : $config->icondisplayposition,
|
|
|
134 |
'maxallowedcharacters' => $config->characterlimit,
|
|
|
135 |
'contextid' => $context->id,
|
|
|
136 |
'maxallowedcharacters_warning' => get_string('notmorethan', 'block_cesa_notes', $config->characterlimit),
|
|
|
137 |
'contextareas' => $mm->get_available_contextareas(),
|
|
|
138 |
'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
|
|
|
139 |
'perpage' => $config->cesa_notesperpage,
|
1 |
efrain |
140 |
),
|
|
|
141 |
);
|
|
|
142 |
$PAGE->requires->string_for_js('charactersleft', 'block_cesa_notes');
|
|
|
143 |
$PAGE->requires->string_for_js('notmorethan', 'block_cesa_notes');
|
|
|
144 |
$PAGE->requires->string_for_js('cesa_notes', 'block_cesa_notes');
|
|
|
145 |
$PAGE->requires->string_for_js('showcesa_notes', 'block_cesa_notes');
|
|
|
146 |
$PAGE->requires->string_for_js('savedsuccess', 'block_cesa_notes');
|
|
|
147 |
$PAGE->requires->string_for_js('save', 'block_cesa_notes');
|
|
|
148 |
$PAGE->requires->string_for_js('placeholdercontent', 'block_cesa_notes');
|
|
|
149 |
$PAGE->requires->string_for_js('deletecesa_notes', 'block_cesa_notes');
|
|
|
150 |
$PAGE->requires->string_for_js('cesa_notescount', 'block_cesa_notes');
|
|
|
151 |
$PAGE->requires->string_for_js('previouspage', 'block_cesa_notes');
|
|
|
152 |
$PAGE->requires->string_for_js('nextpage', 'block_cesa_notes');
|
|
|
153 |
$PAGE->requires->string_for_js('nothingtodisplay', 'block_cesa_notes');
|
|
|
154 |
$PAGE->requires->string_for_js('cesa_notessavedundertab', 'block_cesa_notes');
|
|
|
155 |
$PAGE->requires->string_for_js('cancel', 'moodle');
|
|
|
156 |
$this->page->requires->js_call_amd('block_cesa_notes/cesa_notesblock', 'init', $arguments);
|
|
|
157 |
}
|
965 |
ariadna |
158 |
}
|