You are here

public static function LongAnswerResponse::fetchAllUnscoredAnswers in OG Quiz 7

Get all scores that have not yet been evaluated.

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.

File

includes/og_long_answer.php, line 190
Long answer classes.

Class

LongAnswerResponse
Extension of QuizQuestionResponse

Code

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