Proyectos de Subversion Moodle

Rev

Rev 965 | Ir a la última revisión | | 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
 */
34
class block_cesa_notes extends block_base {
35
 
36
    public function init() {
37
        $this->title = get_string('pluginname', 'block_cesa_notes');
38
    }
39
 
40
    public function has_config() {
41
        return true;
42
    }
43
 
44
    public function applicable_formats() {
45
        return array('all' => true);
46
    }
47
 
48
    public function instance_allow_multiple() {
49
        return false;
50
    }
51
 
52
    public function hide_header() {
53
        global $PAGE;
54
        if (!$PAGE->user_is_editing()) {
55
            return true;
56
        }
57
    }
58
 
59
    /**
60
     * The content object.
61
     *
62
     * @return stdObject
63
     */
64
    public function get_content() {
65
        global $CFG, $PAGE;
66
 
67
        static $jscount = 0;
68
        if ($this->content !== null) {
69
            return $this->content;
70
        } else {
71
            $this->content = new \stdClass();
72
        }
73
 
74
        if (!isloggedin() or isguestuser()) {
75
            return '';      // Never useful unless you are logged in as real users
76
        }
77
 
78
        if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
79
            return '';
80
        }
81
 
82
        $this->content = new stdClass();
83
        $this->content->footer = '';
84
        $this->content->text = '';
85
        if (empty($this->instance)) {
86
            return $this->content;
87
        }
88
 
89
        $this->content = new stdClass();
90
        $this->content->text = '';
91
        if ($PAGE->user_is_editing()) {
92
            $this->content->text = '<div class="inline-cesa_notes-opener">'.get_string('showcesa_notes', 'block_cesa_notes').'</div>';
93
        }
94
        $this->content->footer = '';
95
 
96
        if ($jscount == 0) {
97
            $this->block_cesa_notes_get_required_javascript();
98
            $jscount++;
99
        }
100
        return $this->content;
101
    }
102
 
103
    /*
104
     * load JS that requires into the page.
105
     */
106
    private function block_cesa_notes_get_required_javascript() {
107
        global $PAGE, $CFG;
108
        list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
109
        $config = get_config('block_cesa_notes');
110
 
111
        $mm = new block_cesa_notes_manager();
112
        $currenttabindex = $mm->get_current_tab($context, $PAGE);
113
        $arguments = array( 'arg'=> array(
114
            'instanceid' => $this->instance->id,
115
            'editing' => ($PAGE->user_is_editing()),
116
            'editingicon_pos' => ($PAGE->user_is_editing()) ? 'cesa_notes-pos-inline' : $config->icondisplayposition,
117
            'maxallowedcharacters' => $config->characterlimit,
118
            'contextid' => $context->id,
119
            'maxallowedcharacters_warning' => get_string('notmorethan', 'block_cesa_notes', $config->characterlimit),
120
            'contextareas' => $mm->get_available_contextareas(),
121
            'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
122
            'perpage' => $config->cesa_notesperpage,
123
            ),
124
        );
125
        $PAGE->requires->string_for_js('charactersleft', 'block_cesa_notes');
126
        $PAGE->requires->string_for_js('notmorethan', 'block_cesa_notes');
127
        $PAGE->requires->string_for_js('cesa_notes', 'block_cesa_notes');
128
        $PAGE->requires->string_for_js('showcesa_notes', 'block_cesa_notes');
129
        $PAGE->requires->string_for_js('savedsuccess', 'block_cesa_notes');
130
        $PAGE->requires->string_for_js('save', 'block_cesa_notes');
131
        $PAGE->requires->string_for_js('placeholdercontent', 'block_cesa_notes');
132
        $PAGE->requires->string_for_js('deletecesa_notes', 'block_cesa_notes');
133
        $PAGE->requires->string_for_js('cesa_notescount', 'block_cesa_notes');
134
        $PAGE->requires->string_for_js('previouspage', 'block_cesa_notes');
135
        $PAGE->requires->string_for_js('nextpage', 'block_cesa_notes');
136
        $PAGE->requires->string_for_js('nothingtodisplay', 'block_cesa_notes');
137
        $PAGE->requires->string_for_js('cesa_notessavedundertab', 'block_cesa_notes');
138
        $PAGE->requires->string_for_js('cancel', 'moodle');
139
        $this->page->requires->js_call_amd('block_cesa_notes/cesa_notesblock', 'init', $arguments);
140
    }
141
}