/** * 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; } }
/** * 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(); }
/** * 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; }
/** * 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; }