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']; } }
/** * 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']; } }
/** * 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; } }
/** * Return dependencies form entities to other entities (in our case these are all the DB relations) * * @param $a_entity * @param $a_version * @param $a_rec * @param $a_ids * * @return array */ protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids) { if (!$a_rec && !$a_ids) { return false; } switch ($a_entity) { case 'dcl': $set = $this->db->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $this->db->quote($a_rec['id'], 'integer') . ' ORDER BY id'); $ids = $this->buildCache('il_dcl_table', $set); return array('il_dcl_table' => array('ids' => $ids)); break; case 'il_dcl_table': $set = $this->db->query('SELECT * FROM il_dcl_record WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer')); $ids_records = $this->buildCache('il_dcl_record', $set); $set = $this->db->query('SELECT * FROM il_dcl_field WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer')); $ids_fields = $this->buildCache('il_dcl_field', $set); $set = $this->db->query('SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($a_rec['id'], 'integer')); $ids_views = $this->buildCache('il_dcl_view', $set); return array('il_dcl_field' => array('ids' => $ids_fields), 'il_dcl_record' => array('ids' => $ids_records), 'il_dcl_view' => array('ids' => $ids_views)); case 'il_dcl_field': $set = $this->db->query('SELECT * FROM il_dcl_field_prop WHERE field_id = ' . $this->db->quote($a_rec['id'], 'integer')); $ids = $this->buildCache('il_dcl_field_prop', $set); return array('il_dcl_field_prop' => array('ids' => $ids)); case 'il_dcl_record': $sql = 'SELECT rf.*, d.storage_location FROM il_dcl_record_field AS rf' . ' INNER JOIN il_dcl_field AS f ON (f.id = rf.field_id)' . ' INNER JOIN il_dcl_datatype AS d ON (f.datatype_id = d.id) ' . ' WHERE rf.record_id = ' . $this->db->quote($a_rec['id'], 'integer'); $set = $this->db->query($sql); $ids = $this->buildCache('il_dcl_record_field', $set); $set = $this->db->query($sql); while ($rec = $this->db->fetchObject($set)) { $this->record_field_ids_2_storage[$rec->id] = $rec->storage_location; } // Also build a cache of all values, no matter in which table they are (il_dcl_stloc(1|2|3)_value) $sql = 'SELECT rf.id AS record_field_id, st1.value AS value1, st2.value AS value2, st3.value AS value3 FROM il_dcl_record_field AS rf ' . 'LEFT JOIN il_dcl_stloc1_value AS st1 ON (st1.record_field_id = rf.id) ' . 'LEFT JOIN il_dcl_stloc2_value AS st2 ON (st2.record_field_id = rf.id) ' . 'LEFT JOIN il_dcl_stloc3_value AS st3 ON (st3.record_field_id = rf.id) ' . 'WHERE rf.record_id = ' . $this->db->quote($a_rec['id'], 'integer'); $set = $this->db->query($sql); while ($rec = $this->db->fetchObject($set)) { $stloc = $this->record_field_ids_2_storage[$rec->record_field_id]; $value = "value{$stloc}"; // Save reocrd field id. Internal ID is not used currently $this->caches["il_dcl_stloc{$stloc}_value"][$rec->record_field_id] = array('record_field_id' => $rec->record_field_id, 'value' => $rec->{$value}); } return array('il_dcl_record_field' => array('ids' => $ids)); case 'il_dcl_view': $set = $this->db->query('SELECT * FROM il_dcl_viewdefinition WHERE view_id = ' . $this->db->quote($a_rec['id'], 'integer')); $ids = $this->buildCache('il_dcl_viewdefinition', $set); return array('il_dcl_viewdefinition' => array('ids' => $ids)); case 'il_dcl_record_field': $record_field_id = $a_rec['id']; $storage_loc = $this->record_field_ids_2_storage[$record_field_id]; return array("il_dcl_stloc{$storage_loc}_value" => array('ids' => array($record_field_id))); } return false; }
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; }
/** * @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']; } }
public function loadFromDb() { $this->reset(); $res = $this->db->query("\n\t\t\tSELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode\n\t\t\tFROM qpl_qst_skl_assigns\n\t\t\tWHERE {$this->getWhereConditions()}\n\t\t"); while ($row = $this->db->fetchAssoc($res)) { $assignment = $this->buildSkillQuestionAssignmentByArray($row); if ($assignment->hasEvalModeBySolution()) { $assignment->loadComparisonExpressions(); // db query } $this->addAssignment($assignment); $this->incrementNumAssignsBySkill($assignment); $this->incrementMaxPointsBySkill($assignment); } }
/** * 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); }
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; }
/** * Query * * @param * @return */ function query($sql, $a_handle_error = true) { if (!$this->use_slave || !$this->getDBSlaveActive()) { return parent::query($sql, $a_handle_error); } $r = $this->slave->query($sql); if ($a_handle_error) { return $this->handleError($r, "query(" . $sql . ")"); } return $r; }
/** * Fetch a list of entries from the database. * * The getList() method can be used to retrieve a collection * of entries saved in the database in a given table. * * @params array $params Possible parameters indexes include: * - limit [~numeric] * - offset [~numeric] * - order_field [~string] * - order_direction [=ASC|DESC] * - group [~string] * * @param array $params * @param array $filters * @throws InvalidArgumentException * @return array with indexes 'items' and 'cnt'. */ public function getList(array $params = array(), array $filters = array()) { $data = array('items' => array(), 'cnt' => 0); $select = $this->getSelectPart(); $where = $this->getWherePart($filters); $from = $this->getFromPart(); $order = ""; $group = ""; $limit = ""; /* Build ORDER BY */ if (isset($params['order_field'])) { if (!is_string($params['order_field'])) { throw new InvalidArgumentException("Please provide a valid order field."); } if (!isset($params['order_direction'])) { /* Defaulting to ASC(ending) order. */ $params['order_direction'] = "ASC"; } elseif (!in_array(strtolower($params['order_direction']), array("asc", "desc"))) { throw new InvalidArgumentException("Please provide a valid order direction."); } $order = $params['order_field'] . ' ' . $params['order_direction']; } /* Build GROUP BY */ if (isset($params['group'])) { if (!is_string($params['group'])) { throw new InvalidArgumentException("Please provide a valid group field parameter."); } $group = $params['group']; } /* Build LIMIT */ 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; } elseif (!is_numeric($params['offset'])) { throw new InvalidArgumentException("Please provide a valid numerical offset."); } $this->db->setLimit($params['limit'], $params['offset']); } /* Build SQL query */ $query = "\n\t\t\tSELECT\n\t\t\t\t{$select}\n\t\t\tFROM\n\t\t\t\t{$from}\n\t\t\tWHERE\n\t\t\t\t{$where}\n\t\t"; if (!empty($group)) { $query .= " GROUP BY {$group}"; } if (!empty($order)) { $query .= " ORDER BY {$order}"; } /* Execute query and fetch items. */ $result = $this->db->query($query); while ($row = $this->db->fetchObject($result)) { $data['items'][] = $row; } if (isset($params['limit'])) { /* Fill 'cnt' with total count of items */ $cntSQL = "SELECT COUNT(*) cnt FROM ({$query}) subquery"; $rowCnt = $this->db->fetchAssoc($this->db->query($cntSQL)); $data['cnt'] = $rowCnt['cnt']; } return $data; }