Proyectos de Subversion Moodle

Rev

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