/** * Destructor * Free the result */ public function __destruct() { if ($this->res) { $this->db->free($this->res); $this->res = null; } }
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 loadTaxonomyNodeLabels() { $IN_nodeIds = $this->db->in('tax_node.obj_id', $this->taxonomyNodeIds, false, 'integer'); $query = "\n\t\t\t\t\tSELECT\t\ttax_node.obj_id tax_node_id,\n\t\t\t\t\t\t\t\ttax_node.title tax_node_title\n\n\t\t\t\t\tFROM\t\ttax_node\n\n\t\t\t\t\tWHERE\t\t{$IN_nodeIds}\n\t\t\t\t"; $res = $this->db->query($query); while ($row = $this->db->fetchAssoc($res)) { $this->taxonomyNodeLabels[$row['tax_node_id']] = $row['tax_node_title']; } }
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()}"); }
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 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 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); } }
private function getActiveIds() { if (!count($this->getTestObjIds())) { return null; } $inTestObjIds = $this->db->in('obj_fi', $this->getTestObjIds(), false, 'integer'); $res = $this->db->query("\n\t\t\tSELECT active_id\n\t\t\tFROM tst_tests\n\t\t\tINNER JOIN tst_active\n\t\t\tON test_fi = test_id\n\t\t\tWHERE {$inTestObjIds}\n\t\t"); $activeIds = array(); while ($row = $this->db->fetchAssoc($res)) { $activeIds[] = $row['active_id']; } return $activeIds; }
public function getConditionalExpression() { $conditions = array(); if (count($this->getActiveIds())) { $conditions[] = $this->db->in('active_id', $this->getActiveIds(), false, 'integer'); } if (count($this->getUserIds())) { $conditions[] = $this->db->in('user_fi', $this->getUserIds(), false, 'integer'); } if (count($conditions)) { return '(' . implode(' OR ', $conditions) . ')'; } return '1 = 1'; }
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()))); } }
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; }
/** * @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; }
private function getTaxonomyFilterExpressions() { $expressions = array(); require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php'; require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php'; foreach ($this->getTaxonomyFilters() as $taxId => $taxNodes) { $questionIds = array(); $forceBypass = true; foreach ($taxNodes as $taxNode) { $forceBypass = false; $taxTree = new ilTaxonomyTree($taxId); $taxNodeAssignment = new ilTaxNodeAssignment('tst', $this->getTestObjId(), 'quest', $taxId); $subNodes = $taxTree->getSubTreeIds($taxNode); $subNodes[] = $taxNode; $taxItems = $taxNodeAssignment->getAssignmentsOfNode($subNodes); foreach ($taxItems as $taxItem) { $questionIds[$taxItem['item_id']] = $taxItem['item_id']; } } if (!$forceBypass) { $expressions[] = $this->db->in('question_id', $questionIds, false, 'integer'); } } return $expressions; }
private function getWhereConditions() { $conditions = array('obj_fi = ' . $this->db->quote($this->getParentObjId(), 'integer')); if ($this->getQuestionIdFilter()) { $conditions[] = 'question_fi = ' . $this->db->quote($this->getQuestionIdFilter(), 'integer'); } return implode(' AND ', $conditions); }
protected function getPreparedInsertResultRecordStatement() { if (self::$preparedInsertResultRecordStatement === null) { $query = "\n\t\t\t\tINSERT INTO tst_test_result (\n\t\t\t\t\ttest_result_id, active_fi, question_fi, pass, tstamp,\n\t\t\t\t\tpoints, manual, hint_count, hint_points, answered\n\t\t\t\t) VALUES (\n\t\t\t\t\t?, ?, ?, ?, ?, ?, ?, ?, ?, ?\n\t\t\t\t)\n\t\t\t"; self::$preparedInsertResultRecordStatement = $this->db->prepareManip($query, array('integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer')); } return self::$preparedInsertResultRecordStatement; }
/** * Load the value */ protected function loadValue() { if ($this->value === NULL) { $datatype = $this->field->getDatatype(); $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = " . $this->db->quote($this->id, "integer"); $set = $this->db->query($query); $rec = $this->db->fetchAssoc($set); $this->value = $rec['value']; } }
/** * 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 removeQuestionsNotCheckedAnymore() { $NOT_IN_checkedQuestions = $this->db->in('question_fi', $this->alreadyCheckedQuestions, true, 'integer'); // BEGIN: FIX IN QUERY if ($NOT_IN_checkedQuestions == ' 1=2 ') { $NOT_IN_checkedQuestions = ' 1=1 '; } // END: FIX IN QUERY $query = "\n\t\t\tDELETE FROM tst_seq_qst_checked\n\t\t\tWHERE active_fi = %s\n\t\t\tAND pass = %s\n\t\t\tAND {$NOT_IN_checkedQuestions}\n\t\t"; $this->db->manipulateF($query, array('integer', 'integer'), array((int) $this->getActiveId(), 0)); }
/** * Read object data from database * * @throws ilOrgUnitTypeException */ protected function read() { $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_type_id = ' . $this->db->quote($this->orgu_type_id, 'integer') . ' AND lang = ' . $this->db->quote($this->lang, 'text'); $set = $this->db->query($sql); if (!$this->db->numRows($set)) { throw new ilOrgUnitTypeException("OrgUnit type translation for OrgUnit type {$this->orgu_type_id} and language {$this->lang} does not exist in database"); } while ($rec = $this->db->fetchObject($set)) { $this->members[$rec->member] = (string) $rec->value; } }
private function loadRolesQuery($role) { $this->roles[$role] = array(); $q = "SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_" . $role . "%'"; $set = $this->db->query($q); while ($res = $this->db->fetchAssoc($set)) { $orgu_ref = $this->getRefIdFromRoleTitle($res["title"]); $this->roles[$role][$orgu_ref] = $res["obj_id"]; $this->role_to_orgu[$role][$res["obj_id"]] = $orgu_ref; } }
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 array $params * @param array $filter * @return array * @throws InvalidArgumentException */ public function getList(array $params, array $filter) { $data = array('items' => array(), 'cnt' => 0); $select = $this->getSelectPart($filter); $where = $this->getWherePart($filter); $from = $this->getFromPart($filter); $order = $this->getOrderByPart($params); $group = $this->getGroupByPart(); $having = $this->getHavingPart($filter); if (isset($params['group'])) { if (!is_string($params['group'])) { throw new InvalidArgumentException('Please provide a valid group field parameter.'); } $group = $params['group']; } if (isset($params['limit'])) { if (!is_numeric($params['limit'])) { throw new InvalidArgumentException('Please provide a valid numerical limit.'); } if (!isset($params['offset'])) { $params['offset'] = 0; } else { if (!is_numeric($params['offset'])) { throw new InvalidArgumentException('Please provide a valid numerical offset.'); } } $this->db->setLimit($params['limit'], $params['offset']); } $where = strlen($where) ? 'WHERE ' . $where : ''; $query = "SELECT {$select} FROM {$from} {$where}"; if (strlen($group)) { $query .= " GROUP BY {$group}"; } if (strlen($having)) { $query .= " HAVING {$having}"; } if (strlen($order)) { $query .= " ORDER BY {$order}"; } $res = $this->db->query($query); while ($row = $this->db->fetchAssoc($res)) { $data['items'][] = $row; } $data = $this->getAdditionalItems($data); if (isset($params['limit'])) { $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery"; $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql)); $data['cnt'] = $row_cnt['cnt']; } return $data; }
/** * Load the value */ protected function loadValue() { if ($this->value === NULL) { $datatype = $this->field->getDatatype(); switch ($datatype->getId()) { case ilDataCollectionDatatype::INPUTFORMAT_RATING: return true; } $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = " . $this->db->quote($this->id, "integer"); $set = $this->db->query($query); $rec = $this->db->fetchAssoc($set); $this->value = $rec['value']; } }
/** * Read object data from database * * @throws ilOrgUnitTypeException */ protected function read() { $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = ' . $this->db->quote($this->id, 'integer'); $set = $this->db->query($sql); if (!$this->db->numRows($set)) { throw new ilOrgUnitTypeException("OrgUnit type with id {$this->id} does not exist in database"); } $rec = $this->db->fetchObject($set); $this->default_lang = $rec->default_lang; // Don't use Setter because of unnecessary plugin checks $this->setCreateDate($rec->create_date); $this->setLastUpdate($rec->last_update); $this->setOwner($rec->owner); $this->setIcon($rec->icon); }
/** * Helper method to build cache for data of all entities * * @param $a_entity * @param Object $set ilDB->query() object * * @internal param string $entity * @return array of newly added IDs */ protected function buildCache($a_entity, $set) { $fields = array_keys($this->getTypes($a_entity, '')); $ids = array(); while ($rec = $this->db->fetchObject($set)) { $data = array(); foreach ($fields as $field) { $data[$field] = $rec->{$field}; } // il_dcl_viewdefinition is the only table that has no internal id, so we build primary from view_id AND field columns $id = $a_entity == 'il_dcl_viewdefinition' ? $rec->view_id . '_' . $rec->field : $rec->id; $this->caches[$a_entity][$id] = $data; $ids[] = $id; } return $ids; }
public function getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids) { $page_object_ids = array(); foreach ($a_ids as $dcl_obj_id) { // If a DCL table has a detail view, we need to export the associated page objects! $sql = "SELECT il_dcl_view.id AS page_obj_id FROM il_dcl_view " . "INNER JOIN il_dcl_table ON (il_dcl_table.id = il_dcl_view.table_id) " . "WHERE il_dcl_table.obj_id = " . $this->db->quote($dcl_obj_id, 'integer') . " " . "AND il_dcl_view.type=0 AND il_dcl_view.formtype=0"; $set = $this->db->query($sql); while ($rec = $this->db->fetchObject($set)) { $page_object_ids[] = "dclf:" . $rec->page_obj_id; } } if (count($page_object_ids)) { return array(array('component' => 'Services/COPage', 'entity' => 'pg', 'ids' => $page_object_ids)); } return array(); }
/** * @return bool */ private function read() { if (!$this->getRuleId()) { return true; } $query = 'SELECT * FROM ' . self::TABLE_NAME . ' ' . 'WHERE rule_id = ' . $this->db->quote($this->getRuleId(), 'integer'); $res = $this->db->query($query); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $this->setRoleId($row->role_id); $this->setName($row->name); $this->setValue($row->value); $this->enablePlugin($row->plugin); $this->setPluginId($row->plugin_id); $this->enableAddOnUpdate($row->add_on_update); $this->enableRemoveOnUpdate($row->remove_on_update); } }
public function load() { $this->checkFilters(); $query = $this->buildQuery(); #vd($query); $res = $this->db->query($query); //echo $this->db->db->last_query; #vd($this->db->db->last_query); while ($row = $this->db->fetchAssoc($res)) { if (!$this->isActiveQuestionType($row)) { continue; } $row['taxonomies'] = $this->loadTaxonomyAssignmentData($row['obj_fi'], $row['question_id']); $row['ttype'] = $this->lng->txt($row['type_tag']); $this->questions[$row['question_id']] = $row; } }
/** * delete client * @param boolean remove ini if true * @param boolean remove db if true * @param boolean remove files if true * @return array confirmation messages * */ function delete($a_ini = true, $a_db = false, $a_files = false) { if ($a_ini === true and file_exists(ILIAS_ABSOLUTE_PATH . "/" . ILIAS_WEB_DIR . "/" . $this->getId() . "/client.ini.php")) { unlink(CLIENT_WEB_DIR . "/client.ini.php"); $msg[] = "ini_deleted"; } if ($a_db === true and $this->db_exists) { $this->db->query("DROP DATABASE " . $this->getDbName()); $msg[] = "db_deleted"; } if ($a_files === true and file_exists(CLIENT_WEB_DIR) and is_dir(CLIENT_WEB_DIR)) { // rmdir(); ilUtil::delDir(CLIENT_WEB_DIR); ilUtil::delDir(CLIENT_DATA_DIR); $msg[] = "files_deleted"; } return $msg; }
/** * @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; }