107 $this->newlyTrackedQuestion = null;
108 $this->newlyTrackedQuestionsStatus = null;
110 $this->newlyPostponedQuestion = null;
111 $this->newlyPostponedQuestionsCount = null;
113 $this->newlyAnsweredQuestion = null;
114 $this->newlyAnsweredQuestionsAnswerStatus = null;
116 $this->alreadyCheckedQuestions = array();
117 $this->newlyCheckedQuestion = null;
119 $this->preventCheckedQuestionsFromComingUpEnabled =
false;
148 SELECT question_fi, status
149 FROM tst_seq_qst_tracking
152 ORDER BY orderindex ASC
155 $res = $this->db->queryF(
$query, array(
'integer',
'integer'), array($this->activeId, 0));
157 $this->questionTracking = array();
159 while(
$row = $this->db->fetchAssoc(
$res) )
161 $this->questionTracking[] = array(
162 'qid' =>
$row[
'question_fi'],
163 'status' =>
$row[
'status']
171 SELECT question_fi, correctness
172 FROM tst_seq_qst_answstatus
177 $res = $this->db->queryF(
$query, array(
'integer',
'integer'), array($this->activeId, 0));
179 $this->correctAnsweredQuestions = array();
180 $this->wrongAnsweredQuestions = array();
182 while(
$row = $this->db->fetchAssoc(
$res) )
184 if(
$row[
'correctness'] )
186 $this->correctAnsweredQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
190 $this->wrongAnsweredQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
198 SELECT question_fi, cnt
199 FROM tst_seq_qst_postponed
204 $res = $this->db->queryF(
$query, array(
'integer',
'integer'), array($this->activeId, 0));
206 $this->postponedQuestions = array();
208 while(
$row = $this->db->fetchAssoc(
$res) )
210 $this->postponedQuestions[
$row[
'question_fi'] ] = $row[
'cnt'];
216 $res = $this->db->queryF(
"SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
217 array(
'integer',
'integer'), array($this->
getActiveId(), 0)
220 while(
$row = $this->db->fetchAssoc(
$res) )
222 $this->alreadyCheckedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
228 $this->db->manipulateF(
229 "DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
230 array(
'integer',
'integer'), array($this->
getActiveId(), 0)
233 $this->db->insert(
'tst_sequence', array(
234 'active_fi' => array(
'integer', $this->
getActiveId()),
235 'pass' => array(
'integer', 0),
236 'sequence' => array(
'clob', null),
237 'postponed' => array(
'text', null),
238 'hidden' => array(
'text', null),
239 'tstamp' => array(
'integer', time())
252 if( (
int)$this->newlyTrackedQuestion )
256 $this->db->replace(
'tst_seq_qst_tracking',
258 'active_fi' => array(
'integer', (
int)$this->
getActiveId()),
259 'pass' => array(
'integer', 0),
260 'question_fi' => array(
'integer', (
int)$this->newlyTrackedQuestion)
263 'status' => array(
'text', $this->newlyTrackedQuestionsStatus),
264 'orderindex' => array(
'integer', $newOrderIndex)
273 SELECT (MAX(orderindex) + 1) new_order_index
274 FROM tst_seq_qst_tracking
283 if(
$row[
'new_order_index'] )
285 return $row[
'new_order_index'];
293 if( (
int)$this->newlyAnsweredQuestion )
295 $this->db->replace(
'tst_seq_qst_answstatus',
297 'active_fi' => array(
'integer', (
int)$this->
getActiveId()),
298 'pass' => array(
'integer', 0),
299 'question_fi' => array(
'integer', (
int)$this->newlyAnsweredQuestion)
302 'correctness' => array(
'integer', (
int)$this->newlyAnsweredQuestionsAnswerStatus)
310 if( (
int)$this->newlyPostponedQuestion )
312 $this->db->replace(
'tst_seq_qst_postponed',
314 'active_fi' => array(
'integer', (
int)$this->
getActiveId()),
315 'pass' => array(
'integer', 0),
316 'question_fi' => array(
'integer', (
int)$this->newlyPostponedQuestion)
319 'cnt' => array(
'integer', (
int)$this->newlyPostponedQuestionsCount)
327 $INquestions = $this->db->in(
'question_fi', array_keys($this->postponedQuestions),
true,
'integer');
330 DELETE FROM tst_seq_qst_postponed
336 $this->db->manipulateF(
$query, array(
'integer',
'integer'), array($this->
getActiveId(), 0));
341 if( (
int)$this->newlyCheckedQuestion )
343 $this->db->replace(
'tst_seq_qst_checked', array(
344 'active_fi' => array(
'integer', (
int)$this->
getActiveId()),
345 'pass' => array(
'integer', 0),
346 'question_fi' => array(
'integer', (
int)$this->newlyCheckedQuestion)
353 $NOT_IN_checkedQuestions = $this->db->in(
'question_fi', $this->alreadyCheckedQuestions,
true,
'integer');
356 if($NOT_IN_checkedQuestions ==
' 1=2 ') $NOT_IN_checkedQuestions =
' 1=1 ';
360 DELETE FROM tst_seq_qst_checked
363 AND $NOT_IN_checkedQuestions
366 $this->db->manipulateF(
$query, array(
'integer',
'integer'), array((
int)$this->
getActiveId(), 0));
371 $this->questionSet->load($dynamicQuestionSetConfig, $filterSelection);
392 foreach($this->postponedQuestions as $questionId)
394 if( !$this->questionSet->questionExists($questionId) )
396 unset($this->postponedQuestions[$questionId]);
400 foreach($this->wrongAnsweredQuestions as $questionId)
402 if( !$this->questionSet->questionExists($questionId) )
404 unset($this->wrongAnsweredQuestions[$questionId]);
408 foreach($this->correctAnsweredQuestions as $questionId)
410 if( !$this->questionSet->questionExists($questionId) )
412 unset($this->correctAnsweredQuestions[$questionId]);
438 foreach($this->questionSet->getActualQuestionSequence() as $level => $questions)
442 foreach($questions as $pos => $qId)
444 if( isset($this->correctAnsweredQuestions[$qId]) )
454 if( $forceNonAnsweredQuestion && isset($this->wrongAnsweredQuestions[$qId]) )
459 if( isset($this->postponedQuestions[$qId]) )
480 isset($this->correctAnsweredQuestions[$questionId])
481 || isset($this->wrongAnsweredQuestions[$questionId])
487 return isset($this->postponedQuestions[$questionId]);
492 foreach($this->questionSet->getActualQuestionSequence() as $level => $questions)
494 if( in_array($questionId, $questions) )
505 return (
bool)count($this->questionTracking);
510 $questionList = array();
512 if( $currentQuestionId )
514 $questionList[$currentQuestionId] = $this->questionSet->getQuestionData($currentQuestionId);
517 foreach( array_reverse($this->questionTracking) as $trackedQuestion)
519 if( !isset($questionList[ $trackedQuestion[
'qid'] ]) )
521 $questionList[ $trackedQuestion[
'qid'] ] = $this->questionSet->getQuestionData($trackedQuestion[
'qid']);
525 return $questionList;
530 $this->questionTracking = array();
540 $completeQuestionIds = array_keys( $this->questionSet->getAllQuestionsData() );
542 $openQuestions = array_diff($completeQuestionIds, $this->correctAnsweredQuestions);
544 return $openQuestions;
549 $uniqueQuestions = array();
551 foreach($this->questionTracking as $trackedQuestion)
553 $uniqueQuestions[$trackedQuestion[
'qid']] = $trackedQuestion[
'qid'];
556 return count($uniqueQuestions);
563 foreach($this->questionSet->getActualQuestionSequence() as $level => $questions)
565 foreach($questions as $pos => $qId)
569 if($qId == $questionId)
583 foreach($this->questionSet->getActualQuestionSequence() as $level => $questions)
585 $count += count($questions);
595 unset($this->alreadyCheckedQuestions[$questionId]);
600 $this->newlyCheckedQuestion = $questionId;
601 $this->alreadyCheckedQuestions[$questionId] = $questionId;
606 return isset($this->alreadyCheckedQuestions[$questionId]);
613 if( !isset($this->postponedQuestions[$questionId]) )
615 $this->postponedQuestions[$questionId] = 0;
618 $this->postponedQuestions[$questionId]++;
620 $this->newlyPostponedQuestion = $questionId;
621 $this->newlyPostponedQuestionsCount = $this->postponedQuestions[$questionId];
626 if( isset($this->postponedQuestions[$questionId]) )
627 unset($this->postponedQuestions[$questionId]);
634 $this->correctAnsweredQuestions[$questionId] = $questionId;
636 if( isset($this->wrongAnsweredQuestions[$questionId]) )
637 unset($this->wrongAnsweredQuestions[$questionId]);
639 $this->newlyAnsweredQuestion = $questionId;
640 $this->newlyAnsweredQuestionsAnswerStatus =
true;
647 $this->wrongAnsweredQuestions[$questionId] = $questionId;
649 if( isset($this->correctAnsweredQuestions[$questionId]) )
650 unset($this->correctAnsweredQuestions[$questionId]);
652 $this->newlyAnsweredQuestion = $questionId;
653 $this->newlyAnsweredQuestionsAnswerStatus =
false;
658 $this->questionTracking[] = array(
659 'qid' => $questionId,
'status' => $answerStatus
662 $this->newlyTrackedQuestion = $questionId;
663 $this->newlyTrackedQuestionsStatus = $answerStatus;
677 return $this->questionSet->getCompleteQuestionList()->getQuestionDataArray();
682 return $this->questionSet->getFilteredQuestionList()->getQuestionDataArray();
691 $questionSequence = array();
693 foreach( $this->questionSet->getActualQuestionSequence() as $level => $questions )
695 $questionSequence = array_merge($questionSequence, $questions);
698 return $questionSequence;
707 $minPostponeCount = null;
708 $minPostponeItem = null;
712 if($minPostponeCount === null || $postponeCount <= $minPostponeCount)
714 $minPostponeCount = $postponeCount;
715 $minPostponeItem = $qId;
718 return $minPostponeItem;