Ejemplo n.º 1
0
 /**
  *
  *
  * @param int|null $userid
  *
  * @return array An array of group objects keyed by groupid
  */
 public function get_user_groups($userid = null)
 {
     global $USER;
     // assume current user when none specified
     if (empty($userid)) {
         $userid = $USER->id;
     }
     if (!empty($this->rtq->getRTQ()->grouping)) {
         return groups_get_all_groups($this->rtq->getCourse()->id, $userid, $this->rtq->getRTQ()->grouping);
     } else {
         return array();
         // return empty array when there is no grouping
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
/**
 * Prints local lib tabs
 *
 * @param \mod_activequiz\activequiz $RTQ Realtime quiz class
 * @param                            $currenttab
 *
 * @return string HTML string of the tabs
 */
function activequiz_view_tabs($RTQ, $currenttab)
{
    $tabs = array();
    $row = array();
    $inactive = array();
    $activated = array();
    if ($RTQ->has_capability('mod/activequiz:attempt')) {
        $row[] = new tabobject('view', new moodle_url('/mod/activequiz/view.php', array('id' => $RTQ->getCM()->id)), get_string('view', 'activequiz'));
    }
    if ($RTQ->has_capability('mod/activequiz:editquestions')) {
        $row[] = new tabobject('edit', new moodle_url('/mod/activequiz/edit.php', array('cmid' => $RTQ->getCM()->id)), get_string('edit', 'activequiz'));
    }
    if ($RTQ->has_capability('mod/activequiz:seeresponses')) {
        $row[] = new tabobject('responses', new moodle_url('/mod/activequiz/responses.php', array('id' => $RTQ->getCM()->id)), get_string('responses', 'activequiz'));
    }
    if ($currenttab == 'view' && count($row) == 1) {
        // No tabs for students
        echo '<br />';
    } else {
        $tabs[] = $row;
    }
    if ($currenttab == 'responses') {
        $activated[] = 'responses';
    }
    if ($currenttab == 'edit') {
        $activated[] = 'edit';
    }
    if ($currenttab == 'view') {
        $activated[] = 'view';
    }
    return print_tabs($tabs, $currenttab, $inactive, $activated, true);
}
Ejemplo n.º 4
0
 /**
  * Render a review question with no editing capabilities.
  *
  * Reviewing will be based upon the after review options specified in module settings
  *
  * @param int                                $slot
  * @param \mod_activequiz\activequiz_attempt $attempt
  *
  * @return string HTML fragment for the question
  */
 public function render_review_question($slot, $attempt)
 {
     $qnum = $attempt->get_question_number();
     $output = '';
     $output .= html_writer::start_div('activequizbox', array('id' => 'q' . $qnum . '_container'));
     $output .= $attempt->render_question($slot, true, $this->rtq->get_review_options('after'));
     $output .= html_writer::end_div();
     return $output;
 }
 /**
  * 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;
 }
Ejemplo n.º 6
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);
         }
     }
 }
 /**
  * Orders the real time questions and then
  * puts question bank ordered questions into the qbankorderedquestions var
  *
  */
 private function init_qbank_questions()
 {
     global $DB;
     // start by ordering the RTQ question ids into an array
     $questionorder = $this->rtq->getRTQ()->questionorder;
     // generate empty array for ordered questions for no question order
     if (empty($questionorder)) {
         $this->qbankOrderedQuestions = array();
         return;
     } else {
         // otherwise explode it and continue on
         $questionorder = explode(',', $questionorder);
     }
     // using the question order saved in rtq object, get the qbank question ids from the rtq questions
     $orderedquestionids = array();
     foreach ($questionorder as $qorder) {
         // store the rtq question id as the key so that it can be used later when adding question time to
         // question bank question object
         $orderedquestionids[$qorder] = $this->rtqQuestions[$qorder]->questionid;
     }
     // get qbank questions based on the question ids from the RTQ questions table
     list($sql, $params) = $DB->get_in_or_equal($orderedquestionids);
     $query = 'SELECT * FROM {question} WHERE id ' . $sql;
     $questions = $DB->get_records_sql($query, $params);
     // Now order the qbank questions based on the order that we got above
     $qbankOrderedQuestions = array();
     foreach ($orderedquestionids as $rtqqid => $questionid) {
         // use the ordered question ids we got earlier
         if (!empty($questions[$questionid])) {
             // create realtime quiz question and add it to the array
             $quizquestion = new \mod_activequiz\activequiz_question($rtqqid, $this->rtqQuestions[$rtqqid]->notime, $this->rtqQuestions[$rtqqid]->questiontime, $this->rtqQuestions[$rtqqid]->tries, $this->rtqQuestions[$rtqqid]->points, $this->rtqQuestions[$rtqqid]->showhistoryduringquiz, $questions[$questionid]);
             $qbankOrderedQuestions[$rtqqid] = $quizquestion;
             // add question to the ordered questions
         }
     }
     $this->qbankOrderedQuestions = $qbankOrderedQuestions;
 }
 /**
  * Closes the attempt
  *
  * @param \mod_activequiz\activequiz $rtq
  *
  * @return bool Weather or not it was successful
  */
 public function close_attempt($rtq)
 {
     $this->quba->finish_all_questions(time());
     $this->attempt->status = self::FINISHED;
     $this->attempt->timefinish = time();
     $this->save();
     $params = array('objectid' => $this->attempt->id, 'context' => $rtq->getContext(), 'relateduserid' => $this->attempt->userid);
     $event = \mod_activequiz\event\attempt_ended::create($params);
     $event->add_record_snapshot('activequiz_attempts', $this->attempt);
     $event->trigger();
     return true;
 }
 /**
  * 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;
 }
Ejemplo n.º 10
0
/**
 * Proces the review options on the quiz settings page
 *
 * @param \mod_activequiz\activequiz $activequiz
 * @return string
 */
function activequiz_process_review_options($activequiz)
{
    $afterreviewoptions = \mod_activequiz\activequiz::get_review_options_from_form($activequiz, 'after');
    $reviewoptions = new stdClass();
    $reviewoptions->after = $afterreviewoptions;
    // add all review options to the db object in the review options field.
    return json_encode($reviewoptions);
}