function quiz_question_refresh_latest_quizzes in Quiz 6.4
Same name and namespace in other branches
- 8.4 question_types/quiz_question/quiz_question.module \quiz_question_refresh_latest_quizzes()
- 7 question_types/quiz_question/quiz_question.module \quiz_question_refresh_latest_quizzes()
- 7.4 question_types/quiz_question/quiz_question.module \quiz_question_refresh_latest_quizzes()
Refreshes the quiz_question_latest_quizzes table when a user has modified a new quiz.
The latest quizzes table is used to know what quizzes the user has been using lately.
Parameters
$nid: nid of the last quiz the current user modified
2 calls to quiz_question_refresh_latest_quizzes()
- quiz_question_insert in question_types/
quiz_question/ quiz_question.module - Implementation of hook_insert()
- quiz_question_nodeapi in question_types/
quiz_question/ quiz_question.module - Implementation of hook_nodeapi().
File
- question_types/
quiz_question/ quiz_question.module, line 740 - Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.
Code
function quiz_question_refresh_latest_quizzes($nid) {
global $user;
// Delete entry if it allready exists
$sql = 'DELETE FROM {quiz_question_latest_quizzes}
WHERE uid = %d AND quiz_nid = %d';
db_query($sql, $user->uid, $nid);
// Inserts as new entry to get new id. Latest quizzes are ordered by id(descending)
$sql = 'INSERT INTO {quiz_question_latest_quizzes}
(uid, quiz_nid)
VALUES (%d, %d)';
db_query($sql, $user->uid, $nid);
// If we have to many entries for current user, delete the oldest entries...
$sql = 'SELECT COUNT(*)
FROM {quiz_question_latest_quizzes}
WHERE uid = %d';
$count = db_result(db_query($sql, $user->uid));
$n_to_delete = (int) $count - QUIZ_QUESTION_NUM_LATEST;
if ($n_to_delete > 0) {
$sql = 'DELETE FROM {quiz_question_latest_quizzes}
WHERE uid = %d
ORDER BY id LIMIT %d';
db_query($sql, $user->uid, $n_to_delete);
}
}