Proyectos de Subversion Moodle

Rev

Rev 967 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 
57
    /**
58
     * The content object.
59
     *
60
     * @return stdObject
61
     */
965 ariadna 62
    public function get_content()
63
    {
1 efrain 64
        global $CFG, $PAGE;
965 ariadna 65
 
1 efrain 66
        static $jscount = 0;
67
        if ($this->content !== null) {
68
            return $this->content;
69
        } else {
70
            $this->content = new \stdClass();
71
        }
72
 
73
        if (!isloggedin() or isguestuser()) {
74
            return '';      // Never useful unless you are logged in as real users
75
        }
965 ariadna 76
 
1 efrain 77
        if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
78
            return '';
79
        }
965 ariadna 80
 
1 efrain 81
        $this->content = new stdClass();
965 ariadna 82
 
966 ariadna 83
        if (!empty($this->config->title)) {
84
            $this->content->title =  format_text($this->config->title, FORMAT_HTML, array('filter' => true));
85
        } else {
86
            $this->content->title = get_string('cesa_notes', 'block_cesa_notes');
87
        }
88
 
965 ariadna 89
        $this->content->text = '<div class="inline-cesa_notes-opener">' . get_string('showcesa_notes', 'block_cesa_notes') . '</div>';
1 efrain 90
        $this->content->footer = '';
965 ariadna 91
 
967 ariadna 92
        if (empty($this->instance)) {
93
            return $this->content;
94
        }
95
 
1 efrain 96
        if ($jscount == 0) {
97
            $this->block_cesa_notes_get_required_javascript();
98
            $jscount++;
99
        }
967 ariadna 100
 
1 efrain 101
        return $this->content;
102
    }
103
 
104
    /*
105
     * load JS that requires into the page.
106
     */
965 ariadna 107
    private function block_cesa_notes_get_required_javascript()
108
    {
109
        global $PAGE, $CFG;
1 efrain 110
        list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
111
        $config = get_config('block_cesa_notes');
965 ariadna 112
 
1 efrain 113
        $mm = new block_cesa_notes_manager();
114
        $currenttabindex = $mm->get_current_tab($context, $PAGE);
965 ariadna 115
        $arguments = array(
116
            'arg' => array(
117
                'instanceid' => $this->instance->id,
118
                'editing' => ($PAGE->user_is_editing()),
119
                'editingicon_pos' => ($PAGE->user_is_editing()) ? 'cesa_notes-pos-inline' : $config->icondisplayposition,
120
                'maxallowedcharacters' => $config->characterlimit,
121
                'contextid' => $context->id,
122
                'maxallowedcharacters_warning' => get_string('notmorethan', 'block_cesa_notes', $config->characterlimit),
123
                'contextareas' => $mm->get_available_contextareas(),
124
                'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
125
                'perpage' => $config->cesa_notesperpage,
1 efrain 126
            ),
127
        );
128
        $PAGE->requires->string_for_js('charactersleft', 'block_cesa_notes');
129
        $PAGE->requires->string_for_js('notmorethan', 'block_cesa_notes');
130
        $PAGE->requires->string_for_js('cesa_notes', 'block_cesa_notes');
131
        $PAGE->requires->string_for_js('showcesa_notes', 'block_cesa_notes');
132
        $PAGE->requires->string_for_js('savedsuccess', 'block_cesa_notes');
133
        $PAGE->requires->string_for_js('save', 'block_cesa_notes');
134
        $PAGE->requires->string_for_js('placeholdercontent', 'block_cesa_notes');
135
        $PAGE->requires->string_for_js('deletecesa_notes', 'block_cesa_notes');
136
        $PAGE->requires->string_for_js('cesa_notescount', 'block_cesa_notes');
137
        $PAGE->requires->string_for_js('previouspage', 'block_cesa_notes');
138
        $PAGE->requires->string_for_js('nextpage', 'block_cesa_notes');
139
        $PAGE->requires->string_for_js('nothingtodisplay', 'block_cesa_notes');
140
        $PAGE->requires->string_for_js('cesa_notessavedundertab', 'block_cesa_notes');
141
        $PAGE->requires->string_for_js('cancel', 'moodle');
142
        $this->page->requires->js_call_amd('block_cesa_notes/cesa_notesblock', 'init', $arguments);
143
    }
965 ariadna 144
}