lib/db/cortex.php
public function find($filter = NULL, array $options = NULL, $ttl = 0) {
		$sort=false;
		if ($this->dbsType!='sql') {
			// see if reordering is needed
			foreach($this->countFields?:[] as $counter) {
				if ($options && isset($options['order']) &&
					preg_match('/count_'.$counter.'\h+(asc|desc)/i',$options['order'],$match))
					$sort=true;
			}
			if ($sort) {
				// backup slice settings
				if (isset($options['limit'])) {
					$limit = $options['limit'];
					unset($options['limit']);
				}
				if (isset($options['offset'])) {
					$offset = $options['offset'];
					unset($options['offset']);
				}
			}
		}
		$this->_ttl=$ttl?:$this->rel_ttl;
		$result = $this->filteredFind($filter,$options,$ttl);
		if (empty($result))
			return false;
		foreach($result as &$record) {
			$record = $this->factory($record);
			unset($record);
		}
		// add counter for NoSQL engines
		foreach($this->countFields?:[] as $counter)
			foreach($result as &$mapper) {
				$cr=$mapper->get($counter);
				$mapper->virtual('count_'.$counter,$cr?count($cr):null);
				unset($mapper);
			}
		$cc = new CortexCollection();
		$cc->setModels($result);
		if($sort) {
			$cc->orderBy($options['order']);
			$cc->slice(isset($offset)?$offset:0,isset($limit)?$limit:NULL);
		}
		$this->clearFilter();
		return $cc;
	}
public function find($filter = NULL, array $options = NULL, $ttl = 0) {
		$sort=false;
		if ($this->dbsType!='sql') {
			// see if reordering is needed
			foreach($this->countFields?:[] as $counter) {
				if ($options && isset($options['order']) &&
					preg_match('/count_'.$counter.'\h+(asc|desc)/i',$options['order'],$match))
					$sort=true;
			}
			if ($sort) {
				// backup slice settings
				if (isset($options['limit'])) {
					$limit = $options['limit'];
					unset($options['limit']);
				}
				if (isset($options['offset'])) {
					$offset = $options['offset'];
					unset($options['offset']);
				}
			}
		}
		$this->_ttl=$ttl?:$this->rel_ttl;
		$result = $this->filteredFind($filter,$options,$ttl);
		if (empty($result))
			return false;
		foreach($result as &$record) {
			$record = $this->factory($record);
			unset($record);
		}
		// add counter for NoSQL engines
		foreach($this->countFields?:[] as $counter)
			foreach($result as &$mapper) {
				$cr=$mapper->get($counter);
				$mapper->virtual('count_'.$counter,$cr?count($cr):null);
				unset($mapper);
			}
		$cc = new CortexCollection();
		$cc->setModels($result);
		if($sort) {
			$cc->orderBy($options['order']);
			$cc->slice(isset($offset)?$offset:0,isset($limit)?$limit:NULL);
		}
		$this->clearFilter();
		return $cc;
	}
public function find ( $ filter = NULL , array $ options = NULL , $ ttl = 0 ) { $ sort = false ; if ( $ this -> dbsType != 'sql' ) { // see if reordering is needed foreach ( $ this -> countFields ? : [ ] as $ counter ) { if ( $ options && isset ( $ options [ 'order' ] ) && preg_match ( '/count_' . $ counter . '\h+(asc|desc)/i' , $ options [ 'order' ] , $ match ) ) $ sort = true ; } if ( $ sort ) { // backup slice settings if ( isset ( $ options [ 'limit' ] ) ) { $ limit = $ options [ 'limit' ] ; unset ( $ options [ 'limit' ] ) ; } if ( isset ( $ options [ 'offset' ] ) ) { $ offset = $ options [ 'offset' ] ; unset ( $ options [ 'offset' ] ) ; } } } $ this -> _ttl = $ ttl ? : $ this -> rel_ttl ; $ result = $ this -> filteredFind ( $ filter , $ options , $ ttl ) ; if ( empty ( $ result ) ) return false ; foreach ( $ result as & $ record ) { $ record = $ this -> factory ( $ record ) ; unset ( $ record ) ; } // add counter for NoSQL engines foreach ( $ this -> countFields ? : [ ] as $ counter ) foreach ( $ result as & $ mapper ) { $ cr = $ mapper -> get ( $ counter ) ; $ mapper -> virtual ( 'count_' . $ counter , $ cr ? count ( $ cr ) : null ) ; unset ( $ mapper ) ; } $ cc = new CortexCollection ( ) ; $ cc -> setModels ( $ result ) ; if ( $ sort ) { $ cc -> orderBy ( $ options [ 'order' ] ) ; $ cc -> slice ( isset ( $ offset ) ? $ offset : 0 , isset ( $ limit ) ? $ limit : NULL ) ; } $ this -> clearFilter ( ) ; return $ cc ; }
Return an array of objects matching criteria
@param array|null $filter
@param array|null $options
@param int        $ttl
@return CortexCollection
Return an array of objects matching criteria