Proyectos de Subversion Moodle

Rev

| 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
 * This file contains the definition for the library class for edit PDF renderer.
19
 *
20
 * @package   assignfeedback_editpdf
21
 * @copyright 2012 Davo Smith
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * A custom renderer class that extends the plugin_renderer_base and is used by the editpdf feedback plugin.
29
 *
30
 * @package assignfeedback_editpdf
31
 * @copyright 2013 Davo Smith
32
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class assignfeedback_editpdf_renderer extends plugin_renderer_base {
35
 
36
    /**
37
     * Return the PDF button shortcut.
38
     *
39
     * @param string $name the name of a specific button.
40
     * @return string the specific shortcut.
41
     */
42
    private function get_shortcut($name) {
43
 
44
        $shortcuts = array('navigate-previous-button' => 'j',
45
            'rotateleft' => 'q',
46
            'rotateright' => 'w',
47
            'navigate-page-select' => 'k',
48
            'navigate-next-button' => 'l',
49
            'searchcomments' => 'h',
50
            'expcolcomments' => 'g',
51
            'comment' => 'z',
52
            'commentcolour' => 'x',
53
            'select' => 'c',
54
            'drag' => 'd',
55
            'pen' => 'y',
56
            'line' => 'u',
57
            'rectangle' => 'i',
58
            'oval' => 'o',
59
            'highlight' => 'p',
60
            'annotationcolour' => 'r',
61
            'stamp' => 'n',
62
            'currentstamp' => 'm');
63
 
64
 
65
        // Return the shortcut.
66
        return $shortcuts[$name];
67
    }
68
 
69
    /**
70
     * Render a single colour button.
71
     *
72
     * @param string $icon - The key for the icon
73
     * @param string $tool - The key for the lang string.
74
     * @param string $accesskey Optional - The access key for the button.
75
     * @param bool $disabled Optional - Is this button disabled.
76
     * @return string
77
     */
78
    private function render_toolbar_button($icon, $tool, $accesskey = null, $disabled=false) {
79
 
80
        // Build button alt text.
81
        $alttext = new stdClass();
82
        $alttext->tool = get_string($tool, 'assignfeedback_editpdf');
83
        if (!empty($accesskey)) {
84
            $alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
85
        } else {
86
            $alttext->shortcut = '';
87
        }
88
        $iconalt = get_string('toolbarbutton', 'assignfeedback_editpdf', $alttext);
89
 
90
        $iconhtml = $this->image_icon($icon, $iconalt, 'assignfeedback_editpdf');
91
        $iconparams = array('data-tool'=>$tool, 'class'=>$tool . 'button');
92
        if ($disabled) {
93
            $iconparams['disabled'] = 'true';
94
        }
95
        if (!empty($accesskey)) {
96
            $iconparams['accesskey'] = $accesskey;
97
        }
98
 
99
        return html_writer::tag('button', $iconhtml, $iconparams);
100
    }
101
 
102
    /**
103
     * Render the editpdf widget in the grading form.
104
     *
105
     * @param assignfeedback_editpdf_widget $widget - Renderable widget containing assignment, user and attempt number.
106
     * @return string
107
     */
108
    public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widget $widget) {
109
        global $CFG;
110
 
111
        $html = '';
112
 
113
        $html .= html_writer::div(get_string('jsrequired', 'assignfeedback_editpdf'), 'hiddenifjs');
114
        $linkid = html_writer::random_id();
115
 
116
        $launcheditorstring = $widget->readonly ? get_string('viewfeedbackonline', 'assignfeedback_editpdf') :
117
            get_string('launcheditor', 'assignfeedback_editpdf');
118
        $links = html_writer::link('#', $launcheditorstring, ['id' => $linkid, 'class' => 'd-block mt-2']);
119
 
120
        $html .= '<input type="hidden" name="assignfeedback_editpdf_haschanges" value="false"/>';
121
 
122
        $html .= html_writer::div($links, 'visibleifjs');
123
        $header = get_string('pluginname', 'assignfeedback_editpdf');
124
        $body = '';
125
        // Create the page navigation.
126
        $navigation1 = '';
127
        $navigation2 = '';
128
        $navigation3 = '';
129
 
130
        // Pick the correct arrow icons for right to left mode.
131
        if (right_to_left()) {
132
            $nav_prev = 'nav_next';
133
            $nav_next = 'nav_prev';
134
        } else {
135
            $nav_prev = 'nav_prev';
136
            $nav_next = 'nav_next';
137
        }
138
 
139
        $iconshortcut = $this->get_shortcut('navigate-previous-button');
140
        $iconalt = get_string('navigateprevious', 'assignfeedback_editpdf', $iconshortcut);
141
        $iconhtml = $this->image_icon($nav_prev, $iconalt, 'assignfeedback_editpdf');
142
        $navigation1 .= html_writer::tag('button', $iconhtml, array('disabled'=>'true',
143
            'class'=>'navigate-previous-button', 'accesskey' => $this->get_shortcut('navigate-previous-button')));
144
        $navigation1 .= html_writer::tag('select', null, array('disabled'=>'true',
145
            'aria-label' => get_string('gotopage', 'assignfeedback_editpdf'), 'class'=>'navigate-page-select',
146
            'accesskey' => $this->get_shortcut('navigate-page-select')));
147
        $iconshortcut = $this->get_shortcut('navigate-next-button');
148
        $iconalt = get_string('navigatenext', 'assignfeedback_editpdf', $iconshortcut);
149
        $iconhtml = $this->image_icon($nav_next, $iconalt, 'assignfeedback_editpdf');
150
        $navigation1 .= html_writer::tag('button', $iconhtml, array('disabled'=>'true',
151
            'class'=>'navigate-next-button', 'accesskey' => $this->get_shortcut('navigate-next-button')));
152
 
153
        $navigation1 = html_writer::div($navigation1, 'navigation', array('role'=>'navigation'));
154
 
155
        $navigation2 .= $this->render_toolbar_button('comment_search', 'searchcomments', $this->get_shortcut('searchcomments'));
156
        $navigation2 = html_writer::div($navigation2, 'navigation-search', array('role'=>'navigation'));
157
 
158
        $navigation3 .= $this->render_toolbar_button('comment_expcol', 'expcolcomments', $this->get_shortcut('expcolcomments'));
159
        $navigation3 = html_writer::div($navigation3, 'navigation-expcol', array('role' => 'navigation'));
160
 
161
        $rotationtools = '';
162
        if (!$widget->readonly) {
163
            $rotationtools .= $this->render_toolbar_button('rotate_left', 'rotateleft', $this->get_shortcut('rotateleft'));
164
            $rotationtools .= $this->render_toolbar_button('rotate_right', 'rotateright', $this->get_shortcut('rotateright'));
165
            $rotationtools = html_writer::div($rotationtools, 'toolbar', array('role' => 'toolbar'));
166
        }
167
 
168
        $toolbargroup = '';
169
        $clearfix = html_writer::div('', 'clearfix');
170
        if (!$widget->readonly) {
171
            // Comments.
172
            $toolbar1 = '';
173
            $toolbar1 .= $this->render_toolbar_button('comment', 'comment', $this->get_shortcut('comment'));
174
            $toolbar1 .= $this->render_toolbar_button('background_colour_clear', 'commentcolour', $this->get_shortcut('commentcolour'));
175
            $toolbar1 = html_writer::div($toolbar1, 'toolbar', array('role' => 'toolbar'));
176
 
177
            // Select Tool.
178
            $toolbar2 = '';
179
            $toolbar2 .= $this->render_toolbar_button('drag', 'drag', $this->get_shortcut('drag'));
180
            $toolbar2 .= $this->render_toolbar_button('select', 'select', $this->get_shortcut('select'));
181
            $toolbar2 = html_writer::div($toolbar2, 'toolbar', array('role' => 'toolbar'));
182
 
183
            // Other Tools.
184
            $toolbar3 = '';
185
            $toolbar3 .= $this->render_toolbar_button('pen', 'pen', $this->get_shortcut('pen'));
186
            $toolbar3 .= $this->render_toolbar_button('line', 'line', $this->get_shortcut('line'));
187
            $toolbar3 .= $this->render_toolbar_button('rectangle', 'rectangle', $this->get_shortcut('rectangle'));
188
            $toolbar3 .= $this->render_toolbar_button('oval', 'oval', $this->get_shortcut('oval'));
189
            $toolbar3 .= $this->render_toolbar_button('highlight', 'highlight', $this->get_shortcut('highlight'));
190
            $toolbar3 .= $this->render_toolbar_button('background_colour_clear', 'annotationcolour', $this->get_shortcut('annotationcolour'));
191
            $toolbar3 = html_writer::div($toolbar3, 'toolbar', array('role' => 'toolbar'));
192
 
193
            // Stamps.
194
            $toolbar4 = '';
195
            $toolbar4 .= $this->render_toolbar_button('stamp', 'stamp', $this->get_shortcut('stamp'));
196
            $toolbar4 .= $this->render_toolbar_button('background_colour_clear', 'currentstamp', $this->get_shortcut('currentstamp'));
197
            $toolbar4 = html_writer::div($toolbar4, 'toolbar', array('role'=>'toolbar'));
198
 
199
            // Add toolbars to toolbar_group in order of display, and float the toolbar_group right.
200
            $toolbars = $rotationtools . $toolbar1 . $toolbar2 . $toolbar3 . $toolbar4;
201
            $toolbargroup = html_writer::div($toolbars, 'toolbar_group', ['role' => 'toolbar']);
202
        }
203
 
204
        $pageheader = html_writer::div($navigation1 .
205
                                       $navigation2 .
206
                                       $navigation3 .
207
                                       $toolbargroup .
208
                                       $clearfix,
209
                                       'pageheader');
210
        $body = $pageheader;
211
 
212
        // Loading progress bar.
213
        $progressbar = html_writer::div('', 'bar', array('style' => 'width: 0%'));
214
        $progressbar = html_writer::div($progressbar, 'progress progress-info progress-striped active',
215
            array('title' => get_string('loadingeditor', 'assignfeedback_editpdf'),
216
                  'role'=> 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0,
217
                  'aria-valuemax' => 100));
218
        $progressbarlabel = html_writer::div(get_string('generatingpdf', 'assignfeedback_editpdf'),
219
            'progressbarlabel');
220
        $loading = html_writer::div($progressbar . $progressbarlabel, 'loading');
221
 
222
        $canvas = html_writer::div($loading, 'drawingcanvas');
223
        $canvas = html_writer::div($canvas, 'drawingregion');
224
        // Place for messages, but no warnings displayed yet.
225
        $changesmessage = html_writer::div('', 'warningmessages');
226
        $canvas .= $changesmessage;
227
 
228
        $infoicon = $this->image_icon('i/info', '');
229
        $infomessage = html_writer::div($infoicon, 'infoicon');
230
        $canvas .= $infomessage;
231
 
232
        $body .= $canvas;
233
 
234
        $footer = '';
235
 
236
        $editorparams = array(
237
            array(
238
                'header' => $header,
239
                'body' => $body,
240
                'footer' => $footer,
241
                'linkid' => $linkid,
242
                'assignmentid' => $widget->assignment,
243
                'userid' => $widget->userid,
244
                'attemptnumber' => $widget->attemptnumber,
245
                'stampfiles' => $widget->stampfiles,
246
                'readonly' => $widget->readonly,
247
            )
248
        );
249
 
250
        $this->page->requires->yui_module('moodle-assignfeedback_editpdf-editor',
251
                                          'M.assignfeedback_editpdf.editor.init',
252
                                          $editorparams);
253
 
254
        $this->page->requires->strings_for_js(array(
255
            'yellow',
256
            'white',
257
            'red',
258
            'blue',
259
            'green',
260
            'black',
261
            'clear',
262
            'colourpicker',
263
            'loadingeditor',
264
            'pagexofy',
265
            'deletecomment',
266
            'addtoquicklist',
267
            'filter',
268
            'searchcomments',
269
            'commentcontextmenu',
270
            'deleteannotation',
271
            'stamp',
272
            'stamppicker',
273
            'cannotopenpdf',
274
            'pagenumber',
275
            'partialwarning',
276
            'draftchangessaved'
277
        ), 'assignfeedback_editpdf');
278
 
279
        return $html;
280
    }
281
}