Exemplo n.º 1
0
 /**
  * Gets the data for the table
  *
  * @return array $data The array of data to show
  */
 protected function get_data()
 {
     global $DB, $USER;
     $data = array();
     $sessions = $this->rtq->get_sessions();
     foreach ($sessions as $session) {
         /** @var \mod_activequiz\activequiz_session $session */
         $sessionattempts = $session->getall_attempts(false, 'closed', $USER->id);
         foreach ($sessionattempts as $sattempt) {
             $ditem = new \stdClass();
             $ditem->attemptid = $sattempt->id;
             $ditem->sessionid = $sattempt->sessionid;
             $ditem->sessionname = $session->get_session()->name;
             if ($this->rtq->group_mode()) {
                 $ditem->group = $this->rtq->get_groupmanager()->get_group_name($sattempt->forgroupid);
             }
             $ditem->timestart = $sattempt->timestart;
             $ditem->timefinish = $sattempt->timefinish;
             $ditem->grade = number_format($this->rtq->get_grader()->calculate_attempt_grade($sattempt), 2);
             $ditem->totalgrade = $this->rtq->getRTQ()->scale;
             $data[$sattempt->id] = $ditem;
         }
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * Renders a response for a specific question and attempt
  *
  * @param \mod_activequiz\activequiz_attempt $attempt
  *
  * @return string HTML fragment for the response
  */
 public function render_response($attempt)
 {
     global $DB;
     $response = html_writer::start_div('response');
     // check if group mode, if so, give the group name the attempt is for
     if ($this->rtq->group_mode()) {
         $name = $this->rtq->get_groupmanager()->get_group_name($attempt->forgroupid);
     } else {
         $user = $DB->get_record('user', array('id' => $attempt->userid));
         $name = fullname($user);
     }
     $response .= html_writer::tag('h3', $name, array('class' => 'responsename'));
     $response .= html_writer::div($attempt->responsesummary, 'responsesummary');
     $response .= html_writer::end_div();
     return $response;
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Figures out the grades for group members if the quiz was taken in group mode
  *
  * IMPORTANT: IF A USER IS IN MORE THAN 1 GROUP FOR THE SPECIFIED GROUPING, THIS FUNCTION
  * WILL TAKE THE HIGHER OF THE 2 GRADES THAT WILL BE GIVEN TO THEM
  *
  * @param array  $sessionsgrades Array of session grades being built for user
  * @param int    $forgroupid
  * @param number $grade
  * @param int    $uid
  * @param int    $sessionid
  */
 protected function calculate_group_grades(&$sessionsgrades, $forgroupid, $grade, $uid, $sessionid)
 {
     if (empty($forgroupid)) {
         // just add the grade for the userid to the sessiongrades
         $sessionsgrades[$uid][$sessionid] = $grade;
         return;
     }
     // get the group attendance if we have it
     if ($this->rtq->getRTQ()->groupattendance == 1) {
         $groupattendance = $this->rtq->get_groupmanager()->get_attendance(null, null, null, $forgroupid);
         foreach ($groupattendance as $gattendanceuser) {
             $this->add_group_grade($sessionsgrades, $gattendanceuser->userid, $sessionid, $grade);
         }
     } else {
         $groupusers = $this->rtq->get_groupmanager()->get_group_members($forgroupid);
         foreach ($groupusers as $guser) {
             $this->add_group_grade($sessionsgrades, $guser->id, $sessionid, $grade);
         }
     }
 }
 /**
  * Gets the data for the table
  *
  * @return array $data The array of data to show
  */
 protected function get_data()
 {
     global $DB, $CFG;
     $data = array();
     $grades = \mod_activequiz\utils\grade::get_user_grade($this->rtq->getRTQ());
     $userids = array();
     foreach ($grades as $grade) {
         $userids[] = $grade->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 ($grades as $grade) {
         // check to see if the grade is for a gradebook role.  if not then their grade
         // shouldn't show up here
         $add = false;
         if ($roles = get_user_roles($this->rtq->getContext(), $grade->userid)) {
             $gradebookroles = explode(',', $CFG->gradebookroles);
             foreach ($roles as $role) {
                 if (in_array($role->roleid, $gradebookroles)) {
                     // if they have at least one gradebook role show their grade
                     $add = true;
                 }
             }
             if ($add === false) {
                 // don't show grade for non gradebook role
                 continue;
             }
         } else {
             // if there are no given roles for the context, then they aren't students
             continue;
         }
         $gradedata = new \stdClass();
         $gradedata->fullname = fullname($userrecs[$grade->userid]);
         if ($this->rtq->group_mode()) {
             $groups = $this->rtq->get_groupmanager()->get_user_groups($grade->userid);
             if (!empty($groups)) {
                 $groupstring = '';
                 foreach ($groups as $group) {
                     if (strlen($groupstring) > 0) {
                         // add a comma space if we're back in the foreach for a second or more time
                         $groupstring .= ', ';
                     }
                     $groupstring .= $this->rtq->get_groupmanager()->get_group_name($group->id);
                 }
                 $gradedata->group = $groupstring;
             } else {
                 $gradedata->group = ' - ';
             }
         }
         $gradedata->grade = number_format($grade->rawgrade, 2);
         $gradedata->timemodified = $grade->dategraded;
         $data[] = $gradedata;
     }
     return $data;
 }