/** * Actual implementation of the reset course functionality, delete all the * quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is * set and true. * * Also, move the quiz open and close dates, if the course start date is changing. * * @param object $data the data submitted from the reset course. * @return array status array */ function quiz_reset_userdata($data) { global $CFG, $DB; require_once($CFG->libdir . '/questionlib.php'); $componentstr = get_string('modulenameplural', 'quiz'); $status = array(); // Delete attempts. if (!empty($data->reset_quiz_attempts)) { question_engine::delete_questions_usage_by_activities(new qubaid_join( '{quiz_attempts} quiza JOIN {quiz} quiz ON quiza.quiz = quiz.id', 'quiza.uniqueid', 'quiz.course = :quizcourseid', array('quizcourseid' => $data->courseid))); $DB->delete_records_select('quiz_attempts', 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid)); $status[] = array( 'component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), 'error' => false); // Remove all grades from gradebook. $DB->delete_records_select('quiz_grades', 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid)); if (empty($data->reset_gradebook_grades)) { quiz_reset_gradebook($data->courseid); } $status[] = array( 'component' => $componentstr, 'item' => get_string('gradesdeleted', 'quiz'), 'error' => false); } // Updating dates - shift may be negative too. if ($data->timeshift) { $DB->execute("UPDATE {quiz_overrides} SET timeopen = timeopen + ? WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND timeopen <> 0", array($data->timeshift, $data->courseid)); $DB->execute("UPDATE {quiz_overrides} SET timeclose = timeclose + ? WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND timeclose <> 0", array($data->timeshift, $data->courseid)); shift_course_mod_dates('quiz', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid); $status[] = array( 'component' => $componentstr, 'item' => get_string('openclosedatesupdated', 'quiz'), 'error' => false); } return $status; }
/** * Scheduled tasks relating to question preview. Specifically, delete any old * previews that are left over in the database. */ function question_preview_cron() { $maxage = 24 * 60 * 60; // We delete previews that have not been touched for 24 hours. $lastmodifiedcutoff = time() - $maxage; mtrace("\n Cleaning up old question previews...", ''); $oldpreviews = new qubaid_join('{question_usages} quba', 'quba.id', 'quba.component = :qubacomponent AND NOT EXISTS ( SELECT 1 FROM {question_attempts} subq_qa JOIN {question_attempt_steps} subq_qas ON subq_qas.questionattemptid = subq_qa.id JOIN {question_usages} subq_qu ON subq_qu.id = subq_qa.questionusageid WHERE subq_qa.questionusageid = quba.id AND subq_qu.component = :qubacomponent2 AND (subq_qa.timemodified > :qamodifiedcutoff OR subq_qas.timecreated > :stepcreatedcutoff) ) ', array('qubacomponent' => 'core_question_preview', 'qubacomponent2' => 'core_question_preview', 'qamodifiedcutoff' => $lastmodifiedcutoff, 'stepcreatedcutoff' => $lastmodifiedcutoff)); question_engine::delete_questions_usage_by_activities($oldpreviews); mtrace('done.'); }
/** * Static function to delete a session instance * * Is static so we don't have to instantiate a session class * * @param $sessionid * @return bool */ public static function delete($sessionid) { global $DB; // delete all attempt qubaids, then all realtime quiz attempts, and then finally itself \question_engine::delete_questions_usage_by_activities(new \mod_activequiz\utils\qubaids_for_rtq($sessionid)); $DB->delete_records('activequiz_attempts', array('sessionid' => $sessionid)); $DB->delete_records('activequiz_groupattendance', array('sessionid' => $sessionid)); $DB->delete_records('activequiz_sessions', array('id' => $sessionid)); return true; }