/** * 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; }
/** * Actual implementation of the rest coures 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 $data the data submitted from the reset course. * @return array status array */ function quiz_reset_userdata($data) { global $CFG, $QTYPES; // TODO: this should use the delete_attempt($attempt->uniqueid) function in questionlib.php // require_once($CFG->libdir.'/questionlib.php'); $componentstr = get_string('modulenameplural', 'quiz'); $status = array(); /// Delete attempts. if (!empty($data->reset_quiz_attempts)) { $stateslistsql = "SELECT s.id\n FROM {$CFG->prefix}question_states s\n INNER JOIN {$CFG->prefix}quiz_attempts qza ON s.attempt=qza.uniqueid\n INNER JOIN {$CFG->prefix}quiz q ON qza.quiz=q.id\n WHERE q.course={$data->courseid}"; $attemptssql = "SELECT a.uniqueid\n FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}quiz q\n WHERE q.course={$data->courseid} AND a.quiz=q.id"; $quizessql = "SELECT q.id\n FROM {$CFG->prefix}quiz q\n WHERE q.course={$data->courseid}"; if ($states = get_records_sql($stateslistsql)) { //TODO: not sure if this works $stateslist = implode(',', array_keys($states)); foreach ($QTYPES as $qtype) { $qtype->delete_states($stateslist); } } delete_records_select('question_states', "attempt IN ({$attemptssql})"); delete_records_select('question_sessions', "attemptid IN ({$attemptssql})"); delete_records_select('question_attempts', "id IN ({$attemptssql})"); // remove all grades from gradebook if (empty($data->reset_gradebook_grades)) { quiz_reset_gradebook($data->courseid); } delete_records_select('quiz_grades', "quiz IN ({$quizessql})"); $status[] = array('component' => $componentstr, 'item' => get_string('gradesdeleted', 'quiz'), 'error' => false); delete_records_select('quiz_attempts', "quiz IN ({$quizessql})"); $status[] = array('component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), 'error' => false); } /// updating dates - shift may be negative too if ($data->timeshift) { 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; }
/** * 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. * * @global stdClass * @global object * @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)) { $quizzes = $DB->get_records('quiz', array('course' => $data->courseid)); foreach ($quizzes as $quiz) { quiz_delete_all_attempts($quiz); } // remove all grades from gradebook if (empty($data->reset_gradebook_grades)) { quiz_reset_gradebook($data->courseid); } $status[] = array('component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), 'error' => false); } /// updating dates - shift may be negative too if ($data->timeshift) { 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; }