You are here

public static function ShortAnswerResponse::fetchAllUnscoredAnswers in Quiz 8.4

Get all quiz scores that haven't been evaluated yet.

Parameters

$count: Number of items to return (default: 50).

$offset: Where in the results we should start (default: 0).

Return value

Array of objects describing unanswered questions. Each object will have result_id, question_nid, and question_vid.

1 call to ShortAnswerResponse::fetchAllUnscoredAnswers()
short_answer_view_unscored in question_types/short_answer/short_answer.admin.inc
Generate a view of all unscored short_answer questions.

File

question_types/short_answer/lib/Drupal/short_answer/ShortAnswerResponse.php, line 30
The main classes for the short answer response.

Class

ShortAnswerResponse
Extension of QuizQuestionResponse

Namespace

Drupal\short_answer

Code

public static function fetchAllUnscoredAnswers($count = 50, $offset = 0) {
  $user = \Drupal::currentUser();
  $query = db_select('quiz_short_answer_user_answers', 'a');
  $query
    ->fields('a', array(
    'result_id',
    'question_nid',
    'question_vid',
    'answer_feedback',
  ));
  $query
    ->fields('nd', array(
    'title',
  ));
  $query
    ->fields('qnr', array(
    'time_end',
    'time_start',
    'uid',
  ));
  $query
    ->join('quiz_node_results', 'qnr', 'a.result_id = qnr.result_id');
  $query
    ->join('node', 'n', 'qnr.nid = n.nid');
  $query
    ->join('node_field_data', 'nd', 'nd.nid = n.nid AND nd.vid = n.vid');
  $query
    ->condition('a.is_evaluated', 0);
  if ($user
    ->hasPermission('score own quiz') && $user
    ->hasPermission('score taken quiz answer')) {
    $query
      ->condition(db_or()
      ->condition('nd.uid', $user
      ->id())
      ->condition('qnr.uid', $user
      ->id()));
  }
  else {
    if ($user
      ->hasPermission('score own quiz')) {
      $query
        ->condition('nd.uid', $user
        ->id());
    }
    else {
      if ($user
        ->hasPermission('score taken quiz answer')) {
        $query
          ->condition('qnr.uid', $user
          ->id());
      }
    }
  }
  $results = $query
    ->execute();
  $unscored = array();
  foreach ($results as $row) {
    $unscored[] = $row;
  }
  return $unscored;
}