Loads a collection from the database
@param array|int|string $condition
@return array
736
public function get($condition)
    {
        $result = null;
        $this->hook->attach('collection.get.before', $condition, $result, $this);

        if (isset($result)) {
            return $result;
        }

        if (!is_array($condition)) {
            $condition = array('collection_id' => $condition);
        }

        $condition['limit'] = array(0, 1);
        $list = (array) $this->getList($condition);
        $result = empty($list) ? array() : reset($list);

        $this->hook->attach('collection.get.after', $condition, $result, $this);
        return $result;
    }
18257
public static function findAllArray($condition = [],$orderBy = []) {
        return self::find()->where($condition)->asArray()->orderBy($orderBy)->all(static::getDb());
    }
869084
public function find( $condition ) {
		$index = $this->find_index( $condition );

		return -1 === $index ? null : $this->elements[ $index ];
	}
1051488
public static function findAll($condition = '1=1', $params = array())
    {
        /* @var $condition \mpf\datasources\sql\ModelCondition */
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        } else {
            $condition->model = $condition->model ? $condition->model : get_called_class();
        }
        $condition->setParams($params);
        $searchedRelations = [];
        if (is_array($condition->with)) {
            foreach ($condition->with as $k) {
                $searchedRelations[$k] = $k;
            }
        }
        $models = static::getDb()->queryClass($condition, get_called_class(), $condition->getParams(), [
            [
                '_columns' => static::getDb()->getTableColumns(static::getTableName()),
                '_pk' => static::getDb()->getTablePk(static::getTableName()),
                '_isNewRecord' => false,
                '_action' => 'update',
                '_tableName' => static::getTableName(),
                '_db' => static::getDb(),
                '_searchedRelations' => $searchedRelations
            ]
        ]);
        if (!$models) {
            return [];
        }
        $condition->getExtraRelations($models);
        return $models;
    }
631590
public function fetchs($condition = NULL, $params = NULL, $fields=null, $order='',$fetchMode=PDO::FETCH_ASSOC) {
		 $this->driver->field($fields)->where($condition, $params);
         $order and $this->orderby($order);
         return  $this->fetchAll($fetchMode);
	}
100963
public function load($collection = null)
    {

        $items = array();

        $list = DB::table($this->table);

        if ($collection !== null) {
            $list = $list->where('key', 'LIKE', $collection . '%');
        }

        $list = $list->pluck('value', 'key');


        // convert dotted list back to multidimensional array
        foreach ($list as $key => $value) {
            $value = json_decode($value);
            array_set($items, $key, $value);
        }

        return $items;
    }
1178817
public static function getListQuery( ?array $condition = [], $key = null, $value = null, $indexBy = true, $orderBy = true, $alias = null )
	{
		
		if( !$alias && is_subclass_of( get_called_class(), ActiveRecord::class ) ) {
			$table = Yii::$app->db->schema->getRawTableName( ( get_called_class() )::tableName() );
		}
		else if( $alias ) {
			$table = $alias;
		}
		else {
			$table = '';
		}
		
		!$table ?: $table .= '.';
		
		$key   = $key ?? static::primaryKey()[0];
		$value = $value ?? $key;
		
		$query = static::find()
		               ->select( [
			               $table . $value,
			               $table . $key,
		               ] )
		               ->andFilterWhere( $condition ?? [] )
		;
		
		if( $orderBy === true ) { //
			$query->orderBy( $table . $value );
		}
		else if( $orderBy !== false ) { //
			$query->orderBy( $table . $orderBy );
		}
		
		if( $indexBy === true ) { //
			$query->indexBy( $key );
		}
		else if( $indexBy !== false ) { //
			$query->indexBy( $indexBy );
		}
		
		return $query;
	}
53756
public static function random(array $conditions = [])
    {
        $count = static::entity()->getDatabase()->count(static::$collection, $conditions);
        if ($count === 0) {
            return null;
        }

        $data = static::find($conditions, [], 1, rand(0, $count));

        return $data[0];
    }
1279765
public function get($condition)
    {
        if (!is_array($condition)) {
            $condition = array('address_id' => $condition);
        }

        $result = &gplcart_static(gplcart_array_hash(array('address.get' => $condition)));

        if (isset($result)) {
            return $result;
        }

        $result = null;
        $this->hook->attach('address.get.before', $condition, $result, $this);

        if (isset($result)) {
            return (array) $result;
        }

        $condition['prepare'] = false;
        $condition['limit'] = array(0, 1);

        $list = (array) $this->getList($condition);
        $result = empty($list) ? array() : reset($list);

        if (isset($result['country_format'])) {
            $result['country_format'] += $this->country->getDefaultFormat();
        }

        $this->hook->attach('address.get.after', $condition, $result, $this);
        return (array) $result;
    }
600065
public function filter($condition)
    {
        $items = $this->find()->where($condition)->all();
        $this->_filter = $this->_getTreeNodesIds($items);
    }
689589
public function loadItemWithPositionData(Collection $collection, int $position): array
    {
        $query = $this->getItemSelectQuery();
        $query->where(
            $query->expr()->andX(
                $query->expr()->eq('collection_id', ':collection_id'),
                $query->expr()->eq('position', ':position')
            )
        )
        ->setParameter('collection_id', $collection->id, Type::INTEGER)
        ->setParameter('position', $position, Type::INTEGER);

        $this->applyStatusCondition($query, $collection->status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
495236
public function listDatabases($condition = [], $options = [])
    {
        if ($this->databaseName === null) {
            $this->databaseName = 'admin';
        }
        $this->document = $this->db->getQueryBuilder()->listDatabases($condition, $options);

        $cursor = $this->execute();
        $result = current($cursor->toArray());

        if (empty($result['databases'])) {
            return [];
        }
        return $result['databases'];
    }
1064265
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        $this->model->builder
            ->select('*')
            ->from($this->model->tableName);

        if ($condition) {
            $this->model->builder->where($condition, $params);
        }

        if (null !== $offset) {
            if (null === $limit) {
                $this->model->builder->limit($offset);
            } else {
                $this->model->builder->limit($offset, $limit);
            }
        }
        $r = $this->model->builder->query();
        if (!is_array($r) || 0 === count($r)) {
            return [];
        }

        return $this->model->setup($r);
    }
357387
public function filterRow(array $condition)
	{
		$this->onBeforeFilter($this->data_source);
		$this->onAfterFilter($this->data_source);

		return $this->data_source->filterOne($condition)->getData();
	}
62856
private function prepareCondition(array $condition): array
    {
        if ($condition['sql'] instanceof self) {
            list($sql, $params) = $condition['sql']->toSql();

            $condition['sql'] = $sql ? '(' . $sql . ')' : null;

            $condition['params'] = $params;
        }

        if ($condition['sql'] instanceof WhereClauseStrategy) {
            list($sql, $params) = $condition['sql']->whereToSql(false);

            $condition['sql'] = $sql ? '(' . $sql . ')' : null;

            $condition['params'] = $params;
        }

        if ($condition['sql'] instanceof HavingClauseStrategy) {
            list($sql, $params) = $condition['sql']->havingToSql(false);

            $condition['sql'] = $sql ? '(' . $sql . ')' : null;

            $condition['params'] = $params;
        }

        return $condition;
    }
780786
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        X::logger()->trace('Redis cached many');
        $key = $this->getManyKey($condition, $params, $offset, $limit);
        /** @var array $pks */
        /** @noinspection UnserializeExploitsInspection */
        $pks = @unserialize($this->redis()->get($key));
        if (is_array($pks)) {
            X::logger()->trace("Hit many $key");
            return $this->pks2models($pks);
        }

        X::logger()->trace("Miss many $key");
        return $this->manySet($key,
            DirectModelManager::getInstance($this->model)
                ->many($condition, $params, $offset, $limit)
        );
    }
498058
public function all($condition)
    {
        return ! $this->any(
            // TODO: create Not predicate class
            function ($elem, $idx) use ($condition) {
                return ! $condition($elem, $idx);
            }
        );
    }