common/services/base/ActiveRecordService.php
public static function searchModels( $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable = $modelClass::tableName();

		// Filters
		$config	= static::applyPublicFilters( $config );
		$config	= static::applySiteFilters( $config );

		// Generate Query
		$query			= $config[ 'query' ] ?? $modelClass::find();
		$offset			= $config[ 'offset' ] ?? 0;
		$limit			= $config[ 'limit' ] ?? self::PAGE_LIMIT;
		$conditions		= $config[ 'conditions' ] ?? null;
		$filters		= $config[ 'filters' ] ?? null;
		$sort			= $config[ 'sort' ] ?? [ 'id' => SORT_DESC ]; // Show latest first
		$public			= $config[ 'public' ] ?? false;

		// Result Columns
		$columns = $config[ 'columns' ] ?? [];

		// Array Result
		$array = $config[ 'array' ] ?? false;

		// Selective columns ---

		if( count( $columns ) > 0 ) {

			$query->select( $columns );
		}

		// Conditions ----------

		if( isset( $conditions ) ) {

			foreach( $conditions as $ckey => $condition ) {

				if( is_numeric( $ckey ) ) {

					$query->andWhere( $condition );

					unset( $conditions[ $ckey ] );
				}
			}

			$query->andWhere( $conditions );
		}

		$interfaces = class_implements( static::class );

		if( isset( $interfaces[ 'cmsgears\core\common\services\interfaces\base\IApproval' ] ) ) {

			$statusFilter = $modelClass::STATUS_TERMINATED;

			$query->andWhere( "$modelTable.status<$statusFilter" );
		}

		// Filters -------------

		if( isset( $filters ) ) {

			foreach( $filters as $filter ) {

				$query->andFilterWhere( $filter );
			}
		}

		// Offset --------------

		if( $offset > 0 ) {

			$query->offset( $offset );
		}

		// Limit ---------------

		if( $limit > 0 ) {

			$query->limit( $limit );
		}

		// Sort -----------------

		if( count( $sort ) > 0 ) {

			$query->orderBy( $sort );
		}

		// Print to Debug -------

		if( isset( $config[ 'pquery' ] ) && $config[ 'pquery' ] ) {

			$command = $query->createCommand();

			var_dump( $command );
		}

		// Models ---------------

		if( $array ) {

			$models = $query->asArray( $array )->all();
		}
		else {

			$models = $query->all();
		}

		return $models;
	}
public static function searchModels( $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable = $modelClass::tableName();

		// Filters
		$config	= static::applyPublicFilters( $config );
		$config	= static::applySiteFilters( $config );

		// Generate Query
		$query			= $config[ 'query' ] ?? $modelClass::find();
		$offset			= $config[ 'offset' ] ?? 0;
		$limit			= $config[ 'limit' ] ?? self::PAGE_LIMIT;
		$conditions		= $config[ 'conditions' ] ?? null;
		$filters		= $config[ 'filters' ] ?? null;
		$sort			= $config[ 'sort' ] ?? [ 'id' => SORT_DESC ]; // Show latest first
		$public			= $config[ 'public' ] ?? false;

		// Result Columns
		$columns = $config[ 'columns' ] ?? [];

		// Array Result
		$array = $config[ 'array' ] ?? false;

		// Selective columns ---

		if( count( $columns ) > 0 ) {

			$query->select( $columns );
		}

		// Conditions ----------

		if( isset( $conditions ) ) {

			foreach( $conditions as $ckey => $condition ) {

				if( is_numeric( $ckey ) ) {

					$query->andWhere( $condition );

					unset( $conditions[ $ckey ] );
				}
			}

			$query->andWhere( $conditions );
		}

		$interfaces = class_implements( static::class );

		if( isset( $interfaces[ 'cmsgears\core\common\services\interfaces\base\IApproval' ] ) ) {

			$statusFilter = $modelClass::STATUS_TERMINATED;

			$query->andWhere( "$modelTable.status<$statusFilter" );
		}

		// Filters -------------

		if( isset( $filters ) ) {

			foreach( $filters as $filter ) {

				$query->andFilterWhere( $filter );
			}
		}

		// Offset --------------

		if( $offset > 0 ) {

			$query->offset( $offset );
		}

		// Limit ---------------

		if( $limit > 0 ) {

			$query->limit( $limit );
		}

		// Sort -----------------

		if( count( $sort ) > 0 ) {

			$query->orderBy( $sort );
		}

		// Print to Debug -------

		if( isset( $config[ 'pquery' ] ) && $config[ 'pquery' ] ) {

			$command = $query->createCommand();

			var_dump( $command );
		}

		// Models ---------------

		if( $array ) {

			$models = $query->asArray( $array )->all();
		}
		else {

			$models = $query->all();
		}

		return $models;
	}
public static function searchModels ( $ config = [ ] ) { $ modelClass = static :: $ modelClass ; $ modelTable = $ modelClass :: tableName ( ) ; // Filters $ config = static :: applyPublicFilters ( $ config ) ; $ config = static :: applySiteFilters ( $ config ) ; // Generate Query $ query = $ config [ 'query' ] ?? $ modelClass :: find ( ) ; $ offset = $ config [ 'offset' ] ?? 0 ; $ limit = $ config [ 'limit' ] ?? self :: PAGE_LIMIT ; $ conditions = $ config [ 'conditions' ] ?? null ; $ filters = $ config [ 'filters' ] ?? null ; $ sort = $ config [ 'sort' ] ?? [ 'id' => SORT_DESC ] ; // Show latest first $ public = $ config [ 'public' ] ?? false ; // Result Columns $ columns = $ config [ 'columns' ] ?? [ ] ; // Array Result $ array = $ config [ 'array' ] ?? false ; // Selective columns --- if ( count ( $ columns ) > 0 ) { $ query -> select ( $ columns ) ; } // Conditions ---------- if ( isset ( $ conditions ) ) { foreach ( $ conditions as $ ckey => $ condition ) { if ( is_numeric ( $ ckey ) ) { $ query -> andWhere ( $ condition ) ; unset ( $ conditions [ $ ckey ] ) ; } } $ query -> andWhere ( $ conditions ) ; } $ interfaces = class_implements ( static :: class ) ; if ( isset ( $ interfaces [ 'cmsgears\core\common\services\interfaces\base\IApproval' ] ) ) { $ statusFilter = $ modelClass :: STATUS_TERMINATED ; $ query -> andWhere ( "$modelTable.status<$statusFilter" ) ; } // Filters ------------- if ( isset ( $ filters ) ) { foreach ( $ filters as $ filter ) { $ query -> andFilterWhere ( $ filter ) ; } } // Offset -------------- if ( $ offset > 0 ) { $ query -> offset ( $ offset ) ; } // Limit --------------- if ( $ limit > 0 ) { $ query -> limit ( $ limit ) ; } // Sort ----------------- if ( count ( $ sort ) > 0 ) { $ query -> orderBy ( $ sort ) ; } // Print to Debug ------- if ( isset ( $ config [ 'pquery' ] ) && $ config [ 'pquery' ] ) { $ command = $ query -> createCommand ( ) ; var_dump ( $ command ) ; } // Models --------------- if ( $ array ) { $ models = $ query -> asArray ( $ array ) -> all ( ) ; } else { $ models = $ query -> all ( ) ; } return $ models ; }
Advanced findModels having more options to search.
Advanced findModels having more options to search .