Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Moodle renderer used to display special elements of the lesson module
  20   *
  21   * @package mod_lesson
  22   * @copyright  2009 Sam Hemelryk
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   **/
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  class mod_lesson_renderer extends plugin_renderer_base {
  29      /**
  30       * Returns the header for the lesson module
  31       *
  32       * @param lesson $lesson a lesson object.
  33       * @param string $currenttab current tab that is shown.
  34       * @param bool   $extraeditbuttons if extra edit buttons should be displayed.
  35       * @param int    $lessonpageid id of the lesson page that needs to be displayed.
  36       * @param string $extrapagetitle String to appent to the page title.
  37       * @return string
  38       */
  39      public function header($lesson, $cm, $currenttab = '', $extraeditbuttons = false, $lessonpageid = null, $extrapagetitle = null) {
  40          global $CFG;
  41  
  42          $activityname = format_string($lesson->name, true, $lesson->course);
  43          if (empty($extrapagetitle)) {
  44              $title = $this->page->course->shortname.": ".$activityname;
  45          } else {
  46              $title = $this->page->course->shortname.": ".$activityname.": ".$extrapagetitle;
  47          }
  48  
  49          // Build the buttons
  50          $context = context_module::instance($cm->id);
  51  
  52          // Header setup.
  53          $this->page->set_title($title);
  54          $this->page->set_heading($this->page->course->fullname);
  55          lesson_add_header_buttons($cm, $context, $extraeditbuttons, $lessonpageid);
  56          $output = $this->output->header();
  57  
  58          if (has_capability('mod/lesson:manage', $context)) {
  59              $output .= $this->output->heading_with_help($activityname, 'overview', 'lesson');
  60              // Info box.
  61              if ($lesson->intro) {
  62                  $output .= $this->output->box(format_module_intro('lesson', $lesson, $cm->id), 'generalbox', 'intro');
  63              }
  64              if (!empty($currenttab)) {
  65                  ob_start();
  66                  include($CFG->dirroot.'/mod/lesson/tabs.php');
  67                  $output .= ob_get_contents();
  68                  ob_end_clean();
  69              }
  70          } else {
  71              $output .= $this->output->heading($activityname);
  72              // Info box.
  73              if ($lesson->intro) {
  74                  $output .= $this->output->box(format_module_intro('lesson', $lesson, $cm->id), 'generalbox', 'intro');
  75              }
  76          }
  77  
  78          foreach ($lesson->messages as $message) {
  79              $output .= $this->output->notification($message[0], $message[1], $message[2]);
  80          }
  81  
  82          return $output;
  83      }
  84  
  85      /**
  86       * Returns the footer
  87       * @return string
  88       */
  89      public function footer() {
  90          return $this->output->footer();
  91      }
  92  
  93      /**
  94       * Returns HTML for a lesson inaccessible message
  95       *
  96       * @param string $message
  97       * @return <type>
  98       */
  99      public function lesson_inaccessible($message) {
 100          global $CFG;
 101          $output  =  $this->output->box_start('generalbox boxaligncenter');
 102          $output .=  $this->output->box_start('center');
 103          $output .=  $message;
 104          $output .=  $this->output->box('<a href="'.$CFG->wwwroot.'/course/view.php?id='. $this->page->course->id .'">'. get_string('returnto', 'lesson', format_string($this->page->course->fullname, true)) .'</a>', 'lessonbutton standardbutton');
 105          $output .=  $this->output->box_end();
 106          $output .=  $this->output->box_end();
 107          return $output;
 108      }
 109  
 110      /**
 111       * Returns HTML to prompt the user to log in
 112       * @param lesson $lesson
 113       * @param bool $failedattempt
 114       * @return string
 115       */
 116      public function login_prompt(lesson $lesson, $failedattempt = false) {
 117          global $CFG;
 118          $output  = $this->output->box_start('password-form');
 119          $output .= $this->output->box_start('generalbox boxaligncenter');
 120          $output .=  '<form id="password" method="post" action="'.$CFG->wwwroot.'/mod/lesson/view.php" autocomplete="off">';
 121          $output .=  '<fieldset class="invisiblefieldset center">';
 122          $output .=  '<input type="hidden" name="id" value="'. $this->page->cm->id .'" />';
 123          $output .=  '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
 124          if ($failedattempt) {
 125              $output .=  $this->output->notification(get_string('loginfail', 'lesson'));
 126          }
 127          $output .= get_string('passwordprotectedlesson', 'lesson', format_string($lesson->name)).'<br /><br />';
 128          $output .= get_string('enterpassword', 'lesson')." <input type=\"password\" name=\"userpassword\" /><br /><br />";
 129          $output .= "<div class='lessonbutton standardbutton submitbutton'><input type='submit' value='".get_string('continue', 'lesson')."' /></div>";
 130          $output .= " <div class='lessonbutton standardbutton submitbutton'><input type='submit' name='backtocourse' value='".get_string('cancel', 'lesson')."' /></div>";
 131          $output .=  '</fieldset></form>';
 132          $output .=  $this->output->box_end();
 133          $output .=  $this->output->box_end();
 134          return $output;
 135      }
 136  
 137      /**
 138       * Returns HTML to display dependancy errors
 139       *
 140       * @param object $dependentlesson
 141       * @param array $errors
 142       * @return string
 143       */
 144      public function dependancy_errors($dependentlesson, $errors) {
 145          $output  = $this->output->box_start('generalbox boxaligncenter');
 146          $output .= get_string('completethefollowingconditions', 'lesson', $dependentlesson->name);
 147          $output .= $this->output->box(implode('<br />'.get_string('and', 'lesson').'<br />', $errors),'center');
 148          $output .= $this->output->box_end();
 149          return $output;
 150      }
 151  
 152      /**
 153       * Returns HTML to display a message
 154       * @param string $message
 155       * @param single_button $button
 156       * @return string
 157       */
 158      public function message($message, single_button $button = null) {
 159          $output  = $this->output->box_start('generalbox boxaligncenter');
 160          $output .= $message;
 161          if ($button !== null) {
 162              $output .= $this->output->box($this->output->render($button), 'lessonbutton standardbutton');
 163          }
 164          $output .= $this->output->box_end();
 165          return $output;
 166      }
 167  
 168      /**
 169       * Returns HTML to display a continue button
 170       * @param lesson $lesson
 171       * @param int $lastpageseen
 172       * @return string
 173       */
 174      public function continue_links(lesson $lesson, $lastpageseenid) {
 175          global $CFG;
 176          $output = $this->output->box(get_string('youhaveseen','lesson'), 'generalbox boxaligncenter');
 177          $output .= $this->output->box_start('center');
 178  
 179          $yeslink = html_writer::link(new moodle_url('/mod/lesson/view.php', array('id' => $this->page->cm->id,
 180              'pageid' => $lastpageseenid, 'startlastseen' => 'yes')), get_string('yes'), array('class' => 'btn btn-primary'));
 181          $output .= html_writer::tag('span', $yeslink, array('class'=>'lessonbutton standardbutton'));
 182          $output .= '&nbsp;';
 183  
 184          $nolink = html_writer::link(new moodle_url('/mod/lesson/view.php', array('id' => $this->page->cm->id,
 185              'pageid' => $lesson->firstpageid, 'startlastseen' => 'no')), get_string('no'), array('class' => 'btn btn-secondary'));
 186          $output .= html_writer::tag('span', $nolink, array('class'=>'lessonbutton standardbutton'));
 187  
 188          $output .= $this->output->box_end();
 189          return $output;
 190      }
 191  
 192      /**
 193       * Returns HTML to display a page to the user
 194       * @param lesson $lesson
 195       * @param lesson_page $page
 196       * @param object $attempt
 197       * @return string
 198       */
 199      public function display_page(lesson $lesson, lesson_page $page, $attempt) {
 200          // We need to buffer here as there is an mforms display call
 201          ob_start();
 202          echo $page->display($this, $attempt);
 203          $output = ob_get_contents();
 204          ob_end_clean();
 205          return $output;
 206      }
 207  
 208      /**
 209       * Returns HTML to display a collapsed edit form
 210       *
 211       * @param lesson $lesson
 212       * @param int $pageid
 213       * @return string
 214       */
 215      public function display_edit_collapsed(lesson $lesson, $pageid) {
 216          global $DB, $CFG;
 217  
 218          $manager = lesson_page_type_manager::get($lesson);
 219          $qtypes = $manager->get_page_type_strings();
 220          $npages = count($lesson->load_all_pages());
 221  
 222          $table = new html_table();
 223          $table->head = array(get_string('pagetitle', 'lesson'), get_string('qtype', 'lesson'), get_string('jumps', 'lesson'), get_string('actions', 'lesson'));
 224          $table->align = array('left', 'left', 'left', 'center');
 225          $table->wrap = array('', 'nowrap', '', 'nowrap');
 226          $table->tablealign = 'center';
 227          $table->cellspacing = 0;
 228          $table->cellpadding = '2px';
 229          $table->width = '80%';
 230          $table->data = array();
 231  
 232          $canedit = has_capability('mod/lesson:edit', context_module::instance($this->page->cm->id));
 233  
 234          while ($pageid != 0) {
 235              $page = $lesson->load_page($pageid);
 236              $data = array();
 237              $url = new moodle_url('/mod/lesson/edit.php', array(
 238                  'id'     => $this->page->cm->id,
 239                  'mode'   => 'single',
 240                  'pageid' => $page->id
 241              ));
 242              $data[] = html_writer::link($url, format_string($page->title, true), array('id' => 'lesson-' . $page->id));
 243              $data[] = $qtypes[$page->qtype];
 244              $data[] = implode("<br />\n", $page->jumps);
 245              if ($canedit) {
 246                  $data[] = $this->page_action_links($page, $npages, true);
 247              } else {
 248                  $data[] = '';
 249              }
 250              $table->data[] = $data;
 251              $pageid = $page->nextpageid;
 252          }
 253  
 254          return html_writer::table($table);
 255      }
 256  
 257      /**
 258       * Returns HTML to display the full edit page
 259       *
 260       * @param lesson $lesson
 261       * @param int $pageid
 262       * @param int $prevpageid
 263       * @param bool $single
 264       * @return string
 265       */
 266      public function display_edit_full(lesson $lesson, $pageid, $prevpageid, $single=false) {
 267          global $DB, $CFG;
 268  
 269          $manager = lesson_page_type_manager::get($lesson);
 270          $qtypes = $manager->get_page_type_strings();
 271          $npages = count($lesson->load_all_pages());
 272          $canedit = has_capability('mod/lesson:edit', context_module::instance($this->page->cm->id));
 273  
 274          $content = '';
 275          if ($canedit) {
 276              $content = $this->add_page_links($lesson, $prevpageid);
 277          }
 278  
 279          $options = new stdClass;
 280          $options->noclean = true;
 281  
 282          while ($pageid != 0 && $single!=='stop') {
 283              $page = $lesson->load_page($pageid);
 284  
 285              $pagetable = new html_table();
 286              $pagetable->align = array('right','left');
 287              $pagetable->width = '100%';
 288              $pagetable->tablealign = 'center';
 289              $pagetable->cellspacing = 0;
 290              $pagetable->cellpadding = '5px';
 291              $pagetable->data = array();
 292  
 293              $pageheading = new html_table_cell();
 294  
 295              $pageheading->text = html_writer::tag('a', '', array('id' => 'lesson-' . $pageid)) . format_string($page->title);
 296              if ($canedit) {
 297                  $pageheading->text .= ' '.$this->page_action_links($page, $npages);
 298              }
 299              $pageheading->style = 'text-align:center';
 300              $pageheading->colspan = 2;
 301              $pageheading->scope = 'col';
 302              $pagetable->head = array($pageheading);
 303  
 304              $cell = new html_table_cell();
 305              $cell->colspan = 2;
 306              $cell->style = 'text-align:left';
 307              $cell->text = $page->contents;
 308              $pagetable->data[] = new html_table_row(array($cell));
 309  
 310              $cell = new html_table_cell();
 311              $cell->colspan = 2;
 312              $cell->style = 'text-align:center';
 313              $cell->text = '<strong>'.$qtypes[$page->qtype] . $page->option_description_string().'</strong>';
 314              $pagetable->data[] = new html_table_row(array($cell));
 315  
 316              $pagetable = $page->display_answers($pagetable);
 317  
 318              $content .= html_writer::start_tag('div');
 319              $content .= html_writer::table($pagetable);
 320              $content .= html_writer::end_tag('div');
 321  
 322              if ($canedit) {
 323                  $content .= $this->add_page_links($lesson, $pageid);
 324              }
 325  
 326              // check the prev links - fix (silently) if necessary - there was a bug in
 327              // versions 1 and 2 when add new pages. Not serious then as the backwards
 328              // links were not used in those versions
 329              if ($page->prevpageid != $prevpageid) {
 330                  // fix it
 331                  $DB->set_field("lesson_pages", "prevpageid", $prevpageid, array("id" => $page->id));
 332                  debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
 333              }
 334  
 335              $prevpageid = $page->id;
 336              $pageid = $page->nextpageid;
 337  
 338              if ($single === true) {
 339                  $single = 'stop';
 340              }
 341  
 342          }
 343  
 344          return $this->output->box($content, 'edit_pages_box');
 345      }
 346  
 347      /**
 348       * Returns HTML to display the add page links
 349       *
 350       * @param lesson $lesson
 351       * @param int $prevpageid
 352       * @return string
 353       */
 354      public function add_page_links(lesson $lesson, $prevpageid=false) {
 355          global $CFG;
 356  
 357          $links = array();
 358  
 359          $importquestionsurl = new moodle_url('/mod/lesson/import.php',array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
 360          $links[] = html_writer::link($importquestionsurl, get_string('importquestions', 'lesson'));
 361  
 362          $manager = lesson_page_type_manager::get($lesson);
 363          foreach($manager->get_add_page_type_links($prevpageid) as $link) {
 364              $links[] = html_writer::link($link['addurl'], $link['name']);
 365          }
 366  
 367          $addquestionurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
 368          $links[] = html_writer::link($addquestionurl, get_string('addaquestionpagehere', 'lesson'));
 369  
 370          return $this->output->box(implode(" | \n", $links), 'addlinks');
 371      }
 372  
 373      /**
 374       * Return HTML to display add first page links
 375       * @param lesson $lesson
 376       * @return string
 377       */
 378      public function add_first_page_links(lesson $lesson) {
 379          global $CFG;
 380          $prevpageid = 0;
 381  
 382          $output = $this->output->heading(get_string("whatdofirst", "lesson"), 3);
 383          $links = array();
 384  
 385          $importquestionsurl = new moodle_url('/mod/lesson/import.php',array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
 386          $links[] = html_writer::link($importquestionsurl, get_string('importquestions', 'lesson'));
 387  
 388          $manager = lesson_page_type_manager::get($lesson);
 389          foreach ($manager->get_add_page_type_links($prevpageid) as $link) {
 390              $link['addurl']->param('firstpage', 1);
 391              $links[] = html_writer::link($link['addurl'], $link['name']);
 392          }
 393  
 394          $addquestionurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid, 'firstpage'=>1));
 395          $links[] = html_writer::link($addquestionurl, get_string('addaquestionpage', 'lesson'));
 396  
 397          return $this->output->box($output.'<p>'.implode('</p><p>', $links).'</p>', 'generalbox firstpageoptions');
 398      }
 399  
 400      /**
 401       * Returns HTML to display action links for a page
 402       *
 403       * @param lesson_page $page
 404       * @param bool $printmove
 405       * @param bool $printaddpage
 406       * @return string
 407       */
 408      public function page_action_links(lesson_page $page, $printmove, $printaddpage=false) {
 409          global $CFG;
 410  
 411          $actions = array();
 412  
 413          if ($printmove) {
 414              $url = new moodle_url('/mod/lesson/lesson.php',
 415                      array('id' => $this->page->cm->id, 'action' => 'move', 'pageid' => $page->id, 'sesskey' => sesskey()));
 416              $label = get_string('movepagenamed', 'lesson', format_string($page->title));
 417              $img = $this->output->pix_icon('t/move', $label);
 418              $actions[] = html_writer::link($url, $img, array('title' => $label));
 419          }
 420          $url = new moodle_url('/mod/lesson/editpage.php', array('id' => $this->page->cm->id, 'pageid' => $page->id, 'edit' => 1));
 421          $label = get_string('updatepagenamed', 'lesson', format_string($page->title));
 422          $img = $this->output->pix_icon('t/edit', $label);
 423          $actions[] = html_writer::link($url, $img, array('title' => $label));
 424  
 425          // Duplicate action.
 426          $url = new moodle_url('/mod/lesson/lesson.php', array('id' => $this->page->cm->id, 'pageid' => $page->id,
 427                  'action' => 'duplicate', 'sesskey' => sesskey()));
 428          $label = get_string('duplicatepagenamed', 'lesson', format_string($page->title));
 429          $img = $this->output->pix_icon('e/copy', $label, 'mod_lesson');
 430          $actions[] = html_writer::link($url, $img, array('title' => $label));
 431  
 432          $url = new moodle_url('/mod/lesson/view.php', array('id' => $this->page->cm->id, 'pageid' => $page->id));
 433          $label = get_string('previewpagenamed', 'lesson', format_string($page->title));
 434          $img = $this->output->pix_icon('t/preview', $label);
 435          $actions[] = html_writer::link($url, $img, array('title' => $label));
 436  
 437          $url = new moodle_url('/mod/lesson/lesson.php',
 438                  array('id' => $this->page->cm->id, 'action' => 'confirmdelete', 'pageid' => $page->id, 'sesskey' => sesskey()));
 439          $label = get_string('deletepagenamed', 'lesson', format_string($page->title));
 440          $img = $this->output->pix_icon('t/delete', $label);
 441          $actions[] = html_writer::link($url, $img, array('title' => $label));
 442  
 443          if ($printaddpage) {
 444              $options = array();
 445              $manager = lesson_page_type_manager::get($page->lesson);
 446              $links = $manager->get_add_page_type_links($page->id);
 447              foreach ($links as $link) {
 448                  $options[$link['type']] = $link['name'];
 449              }
 450              $options[0] = get_string('addaquestionpage', 'lesson');
 451  
 452              $addpageurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$this->page->cm->id, 'pageid'=>$page->id, 'sesskey'=>sesskey()));
 453              $addpageselect = new single_select($addpageurl, 'qtype', $options, null, array(''=>get_string('addanewpage', 'lesson').'...'), 'addpageafter'.$page->id);
 454              $addpageselector = $this->output->render($addpageselect);
 455          }
 456  
 457          if (isset($addpageselector)) {
 458              $actions[] = $addpageselector;
 459          }
 460  
 461          return implode(' ', $actions);
 462      }
 463  
 464      /**
 465       * Prints the on going message to the user.
 466       *
 467       * With custom grading On, displays points
 468       * earned out of total points possible thus far.
 469       * With custom grading Off, displays number of correct
 470       * answers out of total attempted.
 471       *
 472       * @param object $lesson The lesson that the user is taking.
 473       * @return void
 474       **/
 475  
 476       /**
 477        * Prints the on going message to the user.
 478        *
 479        * With custom grading On, displays points
 480        * earned out of total points possible thus far.
 481        * With custom grading Off, displays number of correct
 482        * answers out of total attempted.
 483        *
 484        * @param lesson $lesson
 485        * @return string
 486        */
 487      public function ongoing_score(lesson $lesson) {
 488          return $this->output->box($lesson->get_ongoing_score_message(), "ongoing center");
 489      }
 490  
 491      /**
 492       * Returns HTML to display a progress bar of progression through a lesson
 493       *
 494       * @param lesson $lesson
 495       * @param int $progress optional, if empty it will be calculated
 496       * @return string
 497       */
 498      public function progress_bar(lesson $lesson, $progress = null) {
 499          $context = context_module::instance($this->page->cm->id);
 500  
 501          // lesson setting to turn progress bar on or off
 502          if (!$lesson->progressbar) {
 503              return '';
 504          }
 505  
 506          // catch teachers
 507          if (has_capability('mod/lesson:manage', $context)) {
 508              return $this->output->notification(get_string('progressbarteacherwarning2', 'lesson'));
 509          }
 510  
 511          if ($progress === null) {
 512              $progress = $lesson->calculate_progress();
 513          }
 514  
 515          $content = html_writer::start_tag('div');
 516          $content .= html_writer::start_tag('div', array('class' => 'progress'));
 517          $content .= html_writer::start_tag('div', array('class' => 'progress-bar bar', 'role' => 'progressbar',
 518              'style' => 'width: ' . $progress .'%', 'aria-valuenow' => $progress, 'aria-valuemin' => 0, 'aria-valuemax' => 100));
 519          $content .= $progress . "%";
 520          $content .= html_writer::end_tag('div');
 521          $content .= html_writer::end_tag('div');
 522          $printprogress = html_writer::tag('div', get_string('progresscompleted', 'lesson', $progress) . $content);
 523          return $this->output->box($printprogress, 'progress_bar');
 524      }
 525  
 526      /**
 527       * Returns HTML to show the start of a slideshow
 528       * @param lesson $lesson
 529       */
 530      public function slideshow_start(lesson $lesson) {
 531          $attributes = array();
 532          $attributes['class'] = 'slideshow';
 533          $attributes['style'] = 'background-color:'.$lesson->properties()->bgcolor.';height:'.
 534                  $lesson->properties()->height.'px;width:'.$lesson->properties()->width.'px;';
 535          $output = html_writer::start_tag('div', $attributes);
 536          return $output;
 537      }
 538      /**
 539       * Returns HTML to show the end of a slideshow
 540       */
 541      public function slideshow_end() {
 542          $output = html_writer::end_tag('div');
 543          return $output;
 544      }
 545      /**
 546       * Returns a P tag containing contents
 547       * @param string $contents
 548       * @param string $class
 549       */
 550      public function paragraph($contents, $class='') {
 551          $attributes = array();
 552          if ($class !== '') {
 553              $attributes['class'] = $class;
 554          }
 555          $output = html_writer::tag('p', $contents, $attributes);
 556          return $output;
 557      }
 558  
 559      /**
 560       * Returns the HTML for displaying the end of lesson page.
 561       *
 562       * @param  lesson $lesson lesson instance
 563       * @param  stdclass $data lesson data to be rendered
 564       * @return string         HTML contents
 565       */
 566      public function display_eol_page(lesson $lesson, $data) {
 567  
 568          $output = '';
 569          $canmanage = $lesson->can_manage();
 570          $course = $lesson->courserecord;
 571  
 572          if ($lesson->custom && !$canmanage && (($data->gradeinfo->nquestions < $lesson->minquestions))) {
 573              $output .= $this->box_start('generalbox boxaligncenter');
 574          }
 575  
 576          if ($data->gradelesson) {
 577              // We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
 578              $output .= $this->heading(get_string("congratulations", "lesson"), 3);
 579              $output .= $this->box_start('generalbox boxaligncenter');
 580          }
 581  
 582          if ($data->notenoughtimespent !== false) {
 583              $output .= $this->paragraph(get_string("notenoughtimespent", "lesson", $data->notenoughtimespent), 'center');
 584          }
 585  
 586          if ($data->numberofpagesviewed !== false) {
 587              $output .= $this->paragraph(get_string("numberofpagesviewed", "lesson", $data->numberofpagesviewed), 'center');
 588          }
 589          if ($data->youshouldview !== false) {
 590              $output .= $this->paragraph(get_string("youshouldview", "lesson", $data->youshouldview), 'center');
 591          }
 592          if ($data->numberofcorrectanswers !== false) {
 593              $output .= $this->paragraph(get_string("numberofcorrectanswers", "lesson", $data->numberofcorrectanswers), 'center');
 594          }
 595  
 596          if ($data->displayscorewithessays !== false) {
 597              $output .= $this->box(get_string("displayscorewithessays", "lesson", $data->displayscorewithessays), 'center');
 598          } else if ($data->displayscorewithoutessays !== false) {
 599              $output .= $this->box(get_string("displayscorewithoutessays", "lesson", $data->displayscorewithoutessays), 'center');
 600          }
 601  
 602          if ($data->yourcurrentgradeisoutof !== false) {
 603              $output .= $this->paragraph(get_string("yourcurrentgradeisoutof", "lesson", $data->yourcurrentgradeisoutof), 'center');
 604          }
 605          if ($data->eolstudentoutoftimenoanswers !== false) {
 606              $output .= $this->paragraph(get_string("eolstudentoutoftimenoanswers", "lesson"));
 607          }
 608          if ($data->welldone !== false) {
 609              $output .= $this->paragraph(get_string("welldone", "lesson"));
 610          }
 611  
 612          if ($data->progresscompleted !== false) {
 613              $output .= $this->progress_bar($lesson, $data->progresscompleted);
 614          }
 615  
 616          if ($data->displayofgrade !== false) {
 617              $output .= $this->paragraph(get_string("displayofgrade", "lesson"), 'center');
 618          }
 619  
 620          $output .= $this->box_end(); // End of Lesson button to Continue.
 621  
 622          if ($data->reviewlesson !== false) {
 623              $output .= html_writer::link($data->reviewlesson, get_string('reviewlesson', 'lesson'), array('class' => 'centerpadded lessonbutton standardbutton p-r-1'));
 624          }
 625          if ($data->modattemptsnoteacher !== false) {
 626              $output .= $this->paragraph(get_string("modattemptsnoteacher", "lesson"), 'centerpadded');
 627          }
 628  
 629          if ($data->activitylink !== false) {
 630              $output .= $data->activitylink;
 631          }
 632  
 633          $url = new moodle_url('/course/view.php', array('id' => $course->id));
 634          $output .= html_writer::link($url, get_string('returnto', 'lesson', format_string($course->fullname, true)),
 635                  array('class' => 'centerpadded lessonbutton standardbutton p-r-1'));
 636  
 637          if (has_capability('gradereport/user:view', context_course::instance($course->id))
 638                  && $course->showgrades && $lesson->grade != 0 && !$lesson->practice) {
 639              $url = new moodle_url('/grade/index.php', array('id' => $course->id));
 640              $output .= html_writer::link($url, get_string('viewgrades', 'lesson'),
 641                  array('class' => 'centerpadded lessonbutton standardbutton p-r-1'));
 642          }
 643          return $output;
 644      }
 645  }