[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/feedback/editpdf/classes/ -> renderer.php (source)

   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              'navigate-page-select' => 'k',
  46              'navigate-next-button' => 'l',
  47              'searchcomments' => 'h',
  48              'comment' => 'z',
  49              'commentcolour' => 'x',
  50              'select' => 'c',
  51              'drag' => 'd',
  52              'pen' => 'y',
  53              'line' => 'u',
  54              'rectangle' => 'i',
  55              'oval' => 'o',
  56              'highlight' => 'p',
  57              'annotationcolour' => 'r',
  58              'stamp' => 'n',
  59              'currentstamp' => 'm');
  60  
  61  
  62          // Return the shortcut.
  63          return $shortcuts[$name];
  64      }
  65  
  66      /**
  67       * Render a single colour button.
  68       *
  69       * @param string $icon - The key for the icon
  70       * @param string $tool - The key for the lang string.
  71       * @param string $accesskey Optional - The access key for the button.
  72       * @param bool $disabled Optional - Is this button disabled.
  73       * @return string
  74       */
  75      private function render_toolbar_button($icon, $tool, $accesskey = null, $disabled=false) {
  76  
  77          // Build button alt text.
  78          $alttext = new stdClass();
  79          $alttext->tool = $tool;
  80          if (!empty($accesskey)) {
  81              $alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
  82          } else {
  83              $alttext->shortcut = '';
  84          }
  85          $iconalt = get_string('toolbarbutton', 'assignfeedback_editpdf', $alttext);
  86  
  87          $iconhtml = $this->pix_icon($icon, $iconalt, 'assignfeedback_editpdf');
  88          $iconparams = array('data-tool'=>$tool, 'class'=>$tool . 'button');
  89          if ($disabled) {
  90              $iconparams['disabled'] = 'true';
  91          }
  92          if (!empty($accesskey)) {
  93              $iconparams['accesskey'] = $accesskey;
  94          }
  95  
  96          return html_writer::tag('button', $iconhtml, $iconparams);
  97      }
  98  
  99      /**
 100       * Render the editpdf widget in the grading form.
 101       *
 102       * @param assignfeedback_editpdf_widget $widget - Renderable widget containing assignment, user and attempt number.
 103       * @return string
 104       */
 105      public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widget $widget) {
 106          global $CFG;
 107  
 108          $html = '';
 109  
 110          $html .= html_writer::div(get_string('jsrequired', 'assignfeedback_editpdf'), 'hiddenifjs');
 111          $linkid = html_writer::random_id();
 112          if ($widget->readonly) {
 113              $launcheditorlink = html_writer::tag('a',
 114                                                get_string('viewfeedbackonline', 'assignfeedback_editpdf'),
 115                                                array('id'=>$linkid, 'class'=>'btn', 'href'=>'#'));
 116          } else {
 117              $launcheditorlink = html_writer::tag('a',
 118                                                get_string('launcheditor', 'assignfeedback_editpdf'),
 119                                                array('id'=>$linkid, 'class'=>'btn', 'href'=>'#'));
 120          }
 121          $links = $launcheditorlink;
 122          $html .= '<input type="hidden" name="assignfeedback_editpdf_haschanges" value="false"/>';
 123  
 124          $html .= html_writer::div($links, 'visibleifjs');
 125          $header = get_string('pluginname', 'assignfeedback_editpdf');
 126          $body = '';
 127          // Create the page navigation.
 128          $navigation1 = '';
 129          $navigation2 = '';
 130          $navigation3 = '';
 131  
 132          // Pick the correct arrow icons for right to left mode.
 133          if (right_to_left()) {
 134              $nav_prev = 'nav_next';
 135              $nav_next = 'nav_prev';
 136          } else {
 137              $nav_prev = 'nav_prev';
 138              $nav_next = 'nav_next';
 139          }
 140  
 141          $iconalt = get_string('navigateprevious', 'assignfeedback_editpdf');
 142          $iconhtml = $this->pix_icon($nav_prev, $iconalt, 'assignfeedback_editpdf');
 143          $navigation1 .= html_writer::tag('button', $iconhtml, array('disabled'=>'true',
 144              'class'=>'navigate-previous-button', 'accesskey' => $this->get_shortcut('navigate-previous-button')));
 145          $navigation1 .= html_writer::tag('select', null, array('disabled'=>'true',
 146              'aria-label' => get_string('gotopage', 'assignfeedback_editpdf'), 'class'=>'navigate-page-select',
 147              'accesskey' => $this->get_shortcut('navigate-page-select')));
 148          $iconalt = get_string('navigatenext', 'assignfeedback_editpdf');
 149          $iconhtml = $this->pix_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  
 159          $toolbar1 = '';
 160          $toolbar2 = '';
 161          $toolbar3 = '';
 162          $toolbar4 = '';
 163          $clearfix = html_writer::div('', 'clearfix');
 164          if (!$widget->readonly) {
 165  
 166              // Comments.
 167              $toolbar1 .= $this->render_toolbar_button('comment', 'comment', $this->get_shortcut('comment'));
 168              $toolbar1 .= $this->render_toolbar_button('background_colour_clear', 'commentcolour', $this->get_shortcut('commentcolour'));
 169              $toolbar1 = html_writer::div($toolbar1, 'toolbar', array('role'=>'toolbar'));
 170  
 171              // Select Tool.
 172              $toolbar2 .= $this->render_toolbar_button('drag', 'drag', $this->get_shortcut('drag'));
 173              $toolbar2 .= $this->render_toolbar_button('select', 'select', $this->get_shortcut('select'));
 174              $toolbar2 = html_writer::div($toolbar2, 'toolbar', array('role'=>'toolbar'));
 175  
 176              // Other Tools.
 177              $toolbar3 = $this->render_toolbar_button('pen', 'pen', $this->get_shortcut('pen'));
 178              $toolbar3 .= $this->render_toolbar_button('line', 'line', $this->get_shortcut('line'));
 179              $toolbar3 .= $this->render_toolbar_button('rectangle', 'rectangle', $this->get_shortcut('rectangle'));
 180              $toolbar3 .= $this->render_toolbar_button('oval', 'oval', $this->get_shortcut('oval'));
 181              $toolbar3 .= $this->render_toolbar_button('highlight', 'highlight', $this->get_shortcut('highlight'));
 182              $toolbar3 .= $this->render_toolbar_button('background_colour_clear', 'annotationcolour', $this->get_shortcut('annotationcolour'));
 183              $toolbar3 = html_writer::div($toolbar3, 'toolbar', array('role'=>'toolbar'));
 184  
 185              // Stamps.
 186              $toolbar4 .= $this->render_toolbar_button('stamp', 'stamp', 'n');
 187              $toolbar4 .= $this->render_toolbar_button('background_colour_clear', 'currentstamp', $this->get_shortcut('currentstamp'));
 188              $toolbar4 = html_writer::div($toolbar4, 'toolbar', array('role'=>'toolbar'));
 189          }
 190  
 191          // Toobars written in reverse order because they are floated right.
 192          $pageheader = html_writer::div($navigation1 .
 193                                         $navigation2 .
 194                                         $toolbar4 .
 195                                         $toolbar3 .
 196                                         $toolbar2 .
 197                                         $toolbar1 .
 198                                         $clearfix,
 199                                         'pageheader');
 200          $body = $pageheader;
 201  
 202          // Loading progress bar.
 203          $progressbar = html_writer::div('', 'bar', array('style' => 'width: 0%'));
 204          $progressbar = html_writer::div($progressbar, 'progress progress-info progress-striped active',
 205              array('title' => get_string('loadingeditor', 'assignfeedback_editpdf'),
 206                    'role'=> 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0,
 207                    'aria-valuemax' => 100));
 208          $progressbarlabel = html_writer::div(get_string('generatingpdf', 'assignfeedback_editpdf'),
 209              'progressbarlabel');
 210          $loading = html_writer::div($progressbar . $progressbarlabel, 'loading');
 211  
 212          $canvas = html_writer::div($loading, 'drawingcanvas');
 213          $canvas = html_writer::div($canvas, 'drawingregion');
 214          $changesmessage = html_writer::tag('div',
 215                                             get_string('draftchangessaved', 'assignfeedback_editpdf'),
 216                                             array(
 217                                                 'class' => 'assignfeedback_editpdf_unsavedchanges warning label label-info'
 218                                             ));
 219  
 220          $changesmessage = html_writer::div($changesmessage, 'unsaved-changes');
 221          $canvas .= $changesmessage;
 222  
 223          $body .= $canvas;
 224  
 225          $footer = '';
 226  
 227          $editorparams = array(array('header'=>$header,
 228                                      'body'=>$body,
 229                                      'footer'=>$footer,
 230                                      'linkid'=>$linkid,
 231                                      'assignmentid'=>$widget->assignment,
 232                                      'userid'=>$widget->userid,
 233                                      'attemptnumber'=>$widget->attemptnumber,
 234                                      'stampfiles'=>$widget->stampfiles,
 235                                      'readonly'=>$widget->readonly,
 236                                      'pagetotal'=>$widget->pagetotal));
 237  
 238          $this->page->requires->yui_module('moodle-assignfeedback_editpdf-editor',
 239                                            'M.assignfeedback_editpdf.editor.init',
 240                                            $editorparams);
 241  
 242          $this->page->requires->strings_for_js(array(
 243              'yellow',
 244              'white',
 245              'red',
 246              'blue',
 247              'green',
 248              'black',
 249              'clear',
 250              'colourpicker',
 251              'loadingeditor',
 252              'pagexofy',
 253              'deletecomment',
 254              'addtoquicklist',
 255              'filter',
 256              'searchcomments',
 257              'commentcontextmenu',
 258              'deleteannotation',
 259              'stamp',
 260              'stamppicker',
 261              'cannotopenpdf',
 262              'pagenumber'
 263          ), 'assignfeedback_editpdf');
 264  
 265          return $html;
 266      }
 267  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1