Proyectos de Subversion Moodle

Rev

Rev 1 | Rev 966 | 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();
965 ariadna 97
        $this->content->text = '<div class="inline-cesa_notes-opener">' . get_string('showcesa_notes', 'block_cesa_notes') . '</div>';
98
 
1 efrain 99
        $this->content->footer = '';
965 ariadna 100
 
1 efrain 101
        if ($jscount == 0) {
102
            $this->block_cesa_notes_get_required_javascript();
103
            $jscount++;
104
        }
105
        return $this->content;
106
    }
107
 
108
    /*
109
     * load JS that requires into the page.
110
     */
965 ariadna 111
    private function block_cesa_notes_get_required_javascript()
112
    {
113
        global $PAGE, $CFG;
1 efrain 114
        list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
115
        $config = get_config('block_cesa_notes');
965 ariadna 116
 
1 efrain 117
        $mm = new block_cesa_notes_manager();
118
        $currenttabindex = $mm->get_current_tab($context, $PAGE);
965 ariadna 119
        $arguments = array(
120
            'arg' => array(
121
                'instanceid' => $this->instance->id,
122
                'editing' => ($PAGE->user_is_editing()),
123
                'editingicon_pos' => ($PAGE->user_is_editing()) ? 'cesa_notes-pos-inline' : $config->icondisplayposition,
124
                'maxallowedcharacters' => $config->characterlimit,
125
                'contextid' => $context->id,
126
                'maxallowedcharacters_warning' => get_string('notmorethan', 'block_cesa_notes', $config->characterlimit),
127
                'contextareas' => $mm->get_available_contextareas(),
128
                'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
129
                'perpage' => $config->cesa_notesperpage,
1 efrain 130
            ),
131
        );
132
        $PAGE->requires->string_for_js('charactersleft', 'block_cesa_notes');
133
        $PAGE->requires->string_for_js('notmorethan', 'block_cesa_notes');
134
        $PAGE->requires->string_for_js('cesa_notes', 'block_cesa_notes');
135
        $PAGE->requires->string_for_js('showcesa_notes', 'block_cesa_notes');
136
        $PAGE->requires->string_for_js('savedsuccess', 'block_cesa_notes');
137
        $PAGE->requires->string_for_js('save', 'block_cesa_notes');
138
        $PAGE->requires->string_for_js('placeholdercontent', 'block_cesa_notes');
139
        $PAGE->requires->string_for_js('deletecesa_notes', 'block_cesa_notes');
140
        $PAGE->requires->string_for_js('cesa_notescount', 'block_cesa_notes');
141
        $PAGE->requires->string_for_js('previouspage', 'block_cesa_notes');
142
        $PAGE->requires->string_for_js('nextpage', 'block_cesa_notes');
143
        $PAGE->requires->string_for_js('nothingtodisplay', 'block_cesa_notes');
144
        $PAGE->requires->string_for_js('cesa_notessavedundertab', 'block_cesa_notes');
145
        $PAGE->requires->string_for_js('cancel', 'moodle');
146
        $this->page->requires->js_call_amd('block_cesa_notes/cesa_notesblock', 'init', $arguments);
147
    }
965 ariadna 148
}