Proyectos de Subversion Moodle

Rev

Rev 1 | Rev 733 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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