Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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   * Displays the lesson statistics.
      20   *
      21   * @package mod_lesson
      22   * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
      23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
      24   **/
      25  
      26  require_once('../../config.php');
      27  require_once($CFG->dirroot.'/mod/lesson/locallib.php');
      28  
      29  $id     = required_param('id', PARAM_INT);    // Course Module ID
      30  $pageid = optional_param('pageid', null, PARAM_INT);    // Lesson Page ID
      31  $action = optional_param('action', 'reportoverview', PARAM_ALPHA);  // action to take
      32  $nothingtodisplay = false;
      33  
      34  $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
      35  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
      36  $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
      37  
      38  require_login($course, false, $cm);
      39  
      40  $context = context_module::instance($cm->id);
      41  require_capability('mod/lesson:manage', $context);
      42  
      43  $ufields = user_picture::fields('u'); // These fields are enough
      44  $params = array("lessonid" => $lesson->id);
      45  list($sort, $sortparams) = users_order_by_sql('u');
      46  $params = array_merge($params, $sortparams);
      47  // TODO: Improve this. Fetching all students always is crazy!
      48  if (!empty($cm->groupingid)) {
      49      $params["groupingid"] = $cm->groupingid;
      50      $sql = "SELECT DISTINCT $ufields
      51                  FROM {lesson_attempts} a
      52                      INNER JOIN {user} u ON u.id = a.userid
      53                      INNER JOIN {groups_members} gm ON gm.userid = u.id
      54                      INNER JOIN {groupings_groups} gg ON gm.groupid = gg.groupid
      55                  WHERE a.lessonid = :lessonid AND
      56                        gg.groupingid = :groupingid
      57                  ORDER BY $sort";
      58  } else {
      59      $sql = "SELECT DISTINCT $ufields
      60              FROM {user} u,
      61                   {lesson_attempts} a
      62              WHERE a.lessonid = :lessonid and
      63                    u.id = a.userid
      64              ORDER BY $sort";
      65  }
      66  
      67  $students = $DB->get_recordset_sql($sql, $params);
      68  if (!$students->valid()) {
      69      $nothingtodisplay = true;
      70  }
      71  
      72  $url = new moodle_url('/mod/lesson/report.php', array('id'=>$id));
      73  $url->param('action', $action);
      74  if ($pageid !== null) {
      75      $url->param('pageid', $pageid);
      76  }
      77  $PAGE->set_url($url);
      78  if ($action == 'reportoverview') {
      79      $PAGE->navbar->add(get_string('reports', 'lesson'));
      80      $PAGE->navbar->add(get_string('overview', 'lesson'));
      81  }
      82  
      83  $lessonoutput = $PAGE->get_renderer('mod_lesson');
      84  
      85  $attempts = $DB->get_recordset('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen');
      86  if (!$attempts->valid()) {
      87      $nothingtodisplay = true;
      88  }
      89  
      90  if (! $grades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id), 'completed')) {
      91      $grades = array();
      92  }
      93  
      94  if (! $times = $DB->get_records('lesson_timer', array('lessonid' => $lesson->id), 'starttime')) {
      95      $times = array();
      96  }
      97  
      98  if ($nothingtodisplay) {
      99      echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('nolessonattempts', 'lesson'));
     100      echo $OUTPUT->notification(get_string('nolessonattempts', 'lesson'));
     101      echo $OUTPUT->footer();
     102      exit();
     103  }
     104  
     105  if ($action === 'delete') {
     106      /// Process any form data before fetching attempts, grades and times
     107      if (has_capability('mod/lesson:edit', $context) and $form = data_submitted() and confirm_sesskey()) {
     108      /// Cycle through array of userids with nested arrays of tries
     109          if (!empty($form->attempts)) {
     110              foreach ($form->attempts as $userid => $tries) {
     111                  // Modifier IS VERY IMPORTANT!  What does it do?
     112                  //      Well, it is for when you delete multiple attempts for the same user.
     113                  //      If you delete try 1 and 3 for a user, then after deleting try 1, try 3 then
     114                  //      becomes try 2 (because try 1 is gone and all tries after try 1 get decremented).
     115                  //      So, the modifier makes sure that the submitted try refers to the current try in the
     116                  //      database - hope this all makes sense :)
     117                  $modifier = 0;
     118  
     119                  foreach ($tries as $try => $junk) {
     120                      $try -= $modifier;
     121  
     122                  /// Clean up the timer table by removing using the order - this is silly, it should be linked to specific attempt (skodak)
     123                      $params = array ("userid" => $userid, "lessonid" => $lesson->id);
     124                      $timers = $DB->get_records_sql("SELECT id FROM {lesson_timer}
     125                                                       WHERE userid = :userid AND lessonid = :lessonid
     126                                                    ORDER BY starttime", $params, $try, 1);
     127                      if ($timers) {
     128                          $timer = reset($timers);
     129                          $DB->delete_records('lesson_timer', array('id' => $timer->id));
     130                      }
     131  
     132                  /// Remove the grade from the grades and high_scores tables - this is silly, it should be linked to specific attempt (skodak)
     133                      $grades = $DB->get_records_sql("SELECT id FROM {lesson_grades}
     134                                                       WHERE userid = :userid AND lessonid = :lessonid
     135                                                    ORDER BY completed", $params, $try, 1);
     136  
     137                      if ($grades) {
     138                          $grade = reset($grades);
     139                          $DB->delete_records('lesson_grades', array('id' => $grade->id));
     140                          $DB->delete_records('lesson_high_scores', array('gradeid' => $grade->id, 'lessonid' => $lesson->id, 'userid' => $userid));
     141                      }
     142  
     143                  /// Remove attempts and update the retry number
     144                      $DB->delete_records('lesson_attempts', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try));
     145                      $DB->execute("UPDATE {lesson_attempts} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
     146  
     147                  /// Remove seen branches and update the retry number
     148                      $DB->delete_records('lesson_branch', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try));
     149                      $DB->execute("UPDATE {lesson_branch} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
     150  
     151                  /// update central gradebook
     152                      lesson_update_grades($lesson, $userid);
     153  
     154                      $modifier++;
     155                  }
     156              }
     157          }
     158      }
     159      redirect(new moodle_url($PAGE->url, array('action'=>'reportoverview')));
     160  
     161  } else if ($action === 'reportoverview') {
     162      /**************************************************************************
     163      this action is for default view and overview view
     164      **************************************************************************/
     165      echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('overview', 'lesson'));
     166  
     167      $course_context = context_course::instance($course->id);
     168      if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
     169          $seeallgradeslink = new moodle_url('/grade/report/grader/index.php', array('id'=>$course->id));
     170          $seeallgradeslink = html_writer::link($seeallgradeslink, get_string('seeallcoursegrades', 'grades'));
     171          echo $OUTPUT->box($seeallgradeslink, 'allcoursegrades');
     172      }
     173  
     174      $studentdata = array();
     175  
     176      // build an array for output
     177      foreach ($attempts as $attempt) {
     178          // if the user is not in the array or if the retry number is not in the sub array, add the data for that try.
     179          if (!array_key_exists($attempt->userid, $studentdata) || !array_key_exists($attempt->retry, $studentdata[$attempt->userid])) {
     180              // restore/setup defaults
     181              $n = 0;
     182              $timestart = 0;
     183              $timeend = 0;
     184              $usergrade = null;
     185  
     186              // search for the grade record for this try. if not there, the nulls defined above will be used.
     187              foreach($grades as $grade) {
     188                  // check to see if the grade matches the correct user
     189                  if ($grade->userid == $attempt->userid) {
     190                      // see if n is = to the retry
     191                      if ($n == $attempt->retry) {
     192                          // get grade info
     193                          $usergrade = round($grade->grade, 2); // round it here so we only have to do it once
     194                          break;
     195                      }
     196                      $n++; // if not equal, then increment n
     197                  }
     198              }
     199              $n = 0;
     200              // search for the time record for this try. if not there, the nulls defined above will be used.
     201              foreach($times as $time) {
     202                  // check to see if the grade matches the correct user
     203                  if ($time->userid == $attempt->userid) {
     204                      // see if n is = to the retry
     205                      if ($n == $attempt->retry) {
     206                          // get grade info
     207                          $timeend = $time->lessontime;
     208                          $timestart = $time->starttime;
     209                          break;
     210                      }
     211                      $n++; // if not equal, then increment n
     212                  }
     213              }
     214  
     215              // build up the array.
     216              // this array represents each student and all of their tries at the lesson
     217              $studentdata[$attempt->userid][$attempt->retry] = array( "timestart" => $timestart,
     218                                                                      "timeend" => $timeend,
     219                                                                      "grade" => $usergrade,
     220                                                                      "try" => $attempt->retry,
     221                                                                      "userid" => $attempt->userid);
     222          }
     223      }
     224      $attempts->close();
     225      // set all the stats variables
     226      $numofattempts = 0;
     227      $avescore      = 0;
     228      $avetime       = 0;
     229      $highscore     = null;
     230      $lowscore      = null;
     231      $hightime      = null;
     232      $lowtime       = null;
     233  
     234      $table = new html_table();
     235  
     236      // set up the table object
     237      $table->head = array(get_string('name'), get_string('attempts', 'lesson'), get_string('highscore', 'lesson'));
     238      $table->align = array('center', 'left', 'left');
     239      $table->wrap = array('nowrap', 'nowrap', 'nowrap');
     240      $table->attributes['class'] = 'standardtable generaltable';
     241      $table->size = array(null, '70%', null);
     242  
     243      // print out the $studentdata array
     244      // going through each student that has attempted the lesson, so, each student should have something to be displayed
     245      foreach ($students as $student) {
     246          // check to see if the student has attempts to print out
     247          if (array_key_exists($student->id, $studentdata)) {
     248              // set/reset some variables
     249              $attempts = array();
     250              // gather the data for each user attempt
     251              $bestgrade = 0;
     252              $bestgradefound = false;
     253              // $tries holds all the tries/retries a student has done
     254              $tries = $studentdata[$student->id];
     255              $studentname = "{$student->lastname},&nbsp;$student->firstname";
     256              foreach ($tries as $try) {
     257              // start to build up the checkbox and link
     258                  if (has_capability('mod/lesson:edit', $context)) {
     259                      $temp = '<input type="checkbox" id="attempts" name="attempts['.$try['userid'].']['.$try['try'].']" /> ';
     260                  } else {
     261                      $temp = '';
     262                  }
     263  
     264                  $temp .= "<a href=\"report.php?id=$cm->id&amp;action=reportdetail&amp;userid=".$try['userid'].'&amp;try='.$try['try'].'">';
     265                  if ($try["grade"] !== null) { // if null then not done yet
     266                      // this is what the link does when the user has completed the try
     267                      $timetotake = $try["timeend"] - $try["timestart"];
     268  
     269                      $temp .= $try["grade"]."%";
     270                      $bestgradefound = true;
     271                      if ($try["grade"] > $bestgrade) {
     272                          $bestgrade = $try["grade"];
     273                      }
     274                      $temp .= "&nbsp;".userdate($try["timestart"]);
     275                      $temp .= ",&nbsp;(".format_time($timetotake).")</a>";
     276                  } else {
     277                      // this is what the link does/looks like when the user has not completed the try
     278                      $temp .= get_string("notcompleted", "lesson");
     279                      $temp .= "&nbsp;".userdate($try["timestart"])."</a>";
     280                      $timetotake = null;
     281                  }
     282                  // build up the attempts array
     283                  $attempts[] = $temp;
     284  
     285                  // run these lines for the stats only if the user finnished the lesson
     286                  if ($try["grade"] !== null) {
     287                      $numofattempts++;
     288                      $avescore += $try["grade"];
     289                      $avetime += $timetotake;
     290                      if ($try["grade"] > $highscore || $highscore === null) {
     291                          $highscore = $try["grade"];
     292                      }
     293                      if ($try["grade"] < $lowscore || $lowscore === null) {
     294                          $lowscore = $try["grade"];
     295                      }
     296                      if ($timetotake > $hightime || $hightime == null) {
     297                          $hightime = $timetotake;
     298                      }
     299                      if ($timetotake < $lowtime || $lowtime == null) {
     300                          $lowtime = $timetotake;
     301                      }
     302                  }
     303              }
     304              // get line breaks in after each attempt
     305              $attempts = implode("<br />\n", $attempts);
     306              // add it to the table data[] object
     307              $table->data[] = array($studentname, $attempts, $bestgrade."%");
     308          }
     309      }
     310      $students->close();
     311      // print it all out !
     312      if (has_capability('mod/lesson:edit', $context)) {
     313          echo  "<form id=\"theform\" method=\"post\" action=\"report.php\">\n
     314                 <input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n
     315                 <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
     316      }
     317      echo html_writer::table($table);
     318      if (has_capability('mod/lesson:edit', $context)) {
     319          $checklinks  = '<a href="javascript: checkall();">'.get_string('selectall').'</a> / ';
     320          $checklinks .= '<a href="javascript: checknone();">'.get_string('deselectall').'</a>';
     321          $checklinks .= html_writer::label('action', 'menuaction', false, array('class' => 'accesshide'));
     322          $checklinks .= html_writer::select(array('delete' => get_string('deleteselected')), 'action', 0, array(''=>'choosedots'), array('id'=>'actionid', 'class' => 'autosubmit'));
     323          $PAGE->requires->yui_module('moodle-core-formautosubmit',
     324              'M.core.init_formautosubmit',
     325              array(array('selectid' => 'actionid', 'nothing' => false))
     326          );
     327          echo $OUTPUT->box($checklinks, 'center');
     328          echo '</form>';
     329      }
     330  
     331      // some stat calculations
     332      if ($numofattempts == 0) {
     333          $avescore = get_string("notcompleted", "lesson");
     334      } else {
     335          $avescore = format_float($avescore/$numofattempts, 2);
     336      }
     337      if ($avetime == null) {
     338          $avetime = get_string("notcompleted", "lesson");
     339      } else {
     340          $avetime = format_float($avetime/$numofattempts, 0);
     341          $avetime = format_time($avetime);
     342      }
     343      if ($hightime == null) {
     344          $hightime = get_string("notcompleted", "lesson");
     345      } else {
     346          $hightime = format_time($hightime);
     347      }
     348      if ($lowtime == null) {
     349          $lowtime = get_string("notcompleted", "lesson");
     350      } else {
     351          $lowtime = format_time($lowtime);
     352      }
     353      if ($highscore === null) {
     354          $highscore = get_string("notcompleted", "lesson");
     355      }
     356      if ($lowscore === null) {
     357          $lowscore = get_string("notcompleted", "lesson");
     358      }
     359  
     360      // output the stats
     361      echo $OUTPUT->heading(get_string('lessonstats', 'lesson'), 3);
     362      $stattable = new html_table();
     363      $stattable->head = array(get_string('averagescore', 'lesson'), get_string('averagetime', 'lesson'),
     364                              get_string('highscore', 'lesson'), get_string('lowscore', 'lesson'),
     365                              get_string('hightime', 'lesson'), get_string('lowtime', 'lesson'));
     366      $stattable->align = array('center', 'center', 'center', 'center', 'center', 'center');
     367      $stattable->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
     368      $stattable->attributes['class'] = 'standardtable generaltable';
     369  
     370      if (is_numeric($highscore)) {
     371          $highscore .= '%';
     372      }
     373      if (is_numeric($lowscore)) {
     374          $lowscore .= '%';
     375      }
     376      $stattable->data[] = array($avescore.'%', $avetime, $highscore, $lowscore, $hightime, $lowtime);
     377  
     378      echo html_writer::table($stattable);
     379  } else if ($action === 'reportdetail') {
     380      /**************************************************************************
     381      this action is for a student detailed view and for the general detailed view
     382  
     383      General flow of this section of the code
     384      1.  Generate a object which holds values for the statistics for each question/answer
     385      2.  Cycle through all the pages to create a object.  Foreach page, see if the student actually answered
     386          the page.  Then process the page appropriatly.  Display all info about the question,
     387          Highlight correct answers, show how the user answered the question, and display statistics
     388          about each page
     389      3.  Print out info about the try (if needed)
     390      4.  Print out the object which contains all the try info
     391  
     392  **************************************************************************/
     393      echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('detailedstats', 'lesson'));
     394  
     395      $course_context = context_course::instance($course->id);
     396      if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
     397          $seeallgradeslink = new moodle_url('/grade/report/grader/index.php', array('id'=>$course->id));
     398          $seeallgradeslink = html_writer::link($seeallgradeslink, get_string('seeallcoursegrades', 'grades'));
     399          echo $OUTPUT->box($seeallgradeslink, 'allcoursegrades');
     400      }
     401  
     402      $formattextdefoptions = new stdClass;
     403      $formattextdefoptions->para = false;  //I'll use it widely in this page
     404      $formattextdefoptions->overflowdiv = true;
     405  
     406      $userid = optional_param('userid', null, PARAM_INT); // if empty, then will display the general detailed view
     407      $try    = optional_param('try', null, PARAM_INT);
     408  
     409      $lessonpages = $lesson->load_all_pages();
     410      foreach ($lessonpages as $lessonpage) {
     411          if ($lessonpage->prevpageid == 0) {
     412              $pageid = $lessonpage->id;
     413          }
     414      }
     415  
     416      // now gather the stats into an object
     417      $firstpageid = $pageid;
     418      $pagestats = array();
     419      while ($pageid != 0) { // EOL
     420          $page = $lessonpages[$pageid];
     421          $params = array ("lessonid" => $lesson->id, "pageid" => $page->id);
     422          if ($allanswers = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND pageid = :pageid", $params, "timeseen")) {
     423              // get them ready for processing
     424              $orderedanswers = array();
     425              foreach ($allanswers as $singleanswer) {
     426                  // ordering them like this, will help to find the single attempt record that we want to keep.
     427                  $orderedanswers[$singleanswer->userid][$singleanswer->retry][] = $singleanswer;
     428              }
     429              // this is foreach user and for each try for that user, keep one attempt record
     430              foreach ($orderedanswers as $orderedanswer) {
     431                  foreach($orderedanswer as $tries) {
     432                      $page->stats($pagestats, $tries);
     433                  }
     434              }
     435          } else {
     436              // no one answered yet...
     437          }
     438          //unset($orderedanswers);  initialized above now
     439          $pageid = $page->nextpageid;
     440      }
     441  
     442      $manager = lesson_page_type_manager::get($lesson);
     443      $qtypes = $manager->get_page_type_strings();
     444  
     445      $answerpages = array();
     446      $answerpage = "";
     447      $pageid = $firstpageid;
     448      // cycle through all the pages
     449      //  foreach page, add to the $answerpages[] array all the data that is needed
     450      //  from the question, the users attempt, and the statistics
     451      // grayout pages that the user did not answer and Branch, end of branch, cluster
     452      // and end of cluster pages
     453      while ($pageid != 0) { // EOL
     454          $page = $lessonpages[$pageid];
     455          $answerpage = new stdClass;
     456          $data ='';
     457  
     458          $answerdata = new stdClass;
     459          // Set some defaults for the answer data.
     460          $answerdata->score = null;
     461          $answerdata->response = null;
     462          $answerdata->responseformat = FORMAT_PLAIN;
     463  
     464          $answerpage->title = format_string($page->title);
     465  
     466          $options = new stdClass;
     467          $options->noclean = true;
     468          $options->overflowdiv = true;
     469          $options->context = $context;
     470          $answerpage->contents = format_text($page->contents, $page->contentsformat, $options);
     471  
     472          $answerpage->qtype = $qtypes[$page->qtype].$page->option_description_string();
     473          $answerpage->grayout = $page->grayout;
     474          $answerpage->context = $context;
     475  
     476          if (empty($userid)) {
     477              // there is no userid, so set these vars and display stats.
     478              $answerpage->grayout = 0;
     479              $useranswer = null;
     480          } elseif ($useranswers = $DB->get_records("lesson_attempts",array("lessonid"=>$lesson->id, "userid"=>$userid, "retry"=>$try,"pageid"=>$page->id), "timeseen")) {
     481              // get the user's answer for this page
     482              // need to find the right one
     483              $i = 0;
     484              foreach ($useranswers as $userattempt) {
     485                  $useranswer = $userattempt;
     486                  $i++;
     487                  if ($lesson->maxattempts == $i) {
     488                      break; // reached maxattempts, break out
     489                  }
     490              }
     491          } else {
     492              // user did not answer this page, gray it out and set some nulls
     493              $answerpage->grayout = 1;
     494              $useranswer = null;
     495          }
     496          $i = 0;
     497          $n = 0;
     498          $answerpages[] = $page->report_answers(clone($answerpage), clone($answerdata), $useranswer, $pagestats, $i, $n);
     499          $pageid = $page->nextpageid;
     500      }
     501  
     502      /// actually start printing something
     503      $table = new html_table();
     504      $table->wrap = array();
     505      $table->width = "60%";
     506      if (!empty($userid)) {
     507          // if looking at a students try, print out some basic stats at the top
     508  
     509              // print out users name
     510              //$headingobject->lastname = $students[$userid]->lastname;
     511              //$headingobject->firstname = $students[$userid]->firstname;
     512              //$headingobject->attempt = $try + 1;
     513              //print_heading(get_string("studentattemptlesson", "lesson", $headingobject));
     514          echo $OUTPUT->heading(get_string('attempt', 'lesson', $try+1), 3);
     515  
     516          $table->head = array();
     517          $table->align = array('right', 'left');
     518          $table->attributes['class'] = 'compacttable generaltable';
     519  
     520          $params = array("lessonid"=>$lesson->id, "userid"=>$userid);
     521          if (!$grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid and userid = :userid", $params, "completed", "*", $try, 1)) {
     522              $grade = -1;
     523              $completed = -1;
     524          } else {
     525              $grade = current($grades);
     526              $completed = $grade->completed;
     527              $grade = round($grade->grade, 2);
     528          }
     529          if (!$times = $DB->get_records_select("lesson_timer", "lessonid = :lessonid and userid = :userid", $params, "starttime", "*", $try, 1)) {
     530              $timetotake = -1;
     531          } else {
     532              $timetotake = current($times);
     533              $timetotake = $timetotake->lessontime - $timetotake->starttime;
     534          }
     535  
     536          if ($timetotake == -1 || $completed == -1 || $grade == -1) {
     537              $table->align = array("center");
     538  
     539              $table->data[] = array(get_string("notcompleted", "lesson"));
     540          } else {
     541              $user = $DB->get_record('user', array('id' => $userid));
     542  
     543              $gradeinfo = lesson_grade($lesson, $try, $user->id);
     544  
     545              $table->data[] = array(get_string('name').':', $OUTPUT->user_picture($user, array('courseid'=>$course->id)).fullname($user, true));
     546              $table->data[] = array(get_string("timetaken", "lesson").":", format_time($timetotake));
     547              $table->data[] = array(get_string("completed", "lesson").":", userdate($completed));
     548              $table->data[] = array(get_string('rawgrade', 'lesson').':', $gradeinfo->earned.'/'.$gradeinfo->total);
     549              $table->data[] = array(get_string("grade", "lesson").":", $grade."%");
     550          }
     551          echo html_writer::table($table);
     552  
     553          // Don't want this class for later tables
     554          $table->attributes['class'] = '';
     555      }
     556  
     557  
     558      $table->align = array('left', 'left');
     559      $table->size = array('70%', null);
     560      $table->attributes['class'] = 'compacttable generaltable';
     561  
     562      foreach ($answerpages as $page) {
     563          unset($table->data);
     564          if ($page->grayout) { // set the color of text
     565              $fontstart = "<span class=\"dimmed\">";
     566              $fontend = "</font>";
     567              $fontstart2 = $fontstart;
     568              $fontend2 = $fontend;
     569          } else {
     570              $fontstart = "";
     571              $fontend = "";
     572              $fontstart2 = "";
     573              $fontend2 = "";
     574          }
     575  
     576          $table->head = array($fontstart2.$page->qtype.": ".format_string($page->title).$fontend2, $fontstart2.get_string("classstats", "lesson").$fontend2);
     577          $table->data[] = array($fontstart.get_string("question", "lesson").": <br />".$fontend.$fontstart2.$page->contents.$fontend2, " ");
     578          $table->data[] = array($fontstart.get_string("answer", "lesson").":".$fontend, ' ');
     579          // apply the font to each answer
     580          if (!empty($page->answerdata)) {
     581              foreach ($page->answerdata->answers as $answer){
     582                  $modified = array();
     583                  foreach ($answer as $single) {
     584                      // need to apply a font to each one
     585                      $modified[] = $fontstart2.$single.$fontend2;
     586                  }
     587                  $table->data[] = $modified;
     588              }
     589              if (isset($page->answerdata->response)) {
     590                  $table->data[] = array($fontstart.get_string("response", "lesson").": <br />".$fontend
     591                          .$fontstart2.$page->answerdata->response.$fontend2, " ");
     592              }
     593              $table->data[] = array($page->answerdata->score, " ");
     594          } else {
     595              $table->data[] = array(get_string('didnotanswerquestion', 'lesson'), " ");
     596          }
     597          echo html_writer::start_tag('div', array('class' => 'no-overflow'));
     598          echo html_writer::table($table);
     599          echo html_writer::end_tag('div');
     600      }
     601  } else {
     602      print_error('unknowaction');
     603  }
     604  
     605  /// Finish the page
     606  echo $OUTPUT->footer();
    

    Search This Site: