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

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

		// map columns
		$key	= $config[ 'key' ] ?? 'id';
		$value	= static::$modelClass;

		// query generation
		$query		= $config[ 'query' ] ?? $value::find();
		$limit		= $config[ 'limit' ] ?? self::PAGE_LIMIT;
		$conditions	= $config[ 'conditions' ] ?? null;
		$filters	= $config[ 'filters' ] ?? null;

		// 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	= $query->andFilterWhere( $filter );
			}
		}

		// Quering -------------

		$objects = $query->all();

		// Result --------------

		$map = [];

		foreach( $objects as $object ) {

			$map[ $object->$key ] = $object;
		}

		return $map;
	}
public static function generateObjectMap( $config = [] ) {

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

		// map columns
		$key	= $config[ 'key' ] ?? 'id';
		$value	= static::$modelClass;

		// query generation
		$query		= $config[ 'query' ] ?? $value::find();
		$limit		= $config[ 'limit' ] ?? self::PAGE_LIMIT;
		$conditions	= $config[ 'conditions' ] ?? null;
		$filters	= $config[ 'filters' ] ?? null;

		// 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	= $query->andFilterWhere( $filter );
			}
		}

		// Quering -------------

		$objects = $query->all();

		// Result --------------

		$map = [];

		foreach( $objects as $object ) {

			$map[ $object->$key ] = $object;
		}

		return $map;
	}
public static function generateObjectMap ( $ config = [ ] ) { $ modelClass = static :: $ modelClass ; $ modelTable = $ modelClass :: tableName ( ) ; // map columns $ key = $ config [ 'key' ] ?? 'id' ; $ value = static :: $ modelClass ; // query generation $ query = $ config [ 'query' ] ?? $ value :: find ( ) ; $ limit = $ config [ 'limit' ] ?? self :: PAGE_LIMIT ; $ conditions = $ config [ 'conditions' ] ?? null ; $ filters = $ config [ 'filters' ] ?? null ; // 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 = $ query -> andFilterWhere ( $ filter ) ; } } // Quering ------------- $ objects = $ query -> all ( ) ; // Result -------------- $ map = [ ] ; foreach ( $ objects as $ object ) { $ map [ $ object -> $ key ] = $ object ; } return $ map ; }
The method findObjectMap returns an associative array for the defined table and columns. It also apply the provided conditions.
@param array $config
The method findObjectMap returns an associative array for the defined table and columns . It also apply the provided conditions .