public static function search(TableCtl $controller, $term, $filter = false) { $object = call_user_func(array(get_class($controller), 'getObject')); if (!$object) { return false; } $terms = preg_split('/[ ,]/', $term); if (!count($terms)) { return false; } //Check for results containing the word $search = array(); foreach ($terms as $oneTerm) { $search[] = '`word` LIKE CONCAT("%", ?, "%")'; } //Check for results with the exact word $search[] = '`word` IN (' . implode(', ', array_fill(0, count($terms), '?')) . ')'; $search = '(' . implode(') OR (', $search) . ')'; $params = array_merge(array($object->getSource()), $terms, $terms); $query = new SelectQuery(get_called_class()); $query->field('DISTINCT `' . $object->getMeta('table') . '`.*')->leftJoin(get_class($controller), '`' . $object->getMeta('table') . '`.`' . $object->getMeta('id_field') . '` = `table_id`')->filter('`table` = ?')->filter($search)->order('`count` DESC, `sequence`'); if ($filter) { if (is_array($filter)) { foreach ($filter as $one_fil) { $query->filter($one_fil); } } else { $query->filter($filter); } } $result = $query->fetchAll($params); return $result; }
public function getConnection() { $q = new SelectQuery(); $this->assertNull($q->getConnection()); $q->setPeer(Job::getPeer()); $this->assertClass($q->getConnection(), 'net.xp_framework.unittest.rdbms.mock.MockConnection'); }
/** * Alter the term DB query. * * @param SelectQuery $query * The query object ot alter. */ function hook_query_rules_autotag_terms_alter($query) { // Join the original term query from rules_autotag with our field table to // exclude terms that should not be tagged. $query->leftJoin('field_data_field_dont_autotag', 'fd', "t.tid = fd.entity_id AND fd.entity_type = 'taxonomy_term'"); $query->condition(db_or()->condition('fd.field_dont_autotag_value', NULL)->condition('fd.field_dont_autotag_value', '1', '<>')); }
public static function check() { if (!empty($_COOKIE['remembered'])) { $query = new SelectQuery('PersistUser'); $persist = $query->filter('MD5(CONCAT(`id`, `user_id`, `random`)) = :hash')->fetchAssoc(array(':hash' => $_COOKIE['remembered'])); if ($persist) { //Get User $User = self::getObject('BackendUser'); if (!$User instanceof DBObject) { return false; } $query = BackendUser::getQuery(); $query->filter('`backend_users`.`id` = :id'); $params = array(':id' => $persist['user_id']); $User->read(array('query' => $query, 'parameters' => $params, 'mode' => 'object')); if ($User->object) { $_SESSION['BackendUser'] = $User->object; //Remove, and reremember if (self::remember($User->object)) { $query = new DeleteQuery('PersistUser'); $query->filter('`id` = :id')->limit(1); $query->execute(array(':id' => $persist['id'])); } else { Backend::addError('Could not reremember'); } return $User->object; } else { //Backend::addError('Invalid remembered user'); } } } return false; }
/** * @return string */ private function getToJoin() { if ($this->tojoin instanceof SelectQuery || $this->tojoin instanceof UnionQuery) { return " (" . $this->tojoin->get(false) . ")"; } else { return " " . $this->tojoin; } }
/** * @return SelectQuery **/ protected function joinHelperTable(SelectQuery $query) { $uc = $this->container; if (!$query->hasJoinedTable($uc->getHelperTable())) { $query->join($uc->getHelperTable(), Expression::eq(new DBField($uc->getParentTableIdField(), $uc->getDao()->getTable()), new DBField($uc->getChildIdField(), $uc->getHelperTable()))); } return $query->andWhere(Expression::eq(new DBField($uc->getParentIdField(), $uc->getHelperTable()), new DBValue($uc->getParentObject()->getId()))); }
/** * (non-PHPdoc) * @see IQuery::get() */ public function get($end = true) { $return = "(" . $this->firstQuery->get(false) . ")" . self::UNION . "(" . $this->secondQuery->get(false) . ")"; if ($this->hasOrderBy()) { $return .= $this->getOrderBy(); } return $return . $this->getEnd($end); }
public function action_create() { if (is_post()) { $parameters = get_previous_parameters(); $object = new CommentObj(); $object = $object->fromRequest(); $object['foreign_id'] = empty($object['foreign_id']) ? reset($parameters) : $object['foreign_id']; $object['foreign_table'] = empty($object['foreign_table']) ? table_name(get_previous_area()) : $object['foreign_table']; //If we don't have a logged in user, create a dummy account if (!BackendUser::check()) { $query = new SelectQuery('BackendUser'); $query->filter('`email` = :email'); if ($old_user = Controller::getVar('user')) { $existing_user = $query->fetchAssoc(array(':email' => $old_user['email'])); } switch (true) { case $existing_user && $existing_user['confirmed'] && $existing_user['active']: //Attribute quote to user? Seems risque, actually, if I know a user's email address, I can just attribute to him. Auth first Backend::addError('Comment not added. Please login first'); return false; break; case $existing_user && !$existing_user['confirmed'] && $existing_user['active']: //Unregistered user commented before $object['user_id'] = $existing_user['id']; break; default: case !$existing_user: $user_data = array('name' => $old_user['name'], 'surname' => '', 'email' => $old_user['email'], 'website' => $old_user['website'], 'username' => $old_user['email'], 'password' => get_random(), 'confirmed' => 0, 'active' => 1); $user = self::getObject('BackendUser'); if ($user->create($user_data)) { $object['user_id'] = $user->array['id']; $url = SITE_LINK . '/?q=backend_user/confirm/' . $user->array['salt']; $app_name = ConfigValue::get('Title'); $message = <<<END Hi {$user->array['name']}! Thank you for your comment on {$app_name}. An account has automatically been created for you. To activate it, please click on the following link: {$url} Please note that you don't need to do this for your comments to show, but this account will be deleted if it isn't confirmed in a weeks time. Regards END; send_email($user->array['email'], 'Thank you for your comment.', $message); } else { Backend::addError('Could not create user to add Comment'); return false; } break; } } $object = array_filter($object, create_function('$var', 'return !is_null($var);')); Controller::setVar('obj', $object); } return parent::action_create(); }
public function action_filter($pageId = 1) { $query = new SelectQuery('BackendRequest'); $query->setFields(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query', 'COUNT(id) AS `occured`', 'MAX(`added`) AS `last_occured`')); $query->setGroup(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query')); $params = $queryFilter = array(); $parameters = Controller::getVar('params'); $sort = Controller::getVar('sort'); if (!empty($parameters['userId'])) { $queryFilter[] = 'user_id = :userId'; $params[':userId'] = $parameters['userId']; } if (!empty($parameters['query'])) { $queryFilter[] = "query LIKE('%{$parameters['query']}%')"; } if (!empty($parameters['ip'])) { $queryFilter[] = "ip LIKE('%{$parameters['ip']}%')"; } if (!empty($parameters['user_agent'])) { $queryFilter[] = "user_agent LIKE('%{$parameters['user_agent']}%')"; } $query->filter($queryFilter); $count = 10; if (!empty($sort['field'])) { $query->setOrder(array($sort['field'] . ' ' . $sort['order'])); } if ($pageId == 1) { $start = 0; } elseif ($pageId == 0) { $start = false; $count = false; } else { $start = floor(($pageId - 1) * $count); } $pager = array(); if ($start === 'all') { $limit = 'all'; } else { if ($start || $count) { $limit = "{$start}, {$count}"; } else { $limit = false; } } $query->limit($limit); $items = $query->fetchAll($params); $totalItems = $query->getCount($params); $pager = ''; if ($start || $count) { $pager = array('currentPage' => $pageId, 'itemCount' => count($items), 'itemTotal' => $totalItems, 'totalPages' => round(($totalItems - 1) / $count, 0)); } $retArray['pager'] = $pager; $retArray['data'] = $items; $retArray['params'] = $parameters; $retArray['sort'] = $sort; return $retArray; }
public function action_check_defines() { if (!Component::isActive('BackendError')) { return false; } $query = new SelectQuery('BackendError'); $query->distinct()->field('query')->filter("`string` LIKE 'Undefined index: %'")->filter("`file` LIKE '%\\\\Render.obj.php(%) : eval()\\'d code'")->filter("`query` LIKE 'a_p_i/define/%'"); return $query->fetchAll(array(), array('column' => 0)); }
/** Create SELECT query from $table * @param string $table db table name * @param integer $primaryKey return one row by primary key * @return SelectQuery */ public function from($table, $primaryKey = null) { $query = new SelectQuery($this, $table); if ($primaryKey) { $tableTable = $query->getFromTable(); $tableAlias = $query->getFromAlias(); $primaryKeyName = $this->structure->getPrimaryKey($tableTable); $query = $query->where("{$tableAlias}.{$primaryKeyName}", $primaryKey); } return $query; }
public function process(\SelectQuery $query) { $result = $query->limit($this->options['limit'])->offset($this->options['page'] * $this->options['limit'])->fetchAll(); $this->count = count($result); // Check to see if total is equal to our limit and check for the real total if ($this->options['page'] || $this->count == $this->options['limit']) { $this->total = (int) $query->limit(null)->offset(null)->select(null)->select('COUNT(*)')->fetchColumn(); } else { $this->total = $this->count; } return $result; }
public function action_display($id) { $query = new SelectQuery('ContentRevision'); $query->filter('`content_id` = :id')->order('`added` DESC'); $revisions = $query->fetchAll(array(':id' => $id)); $content = new ContentObj($id); if ($content->object) { $content->object->revisions = $revisions; } else { $content = false; } return $content; }
protected function cacheByQuery(SelectQuery $query, $object, $expires = Cache::EXPIRES_FOREVER) { $queryId = $query->getId(); $semKey = $this->keyToInt($this->indexKey); $key = $this->makeQueryKey($query, self::SUFFIX_QUERY); $pool = SemaphorePool::me(); if ($pool->get($semKey)) { $this->syncMap($key); Cache::me()->mark($this->className)->add($key, $object, $expires); $pool->free($semKey); } return $object; }
/** * Initialize this object for a set of authentication tokens. Set the * password to the encrypted version. * * @param mixed $tokens * @return void * @access public * @since 3/1/05 */ function initializeForTokens($tokens) { ArgumentValidator::validate($tokens, ArrayValidatorRule::getRule()); ArgumentValidator::validate($tokens['username'], StringValidatorRule::getRule()); ArgumentValidator::validate($tokens['password'], StringValidatorRule::getRule()); $this->_tokens = $tokens; $this->_identifier = $tokens['username']; // set the password to the encrypted version. $dbc = Services::getService("DatabaseManager"); $dbId = $this->_configuration->getProperty('database_id'); $passwordQuery = new SelectQuery(); $passwordQuery->addColumn("SHA1('" . addslashes($tokens['password']) . "')", "encryptedPassword"); $passwordResult = $dbc->query($passwordQuery, $dbId); $this->_tokens['password'] = $passwordResult->field("encryptedPassword"); $passwordResult->free(); }
/** * Answer an array of all of the themes known to this source * * @return array of Harmoni_Gui2_ThemeInterface * @access public * @since 5/6/08 */ public function getThemes() { $themes = array(); $query = new SelectQuery(); $query->addTable('segue_site_theme'); $query->addColumn('id'); $query->addWhereEqual('fk_site', $this->getSiteId()); $dbMgr = Services::getService("DatabaseManager"); $result = $dbMgr->query($query, $this->databaseIndex); while ($result->hasNext()) { $row = $result->next(); $themes[] = new Segue_Gui2_SiteTheme($this->databaseIndex, $row['id']); } $result->free(); return $themes; }
public function execute() { $cache_key = MemoryObjectStore::gen_key(array($this->build_sql(), $this->build_sql_values())); if (!$this->reload) { $cache = MemoryObjectStore::get($cache_key); } if (!empty($cache)) { return $cache; } else { $result = parent::execute(); if (is_array($result)) { foreach ($result as $result_key => $result_val) { foreach ($this->additions as $key => $val) { $result[$result_key]->{$key} = $val; } } } else { foreach ($this->additions as $key => $val) { $result->{$key} = $val; } } MemoryObjectStore::put($cache_key, $result); } return $result; }
public function read($options = array()) { $result = parent::read($options); if ($result) { $query = new SelectQuery('Assignment'); $query->distinct()->field('`roles`.`name`')->leftJoin('Role', '`roles`.`id` = `assignments`.`role_id`')->filter("`assignments`.`access_type` = 'users'")->filter('`assignments`.`access_id` = :user_id OR `assignments`.`access_id` = 0')->order('`roles`.`name`'); $roles = $query->fetchAll(array(':user_id' => $this->getMeta('id')), array('column' => 0)); $roles = empty($roles) ? array() : $roles; if ($this->object) { $this->object->roles = $roles; } if ($this->array) { $this->array['roles'] = $roles; } } return $result; }
/** * Constructor. * @param object Id $setId The Id of this set. * @param integer $dbIndex The index of the database connection which has * tables in which to store the set. */ function PersistentOrderedSet($setId, $dbIndex) { parent::OrderedSet($setId); ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true); // Create our internal array $this->_dbIndex = $dbIndex; // populate our array with any previously stored items. $query = new SelectQuery(); $query->addColumn("item_order", "item_order"); $query->addColumn("item_id", "item_id"); $query->addTable("sets"); $query->addWhere("id = '" . addslashes($this->_setId->getIdString()) . "'"); $query->addOrderBy("item_order"); $dbHandler = Services::getService("DatabaseManager"); $result = $dbHandler->query($query, $this->_dbIndex); $i = 0; $oldItems = array(); while ($result->hasMoreRows()) { // Add the items to our array $this->_items[$i] = $result->field("item_id"); // Store an array of the order-key/value relationships to reference // when updating any inconsistancies in order numbering. $oldItems[$result->field("item_order")] = $result->field("item_id"); $i++; $result->advanceRow(); } $result->free(); // Make sure that we have our set is filled from 0 to count() reset($oldItems); $this->_updateOrders($oldItems); }
/** * Since the agent manager package already has support for filtering agents and * groups from traversal info iterators, return our search results as traversal * info. * * @param string $criteria * @return TraversalInfoIterator * @access protected * @since 1/31/08 */ protected function getMatching($criteria) { $dbc = Services::getService('DatabaseManager'); $idMgr = Services::getService('Id'); $query = new SelectQuery(); $query->addTable('agent_properties'); $query->addColumn("DISTINCT fk_object_id", "agent_id"); $query->addWhereLike("property_value", str_replace('*', '%', $criteria)); $info = array(); $result = $dbc->query($query, $this->databaseIndex); while ($result->hasNext()) { $row = $result->next(); if (!strlen($row['agent_id'])) { throw new OperationFailedException("No valid agent_id found in row for query: " . $query->asString()); } $info[] = new HarmoniTraversalInfo($idMgr->getId($row['agent_id']), '', 0); } return new HarmoniTraversalInfoIterator($info); }
/** * {@inheritdoc} */ public function getQueryParameters() { $parameters = parent::getQueryParameters(); $modificator = $this->getModificator(); if ($this->isSuffics()) { $modificator .= '?'; } $parameters[] = $modificator; return $parameters; }
/** * Answer the PartStructure Ids for which Tags should be auto-generated, in * the given repository. * * @param object Id $repositoryId * @return object IdIterator * @access public * @since 11/21/06 */ function getPartStructureIdsForTagGeneration($repositoryId) { if (!isset($this->_cache[$repositoryId->getIdString()])) { $this->_cache[$repositoryId->getIdString()] = array(); $query = new SelectQuery(); $query->addColumn('fk_partstruct'); $query->addTable('tag_part_map'); $query->addWhere("fk_repository ='" . addslashes($repositoryId->getIdString()) . "'"); $dbc = Services::getService("DatabaseManager"); $result = $dbc->query($query, $this->getDatabaseIndex()); // Add tag objects to an array, still sorted by frequency of usage $idManager = Services::getService('Id'); while ($result->hasNext()) { $row = $result->next(); $this->_cache[$repositoryId->getIdString()][] = $idManager->getId($row['fk_partstruct']); } } $iterator = new HarmoniIterator($this->_cache[$repositoryId->getIdString()]); return $iterator; }
function toSql(SelectQuery $obj) { $_string = $obj->__toString(); $_conditions = $obj->conditions(); $_tables = $obj->getTables(); $_fields = $obj->getFields(); foreach ($_tables as $k => $t) { if (!empty($t['alias'])) { $_string = str_replace('{' . $t['table'] . '}', $t['table'] . ' as', $_string); } else { $_string = str_replace('{' . $t['table'] . '}', $t['table'], $_string); } } foreach ($_conditions as $k => $c) { if (is_int($c['value'])) { $_string = str_replace(':db_condition_placeholder_' . $k, $c['value'], $_string); } else { $_string = str_replace(':db_condition_placeholder_' . $k, "'" . $c['value'] . "'", $_string); } } return $_string; }
protected function toDialectStringSelect($query, Dialect $dialect) { $fields = array(); foreach ($this->fields as $var => $val) { $fields[] = $dialect->quoteField($var); } if (!$fields) { throw new WrongStateException('what should i insert?'); } if ($this->select->getFieldsCount() != count($fields)) { throw new WrongStateException('count of select fields must be equal with count of insert fields'); } $fields = implode(', ', $fields); return $query . "({$fields}) (" . $this->select->toDialectString($dialect) . ")"; }
/** * Get query * * @return \SelectQueryInterface $query */ public final function getQuery() { if (null === $this->query) { $this->query = $this->buildQuery(); // Apply conditions. foreach ($this->conditions as $statement => $value) { $this->applyOperator($this->query, $statement, $value); } $limit = $this->getLimit(); if (CursorInterface::LIMIT_NONE !== $limit) { $this->query->range($this->getOffset(), $limit); } } return $this->query; }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { ArgumentValidator::validate($value, StringValidatorRule::getRule()); // Store the size in the object in case its asked for again. try { $size = ByteSize::fromString($value); } catch (InvalidArgumentException $e) { $size = ByteSize::withValue(0); } $this->_size = $size->value(); // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // Check to see if the name is in the database $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("size")); $query->setValues(array("'" . addslashes($this->_size) . "'")); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->setColumns(array("id", "size")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Overrides SelectQuery::orderBy(). * * PostgreSQL adheres strictly to the SQL-92 standard and requires that when * using DISTINCT or GROUP BY conditions, fields and expressions that are * ordered on also need to be selected. This is a best effort implementation * to handle the cases that can be automated by adding the field if it is not * yet selected. * * @code * $query = db_select('node', 'n'); * $query->join('node_revision', 'nr', 'n.vid = nr.vid'); * $query * ->distinct() * ->fields('n') * ->orderBy('timestamp'); * @endcode * * In this query, it is not possible (without relying on the schema) to know * whether timestamp belongs to node_revisions and needs to be added or * belongs to node and is already selected. Queries like this will need to be * corrected in the original query by adding an explicit call to * SelectQuery::addField() or SelectQuery::fields(). * * Since this has a small performance impact, both by the additional * processing in this function and in the database that needs to return the * additional fields, this is done as an override instead of implementing it * directly in SelectQuery::orderBy(). */ public function orderBy($field, $direction = 'ASC') { // Call parent function to order on this. $return = parent::orderBy($field, $direction); // If there is a table alias specified, split it up. if (strpos($field, '.') !== FALSE) { list($table, $table_field) = explode('.', $field); } // Figure out if the field has already been added. foreach ($this->fields as $existing_field) { if (!empty($table)) { // If table alias is given, check if field and table exists. if ($existing_field['table'] == $table && $existing_field['field'] == $table_field) { return $return; } } else { // If there is no table, simply check if the field exists as a field or // an aliased field. if ($existing_field['alias'] == $field) { return $return; } } } // Also check expression aliases. foreach ($this->expressions as $expression) { if ($expression['alias'] == $field) { return $return; } } // If a table loads all fields, it can not be added again. It would // result in an ambigious alias error because that field would be loaded // twice: Once through table_alias.* and once directly. If the field // actually belongs to a different table, it must be added manually. foreach ($this->tables as $table) { if (!empty($table['all_fields'])) { return $return; } } // If $field contains an characters which are not allowed in a field name // it is considered an expression, these can't be handeld automatically // either. if ($this->connection->escapeField($field) != $field) { return $return; } // This is a case that can be handled automatically, add the field. $this->addField(NULL, $field); return $return; }
/** * Finishes the query. * * Adds tags, metaData, range and returns the requested list or count. * * @param SelectQuery $select_query * A SelectQuery which has entity_type, entity_id, revision_id and bundle * fields added. * @param $id_key * Which field's values to use as the returned array keys. * * @return * See EntityFieldQuery::execute(). */ function finishQuery($select_query, $id_key = 'entity_id') { foreach ($this->tags as $tag) { $select_query->addTag($tag); } foreach ($this->metaData as $key => $object) { $select_query->addMetaData($key, $object); } $select_query->addMetaData('entity_field_query', $this); if ($this->range) { $select_query->range($this->range['start'], $this->range['length']); } if ($this->count) { return $select_query->countQuery()->execute()->fetchField(); } $return = array(); foreach ($this->fields as $key => $field) { if ('field_sql_storage' == $field['storage']['type']) { foreach ($select_query->conditions() as $condition) { if (is_array($condition) && array_key_exists('field', $condition) && strpos($condition['field'], 'field_data_' . $field['field_name'] . $key . '.') === 0) { list($table_alias, $column) = explode('.', $condition['field']); $select_query->addField($table_alias, $column, $field['field_name']); break; } } } } $this->orderedResults = array(); foreach ($select_query->execute() as $partial_entity) { $bundle = isset($partial_entity->bundle) ? $partial_entity->bundle : NULL; $entity = entity_create_stub_entity($partial_entity->entity_type, array($partial_entity->entity_id, $partial_entity->revision_id, $bundle)); $return[$partial_entity->entity_type][$partial_entity->{$id_key}] = $entity; $this->orderedResults[] = $partial_entity; } return $return; }
/** * Will load the data structures for multiple {@link Schema}s. * @param ref object An array containing the list of types IDs to be loaded. * @return void * @access public */ function loadMultiple($preloadTypes) { $ids = $preloadTypes; if (count($ids)) { // let's do it $query = new SelectQuery(); $query->addTable("dm_schema_field"); $query->addColumn("id", "id", "dm_schema_field"); $query->addColumn("name", "label", "dm_schema_field"); $query->addColumn("mult", "mult", "dm_schema_field"); $query->addColumn("required", "required", "dm_schema_field"); $query->addColumn("active", "active", "dm_schema_field"); $query->addColumn("fieldtype", "fieldtype", "dm_schema_field"); $query->addColumn("fk_schema", "fk_schema", "dm_schema_field"); $wheres = array(); foreach ($ids as $id) { $wheres[] = "fk_schema='" . addslashes($id) . "'"; } $query->setWhere("(" . implode(" OR ", $wheres) . ")"); // print "<PRE>".MySQL_SQLGenerator::generateSQLQuery($query)."</PRE>"; $dbHandler = Services::getService("DatabaseManager"); $res = $dbHandler->query($query, DATAMANAGER_DBID); $rows = array(); while ($res->hasMoreRows()) { $row = $res->getCurrentRow(); $res->advanceRow(); $theID = $row["fk_schema"]; if (!isset($rows[$theID])) { $rows[$theID] = array(); } $rows[$theID][] = $row; } $res->free(); // printpre($rows); // now distribute the rows among their respective objects foreach (array_keys($rows) as $id) { $obj = $this->getSchema($id); if (!$obj->loaded()) { $obj->populate($rows[$id]); } } } }
public static function get($hook, $type = 'pre') { if (!BACKEND_WITH_DATABASE) { return false; } $params = array(':type' => $type, ':hook' => $hook); $query = new SelectQuery('Hook'); $query->leftJoin('Component', array('`hooks`.`class` = `components`.`name`'))->filter('`hooks`.`hook` = :hook')->filter('`hooks`.`type` = :type')->filter('`hooks`.`active` = 1')->filter('`components`.`active` = 1'); if (Controller::$area) { $query->filter('`global` = 1 OR `class` = :area'); $params[':area'] = Controller::$area; } if (Controller::$view && Controller::$view->mode) { $query->filter('`mode` IN (:mode, \'*\')'); $params[':mode'] = Controller::$view->mode; } $query->order('`sequence`'); return $query->fetchAll($params); }