You are here

function quiz_stats_validate_vid in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 modules/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  2. 8.4 modules/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  3. 8.5 modules/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  4. 6.4 includes/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  5. 7.6 modules/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  6. 7 includes/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  7. 7.4 includes/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()
  8. 7.5 modules/quiz_stats/quiz_stats.module \quiz_stats_validate_vid()

Validate the node.

Check if its of type quiz, and that the user has access to it, and that the vid is a vid of that quiz.

Parameters

$quiz: The quiz node.

$vid: The version id.

Return value

TRUE if user has access.

1 string reference to 'quiz_stats_validate_vid'
quiz_stats_menu in modules/quiz_stats/quiz_stats.module
Implements hook_menu().

File

modules/quiz_stats/quiz_stats.module, line 141
Quiz stats.

Code

function quiz_stats_validate_vid($quiz, $vid) {
  if ($quiz->type != 'quiz') {
    return FALSE;
  }
  if (!user_access('access author stats')) {
    return FALSE;
  }

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  return $quiz->nid == \Drupal::database()
    ->query('SELECT n.nid FROM {node} n INNER JOIN {node_revision} nr ON (n.nid = nr.nid) WHERE nr.vid = :vid', [
    ':vid' => $vid,
  ])
    ->fetchField();
}