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

		$config = static::applySiteFilters( $config );

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

		// map columns
		$nameColumn		= $config[ 'nameColumn' ] ?? 'name';
		$valueColumn	= $config[ 'valueColumn' ] ?? 'value';

		// column alias
		$nameAlias		= $config[ 'nameAlias' ] ?? 'name';
		$valueAlias		= $config[ 'valueAlias' ] ?? 'value';

		// limit
		$limit			= $config[ 'limit' ] ?? 0;

		// Query
		$query = $config[ 'query' ] ?? new Query();

		// Conditions, Filters and Sorting
		$conditions	= $config[ 'conditions' ] ?? null;
		$filters	= $config[ 'filters' ] ?? null;
		$order		= $config[ 'order' ] ?? null;

		// additional data
		$prepend		= $config[ 'prepend' ] ?? [];
		$append			= $config[ 'append' ] ?? [];

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

		$query->select( [ "$nameColumn as $nameAlias", "$valueColumn as $valueAlias" ] )
			  ->from( $modelTable );

		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 );
			}
		}

		// Sorting -------------

		if( isset( $order ) ) {

			$query->orderBy( $order );
		}

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

		if( $limit > 0 ) {

			$query->limit( $limit );
		}

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

		// Create command
		$command = $query->createCommand();

		// Execute the command
		$arrayList = $command->queryAll();

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

		// Prepend given list
		if( count( $prepend ) > 0 ) {

			$arrayList = ArrayHelper::merge( $prepend, $arrayList );
		}

		// Append given list
		if( count( $append ) > 0 ) {

			$arrayList = ArrayHelper::merge( $arrayList, $append );
		}

		return $arrayList;
	}
public static function generateNameValueList( $config = [] ) {

		$config = static::applySiteFilters( $config );

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

		// map columns
		$nameColumn		= $config[ 'nameColumn' ] ?? 'name';
		$valueColumn	= $config[ 'valueColumn' ] ?? 'value';

		// column alias
		$nameAlias		= $config[ 'nameAlias' ] ?? 'name';
		$valueAlias		= $config[ 'valueAlias' ] ?? 'value';

		// limit
		$limit			= $config[ 'limit' ] ?? 0;

		// Query
		$query = $config[ 'query' ] ?? new Query();

		// Conditions, Filters and Sorting
		$conditions	= $config[ 'conditions' ] ?? null;
		$filters	= $config[ 'filters' ] ?? null;
		$order		= $config[ 'order' ] ?? null;

		// additional data
		$prepend		= $config[ 'prepend' ] ?? [];
		$append			= $config[ 'append' ] ?? [];

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

		$query->select( [ "$nameColumn as $nameAlias", "$valueColumn as $valueAlias" ] )
			  ->from( $modelTable );

		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 );
			}
		}

		// Sorting -------------

		if( isset( $order ) ) {

			$query->orderBy( $order );
		}

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

		if( $limit > 0 ) {

			$query->limit( $limit );
		}

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

		// Create command
		$command = $query->createCommand();

		// Execute the command
		$arrayList = $command->queryAll();

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

		// Prepend given list
		if( count( $prepend ) > 0 ) {

			$arrayList = ArrayHelper::merge( $prepend, $arrayList );
		}

		// Append given list
		if( count( $append ) > 0 ) {

			$arrayList = ArrayHelper::merge( $arrayList, $append );
		}

		return $arrayList;
	}
public static function generateNameValueList ( $ config = [ ] ) { $ config = static :: applySiteFilters ( $ config ) ; $ modelClass = static :: $ modelClass ; $ modelTable = $ modelClass :: tableName ( ) ; // map columns $ nameColumn = $ config [ 'nameColumn' ] ?? 'name' ; $ valueColumn = $ config [ 'valueColumn' ] ?? 'value' ; // column alias $ nameAlias = $ config [ 'nameAlias' ] ?? 'name' ; $ valueAlias = $ config [ 'valueAlias' ] ?? 'value' ; // limit $ limit = $ config [ 'limit' ] ?? 0 ; // Query $ query = $ config [ 'query' ] ?? new Query ( ) ; // Conditions, Filters and Sorting $ conditions = $ config [ 'conditions' ] ?? null ; $ filters = $ config [ 'filters' ] ?? null ; $ order = $ config [ 'order' ] ?? null ; // additional data $ prepend = $ config [ 'prepend' ] ?? [ ] ; $ append = $ config [ 'append' ] ?? [ ] ; // Conditions ---------- $ query -> select ( [ "$nameColumn as $nameAlias" , "$valueColumn as $valueAlias" ] ) -> from ( $ modelTable ) ; 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 ) ; } } // Sorting ------------- if ( isset ( $ order ) ) { $ query -> orderBy ( $ order ) ; } // Limit --------------- if ( $ limit > 0 ) { $ query -> limit ( $ limit ) ; } // Quering ------------- // Create command $ command = $ query -> createCommand ( ) ; // Execute the command $ arrayList = $ command -> queryAll ( ) ; // Result -------------- // Prepend given list if ( count ( $ prepend ) > 0 ) { $ arrayList = ArrayHelper :: merge ( $ prepend , $ arrayList ) ; } // Append given list if ( count ( $ append ) > 0 ) { $ arrayList = ArrayHelper :: merge ( $ arrayList , $ append ) ; } return $ arrayList ; }
The method generateNameValueList returns an array of associative arrays having name and value as keys for the defined columns.
@param array $config
@return array - associative array of arrays having name and value as keys.
The method generateNameValueList returns an array of associative arrays having name and value as keys for the defined columns .