Proyectos de Subversion Moodle

Rev

Rev 731 | 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 mynotes block
19
 *
20
 * @package    block_mynotes
21
 * @author     Gautam Kumar Das<gautam.arg@gmail.com>
22
 */
23
 
24
defined('MOODLE_INTERNAL') || die();
25
 
26
require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
27
 
28
/**
29
 * Mynotes block.
30
 *
31
 * @package    block_mynotes
32
 *
33
 */
34
class block_mynotes extends block_base {
35
 
36
    public function init() {
37
        $this->title = get_string('pluginname', 'block_mynotes');
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
        }
71
 
72
        if (!isloggedin() or isguestuser()) {
73
            return '';      // Never useful unless you are logged in as real users
74
        }
75
 
76
        if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
77
            return '';
78
        }
79
 
80
        $this->content = new stdClass();
81
        $this->content->footer = '';
82
        $this->content->text = '';
83
        if (empty($this->instance)) {
84
            return $this->content;
85
        }
86
 
87
        $this->content = new stdClass();
88
        $this->content->text = '';
89
        if ($PAGE->user_is_editing()) {
90
            $this->content->text = '<div class="inline-mynotes-opener">'.get_string('showmynotes', 'block_mynotes').'</div>';
91
        }
92
        $this->content->footer = '';
93
 
94
        if ($jscount == 0) {
95
            $this->block_mynotes_get_required_javascript();
96
            $jscount++;
97
        }
98
        return $this->content;
99
    }
100
 
101
    /*
102
     * load JS that requires into the page.
103
     */
104
    private function block_mynotes_get_required_javascript() {
105
        global $PAGE, $CFG;
106
        list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
107
        $config = get_config('block_mynotes');
108
 
109
        $mm = new block_mynotes_manager();
110
        $currenttabindex = $mm->get_current_tab($context, $PAGE);
111
        $arguments = array( 'arg'=> array(
112
            'instanceid' => $this->instance->id,
113
            'editing' => ($PAGE->user_is_editing()),
114
            'editingicon_pos' => ($PAGE->user_is_editing()) ? 'mynotes-pos-inline' : $config->icondisplayposition,
115
            'maxallowedcharacters' => $config->characterlimit,
116
            'contextid' => $context->id,
117
            'maxallowedcharacters_warning' => get_string('notmorethan', 'block_mynotes', $config->characterlimit),
118
            'contextareas' => $mm->get_available_contextareas(),
119
            'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
120
            'perpage' => $config->mynotesperpage,
121
            ),
122
        );
123
        $PAGE->requires->string_for_js('charactersleft', 'block_mynotes');
124
        $PAGE->requires->string_for_js('notmorethan', 'block_mynotes');
125
        $PAGE->requires->string_for_js('mynotes', 'block_mynotes');
126
        $PAGE->requires->string_for_js('showmynotes', 'block_mynotes');
127
        $PAGE->requires->string_for_js('savedsuccess', 'block_mynotes');
128
        $PAGE->requires->string_for_js('save', 'block_mynotes');
129
        $PAGE->requires->string_for_js('placeholdercontent', 'block_mynotes');
130
        $PAGE->requires->string_for_js('deletemynotes', 'block_mynotes');
131
        $PAGE->requires->string_for_js('mynotescount', 'block_mynotes');
132
        $PAGE->requires->string_for_js('previouspage', 'block_mynotes');
133
        $PAGE->requires->string_for_js('nextpage', 'block_mynotes');
134
        $PAGE->requires->string_for_js('nothingtodisplay', 'block_mynotes');
135
        $PAGE->requires->string_for_js('mynotessavedundertab', 'block_mynotes');
136
        $PAGE->requires->string_for_js('cancel', 'moodle');
137
        $this->page->requires->js_call_amd('block_mynotes/mynotesblock', 'init', $arguments);
138
    }
139
}