/**
  * Gets the data for the table
  *
  * @return array $data The array of data to show
  */
 protected function get_data()
 {
     global $DB;
     $data = array();
     $attempts = $this->session->getall_attempts(true);
     $userids = array();
     foreach ($attempts as $attempt) {
         $userids[] = $attempt->userid;
     }
     // get user records to get the full name
     if (!empty($userids)) {
         list($useridsql, $params) = $DB->get_in_or_equal($userids);
         $sql = 'SELECT * FROM {user} WHERE id ' . $useridsql;
         $userrecs = $DB->get_records_sql($sql, $params);
     } else {
         $userrecs = array();
     }
     foreach ($attempts as $attempt) {
         /** @var \mod_activequiz\activequiz_attempt $attempt */
         $ditem = new \stdClass();
         $ditem->attemptid = $attempt->id;
         $ditem->sessionid = $attempt->sessionid;
         if ($this->rtq->group_mode()) {
             $ditem->userid = $attempt->userid;
             $ditem->takenby = fullname($userrecs[$attempt->userid]);
             $ditem->groupname = $this->rtq->get_groupmanager()->get_group_name($attempt->forgroupid);
         } else {
             $ditem->userid = $attempt->userid;
             $userrec = $userrecs[$attempt->userid];
             $ditem->username = fullname($userrec);
         }
         $ditem->attemptno = $attempt->attemptnum;
         $ditem->preview = $attempt->preview;
         $ditem->status = $attempt->getStatus();
         $ditem->timestart = $attempt->timestart;
         $ditem->timefinish = $attempt->timefinish;
         $ditem->timemodified = $attempt->timemodified;
         $ditem->grade = number_format($this->rtq->get_grader()->calculate_attempt_grade($attempt), 2);
         $ditem->totalgrade = $this->rtq->getRTQ()->scale;
         $data[$attempt->id] = $ditem;
     }
     return $data;
 }
Пример #2
0
 /**
  * Get the session's grade
  *
  * For now this will always be the last attempt for the user
  *
  * @param \mod_activequiz\activequiz_session $session
  * @param int                                $userid The userid to get the grade for
  * @return array($forgroupid, $number)
  */
 protected function get_session_grade($session, $userid)
 {
     // get all attempts for the specified userid that are closed and are not previews
     // also skip checking for groups as grading handles groups separately
     $attempts = $session->getall_attempts(false, 'closed', $userid, true);
     $attemptno = count($attempts);
     if ($attemptno === 0) {
         return array(0, 0);
     }
     // get the last attempt for the user
     $attemptgraded = $this->get_last_attempt($attempts);
     return array($attemptgraded->forgroupid, $this->calculate_attempt_grade($attemptgraded));
 }