public function dbRecordExists()
 {
     $query = "\n\t\t\tSELECT COUNT(*) cnt\n\t\t\tFROM tst_skl_qst_assigns\n\t\t\tWHERE test_fi = %s\n\t\t\tAND question_fi = %s\n\t\t\tAND skill_base_fi = %s\n\t\t\tAND skill_tref_fi = %s\n\t\t";
     $res = $this->db->queryF($query, array('integer', 'integer', 'integer', 'integer'), array($this->getTestId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId()));
     $row = $this->db->fetchAssoc($res);
     return $row['cnt'] > 0;
 }
 private function loadTaxonomyTreeLabels()
 {
     $IN_taxIds = $this->db->in('obj_id', $this->taxonomyTreeIds, false, 'integer');
     $query = "\n\t\t\tSELECT\t\tobj_id tax_tree_id,\n\t\t\t\t\t\ttitle tax_tree_title\n\n\t\t\tFROM\t\tobject_data\n\n\t\t\tWHERE\t\t{$IN_taxIds}\n\t\t\tAND\t\t\ttype = %s\n\t\t";
     $res = $this->db->queryF($query, array('text'), array('tax'));
     while ($row = $this->db->fetchAssoc($res)) {
         $this->taxonomyTreeLabels[$row['tax_tree_id']] = $row['tax_tree_title'];
     }
 }
 private function getPurgableQuestionIds()
 {
     $INtypes = $this->db->in('object_data.type', $this->getIgnoredContainerObjectTypes(), true, 'text');
     $query = "\n\t\t\tSELECT qpl_questions.question_id\n\t\t\tFROM qpl_questions\n\t\t\tINNER JOIN object_data\n\t\t\tON object_data.obj_id = qpl_questions.obj_fi\n\t\t\tAND {$INtypes}\n\t\t\tWHERE qpl_questions.owner = %s\n\t\t\tAND qpl_questions.tstamp = %s\n\t\t";
     $res = $this->db->queryF($query, array('integer', 'integer'), array($this->getOwnerId(), 0));
     $questionIds = array();
     while ($row = $this->db->fetchAssoc($res)) {
         $questionIds[] = $row['question_id'];
     }
     return $questionIds;
 }
 public function getNextRequestableHint()
 {
     $query = "\n\t\t\tSELECT\t\tqht_hint_id\n\t\t\t\n\t\t\tFROM\t\tqpl_hints\n\t\t\t\n\t\t\tWHERE\t\tqht_question_fi = %s\n\t\t\t\n\t\t\tORDER BY\tqht_hint_index ASC\n\t\t";
     $res = $this->db->queryF($query, array('integer'), array($this->previewSession->getQuestionId()));
     while ($row = $this->db->fetchAssoc($res)) {
         if (!$this->isRequested($row['qht_hint_id'])) {
             return ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
         }
     }
     throw new ilTestException("no next hint found for questionId={$this->previewSession->getQuestionId()}, userId={$this->previewSession->getUserId()}");
 }
 public function loadFromDb()
 {
     $this->resetThresholds();
     $query = "\n\t\t\tSELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold\n\t\t\tFROM tst_skl_thresholds\n\t\t\tWHERE test_fi = %s\n\t\t";
     $res = $this->db->queryF($query, array('integer'), array($this->getTestId()));
     while ($row = $this->db->fetchAssoc($res)) {
         $threshold = $this->buildSkillLevelThresholdByArray($row);
         $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
         $this->addThreshold($skillKey, $threshold->getSkillLevelId(), $threshold);
     }
 }
 public function load()
 {
     $query = "\n\t\t\tSELECT *\n\t\t\tFROM qpl_qst_skl_sol_expr\n\t\t\tWHERE question_fi = %s AND skill_base_fi = %s AND skill_tref_fi = %s\n\t\t";
     $res = $this->db->queryF($query, array('integer', 'integer', 'integer'), array($this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId()));
     while ($row = $this->db->fetchAssoc($res)) {
         $expression = new ilAssQuestionSolutionComparisonExpression();
         $expression->setDb($this->db);
         $expression->initInstanceFromArray($row);
         $this->add($expression);
     }
 }
 public function loadFromDb()
 {
     $this->reset();
     $query = "\n\t\t\tSELECT test_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points\n\t\t\tFROM tst_skl_qst_assigns\n\t\t\tWHERE test_fi = %s\n\t\t";
     $res = $this->db->queryF($query, array('integer'), array($this->getTestId()));
     while ($row = $this->db->fetchAssoc($res)) {
         $assignment = $this->buildSkillQuestionAssignmentByArray($row);
         $this->addAssignment($assignment);
         $this->incrementNumAssignsBySkill($assignment);
         $this->incrementMaxPointsBySkill($assignment);
     }
 }
 public function load($testId)
 {
     $this->byActiveId = array();
     $this->byUserId = array();
     $query = "\n\t\t\tSELECT\t\tta.active_id,\n\t\t\t\t\t\tta.user_fi user_id,\n\t\t\t\t\t\tud.firstname,\n\t\t\t\t\t\tud.lastname\n\t\t\tFROM\t\ttst_active ta\n\t\t\tLEFT JOIN\tusr_data ud\n\t\t\tON \t\t\tud.usr_id = ta.user_fi\n\t\t\tWHERE\t\ttest_fi = %s\n\t\t\tAND\t\t\t{$this->getConditionalExpression()}\n\t\t";
     $res = $this->db->queryF($query, array('integer'), array($testId));
     while ($row = $this->db->fetchAssoc($res)) {
         $this->byActiveId[$row['active_id']] = $row;
         $this->byUserId[$row['user_id']] = $row;
     }
     $this->setActiveIds(array_keys($this->byActiveId));
     $this->setUserIds(array_keys($this->byUserId));
 }
 private function stageQuestionsFromSourcePool($sourcePoolId)
 {
     $questionIdMapping = array();
     $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
     $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
     while ($row = $this->db->fetchAssoc($res)) {
         $question = assQuestion::_instanciateQuestion($row['question_id']);
         $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
         $nextId = $this->db->nextId('tst_rnd_cpy');
         $this->db->insert('tst_rnd_cpy', array('copy_id' => array('integer', $nextId), 'tst_fi' => array('integer', $this->testOBJ->getTestId()), 'qst_fi' => array('integer', $duplicateId), 'qpl_fi' => array('integer', $sourcePoolId)));
         $questionIdMapping[$row['question_id']] = $duplicateId;
     }
     return $questionIdMapping;
 }
 public function saveToDb()
 {
     $tracking = serialize($this->questionTracking);
     $postponed = serialize($this->postponedQuestions);
     $hidden = serialize(array('correct' => $this->correctAnsweredQuestions, 'wrong' => $this->wrongAnsweredQuestions));
     $query = "SELECT COUNT(*) cnt FROM tst_sequence WHERE active_fi = %s AND pass = %s";
     $res = $this->db->queryF($query, array('integer', 'integer'), array($this->activeId, 0));
     $row = $this->db->fetchAssoc($res);
     if ($row['cnt'] > 0) {
         $this->db->update('tst_sequence', array('sequence' => array('clob', $tracking), 'postponed' => array('text', $postponed), 'hidden' => array('text', $hidden), 'tstamp' => array('integer', time())), array('active_fi' => array('integer', $this->activeId), 'pass' => array('integer', 0)));
     } else {
         $this->db->insert('tst_sequence', array('active_fi' => array('integer', $this->activeId), 'pass' => array('integer', 0), 'sequence' => array('clob', $tracking), 'postponed' => array('text', $postponed), 'hidden' => array('text', $hidden), 'tstamp' => array('integer', time())));
     }
 }
 /**
  * @return bool
  */
 public function savedDefinitionsExist()
 {
     $query = "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
     $res = $this->db->queryF($query, array('integer'), array($this->testOBJ->getTestId()));
     $row = $this->db->fetchAssoc($res);
     return $row['cnt'] > 0;
 }
    /**
     * @param ilTermsOfServiceAcceptanceEntity $entity
     * @return ilTermsOfServiceAcceptanceEntity
     */
    public function loadById(ilTermsOfServiceAcceptanceEntity $entity)
    {
        $res = $this->db->queryF('
			SELECT *
			FROM tos_versions
			WHERE id = %s
			', array('integer'), array($entity->getId()));
        $row = $this->db->fetchAssoc($res);
        $entity->setId($row['id']);
        $entity->setIso2LanguageCode($row['lng']);
        $entity->setSource($row['src']);
        $entity->setSourceType($row['src_type']);
        $entity->setText($row['text']);
        $entity->setTimestamp($row['ts']);
        $entity->setHash($row['hash']);
        return $entity;
    }
 /**
  * @param integer $poolId
  * @return boolean
  */
 public function loadFromDb($id)
 {
     $res = $this->db->queryF("SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s", array('integer'), array($id));
     while ($row = $this->db->fetchAssoc($res)) {
         $this->initFromArray($row);
         return true;
     }
     return false;
 }
 /**
  * returns the SPECIFIC answer feedback ID for a given question id and answer index.
  *
  * @final
  * @access protected
  * @param integer $questionId
  * @param boolean $answerIndex
  * @return string $feedbackId
  */
 protected final function getGenericFeedbackId($questionId, $solutionCompleted)
 {
     $res = $this->db->queryF("SELECT feedback_id FROM {$this->getGenericFeedbackTableName()} WHERE question_fi = %s AND correctness = %s", array('integer', 'text'), array($questionId, (int) $solutionCompleted));
     $feedbackId = null;
     while ($row = $this->db->fetchAssoc($res)) {
         $feedbackId = $row['feedback_id'];
         break;
     }
     return $feedbackId;
 }
 private function getNewOrderIndexForQuestionTracking()
 {
     $query = "\n\t\t\t\tSELECT (MAX(orderindex) + 1) new_order_index\n\t\t\t\tFROM tst_seq_qst_tracking\n\t\t\t\tWHERE active_fi = %s\n\t\t\t\tAND pass = %s\n\t\t\t";
     $res = $this->db->queryF($query, array('integer', 'integer'), array($this->getActiveId(), 0));
     $row = $this->db->fetchAssoc($res);
     if ($row['new_order_index']) {
         return $row['new_order_index'];
     }
     return 1;
 }
 public function loadQuestions()
 {
     $query = "\n\t\t\tSELECT\t\tqpl_questions.question_id,\n\t\t\t\t\t\tqpl_qst_type.type_tag,\n\t\t\t\t\t\tqpl_qst_type.plugin\n\n\t\t\tFROM\t\ttst_rnd_cpy\n\n\t\t\tINNER JOIN\tqpl_questions\n\t\t\tON\t\t\tqpl_questions.question_id = tst_rnd_cpy.qst_fi\n\n\t\t\tINNER JOIN\tqpl_qst_type\n\t\t\tON\t\t\tqpl_qst_type.question_type_id = qpl_questions.question_type_fi\n\n\t\t\tWHERE\t\ttst_rnd_cpy.tst_fi = %s\n\t\t\tAND\t\t\ttst_rnd_cpy.qpl_fi = %s\n\n\t\t\t{$this->getConditionalExpression()}\n\t\t";
     $res = $this->db->queryF($query, array('integer', 'integer'), array($this->getTestId(), $this->getPoolId()));
     //vd($this->db->db->last_query);
     while ($row = $this->db->fetchAssoc($res)) {
         if (!$this->isActiveQuestionType($row)) {
             continue;
         }
         $this->questions[] = $row['question_id'];
     }
 }
 public function load()
 {
     $query = "\n\t\t\tSELECT\t\tqpl_questions.*,\n\t\t\t\t\t\tqpl_qst_type.type_tag,\n\t\t\t\t\t\tqpl_qst_type.plugin\n\t\t\tFROM\t\tqpl_questions,\n\t\t\t\t\t\tqpl_qst_type\n\t\t\tWHERE\t\tqpl_questions.original_id IS NULL\n\t\t\tAND\t\t\tqpl_questions.tstamp > 0\n\t\t\tAND\t\t\tqpl_questions.question_type_fi = qpl_qst_type.question_type_id\n\t\t\tAND\t\t\tqpl_questions.obj_fi = %s\n\t\t\t\n\t\t\t{$this->getConditionalExpression()}\n\t\t";
     $res = $this->db->queryF($query, array('integer'), array($this->parentObjId));
     while ($row = $this->db->fetchAssoc($res)) {
         if (!$this->isActiveQuestionType($row)) {
             continue;
         }
         $row['taxonomies'] = $this->loadTaxonomyAssignmentData($row['question_id']);
         $row['ttype'] = $this->lng->txt($row['type_tag']);
         $this->questions[$row['question_id']] = $row;
     }
 }
 /**
  * @param integer $poolObjId
  * @return \ilDynamicTestQuestionChangeListener
  */
 public static function getPoolQuestionChangeListener(ilDB $db, $poolObjId)
 {
     $query = "\n\t\t\tSELECT obj_fi\n\t\t\tFROM tst_dyn_quest_set_cfg\n\t\t\tINNER JOIN tst_tests\n\t\t\tON tst_tests.test_id = tst_dyn_quest_set_cfg.test_fi\n\t\t\tWHERE source_qpl_fi = %s\n\t\t";
     $res = $db->queryF($query, array('integer'), array($poolObjId));
     require_once 'Modules/Test/classes/class.ilDynamicTestQuestionChangeListener.php';
     $questionChangeListener = new ilDynamicTestQuestionChangeListener($db);
     while ($row = $db->fetchAssoc($res)) {
         $questionChangeListener->addTestObjId($row['obj_fi']);
     }
     return $questionChangeListener;
 }