function quiz_question_refresh_latest_quizzes in Quiz 7
Same name and namespace in other branches
- 8.4 question_types/quiz_question/quiz_question.module \quiz_question_refresh_latest_quizzes()
- 6.4 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
3 calls to quiz_question_refresh_latest_quizzes()
- quiz_question_insert in question_types/
quiz_question/ quiz_question.module - Implements hook_insert().
- quiz_question_node_insert in question_types/
quiz_question/ quiz_question.module - Implements hook_node_insert().
- quiz_question_node_update in question_types/
quiz_question/ quiz_question.module - Implements hook_node_update().
File
- question_types/
quiz_question/ quiz_question.module, line 757 - 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
db_delete('quiz_question_latest_quizzes')
->condition('uid', $user->uid)
->condition('quiz_nid', $nid)
->execute();
// Inserts as new entry to get new id. Latest quizzes are ordered by id(descending)
$id = db_insert('quiz_question_latest_quizzes')
->fields(array(
'uid' => $user->uid,
'quiz_nid' => $nid,
))
->execute();
// If we have to many entries for current user, delete the oldest entries...
$count = db_query('SELECT COUNT(*) FROM {quiz_question_latest_quizzes}
WHERE uid = :uid', array(
':uid' => $user->uid,
))
->fetchField();
$n_to_delete = (int) $count - QUIZ_QUESTION_NUM_LATEST;
if ($n_to_delete > 0) {
db_delete('quiz_question_latest_quizzes')
->condition('uid', $user->uid)
->orderBy('id')
->range(0, $n_to_delete)
->execute();
}
}