@param array $rows
@param $returnType

@return array
548532
private function buildEventAggregate(array $rows, $returnType)
    {
        if ($returnType === self::RETURN_AS_ARRAY) {
            return $this->buildEventAggregateAsArray($rows);
        }

        return $this->buildEventAggregateAsObject($rows);
    }
846101
public function getTimestamp($returnType = 'string')
    {
        if (in_array($returnType, ['array', 'float', 'string'])) {
            return $this->getTimestampRaw($returnType);
        }
        return sprintf($this->lclMsgCmn('i18n_Error_UnknownReturnType'), $returnType);
    }
1093496
public function search(SearchQuery $searchQuery, $returnType = BaseSearch::SEARCH_RESULT)
    {
        $response = static::newResponse($returnType);

        /** @var yii\db\ActiveRecord|SearchableEntity $mainEntityClassName */
        $mainEntityClassName = $searchQuery->mainEntityClassName;

        $activeQuery = $mainEntityClassName::find();

        $success = false;

        // combine query
        $e = new SearchEvent(
            $searchQuery,
            $returnType,
            $response,
            [
                'params' => [
                    'activeQuery' => &$activeQuery,
                ],
            ]
        );
        $this->trigger(self::EVENT_BEFORE_PAGINATION, $e);

        // Pagination
        $pages = $searchQuery->getPagination();
        if ($returnType !== BaseSearch::SEARCH_COUNT && $pages !== null) {
            if ($pages->totalCount === 0) {
                $pages->totalCount = (int) $activeQuery->count();
            }
            $searchQuery->limit = $pages->limit;
            $searchQuery->offset = $pages->offset;
        }

        $e = new SearchEvent(
            $searchQuery,
            $returnType,
            $response,
            [
                'params' => [
                    'activeQuery' => &$activeQuery,
                    'pages' => $pages,
                ],
            ]
        );
        $this->trigger(self::EVENT_AFTER_PAGINATION, $e);

        $response->searchQuery = $searchQuery;

        switch ($returnType) {
            case BaseSearch::SEARCH_COUNT:
                /** @var CountResponse $response */
                $response->count = (int) $activeQuery->count();
                $success = true;
                break;
            case BaseSearch::SEARCH_QUERY:
                /** @var QueryResponse $response */
                $response->query = $activeQuery;
                $success = true;
                break;
            case BaseSearch::SEARCH_RESULT_ARRAY:
            case BaseSearch::SEARCH_RESULT:
                /** @var ResultResponse $response */
                // query for debug
                $response->query = $activeQuery;
                if (is_object($pages)) {
                    $response->pages = $pages;
                }
                if ($returnType === BaseSearch::SEARCH_RESULT_ARRAY) {
                    $activeQuery->asArray(true);
                }
                $response->entities = $activeQuery->all();
                $e = new SearchEvent(
                    $searchQuery,
                    $returnType,
                    $response,
                    [
                        'params' => [
                            'activeQuery' => &$activeQuery,
                        ],
                    ]
                );
                $this->trigger(self::EVENT_AFTER_FIND, $e);
                $success = true;
                break;
            case BaseSearch::SEARCH_IDS:
                /** @var IdsResponse $response */
                $activeQuery->select(
                    array_map(
                        function ($item) use ($mainEntityClassName) {
                            return $mainEntityClassName::tableName() . '.' . $item;
                        },
                        $mainEntityClassName::primaryKey()
                    )
                );
                $response->ids = $activeQuery
                    ->distinct(true)
                    ->asArray(true)
                    ->column();
                $response->query = $activeQuery;
                $success = true;
                break;
        }

        return $response->end($success);
    }
1060601
public function findOneWhere($criteria, $returnType = Table::RETURN_MODEL) {
        $this->limit(1);
        $result = $this->findWhere($criteria, $returnType);
        if (is_array($result)) {
            $result = array_values($result);
            return ($returnType === Table::RETURN_JSON) ? json_encode($result[0])
                        : $result[0];
        }
        else if (is_object($result)) {
            return $result->first();
        }
    }
83908
public static function fromDict($rsp, $txnType, $returnType = 'HpsTransactionStatus')
    {
        $statusResponse = $rsp->Transaction->$txnType;

        $status = parent::fromDict($rsp, $txnType, $returnType);
        $status->authorizationCode = (isset($statusResponse->TransactionStatus->AuthCode) ? (string)$statusResponse->TransactionStatus->AuthCode : null);
        $status->originalGatewayResponseCode = (isset($statusResponse->TransactionStatus->GatewayRspCode) ? (string)$statusResponse->TransactionStatus->GatewayRspCode : null);
        $status->originalGatewayResponseText = (isset($statusResponse->TransactionStatus->GatewayRspMsg) ? (string)$statusResponse->TransactionStatus->GatewayRspMsg : null);
        $status->originalResponseCode = (isset($statusResponse->TransactionStatus->RspCode) ? (string)$statusResponse->TransactionStatus->RspCode : null);
        $status->originalResponseText = (isset($statusResponse->TransactionStatus->RspText) ? (string)$statusResponse->TransactionStatus->RspText : null);
        $status->transactionStatus = (isset($statusResponse->TransactionStatus->TxnStatus) ? (string)$statusResponse->TransactionStatus->TxnStatus : null);
        $status->originalTransactionId = (isset($statusResponse->TransactionStatus->GatewayTxnId) ? (string)$statusResponse->TransactionStatus->GatewayTxnId : null);
        $status->altPayment = (isset($statusResponse->TransactionStatus->AltPayment) ? $statusResponse->TransactionStatus->AltPayment : null);
        $status->timezoneConversion = (isset($statusResponse->TzConversion) ? (string)$statusResponse->TzConversion : null);

        return $status;
    }
777014
public function populate($rows)
    {
        $indexBy = $this->indexBy;

        if ($indexBy === null) {
            return $this->createObjects($rows);
        }
        $result = [];
        foreach ($rows as $row) {
            if (is_string($indexBy)) {
                $key = $row[$indexBy];
            } else {
                $key = call_user_func($indexBy, $row);
            }
            $result[$key] = $this->createObject($row);
        }
        return $result;
    }
1003111
public static function rows(array $fields): Rows
    {
        return new class($fields) extends Rows {
            /**
             * @var array
             */
            private $fields;

            /**
             *  constructor.
             *
             * @param array $fields
             */
            public function __construct(array $fields)
            {
                $this->fields = $fields;
            }

            /**
             * @return array
             */
            public function fields(): array
            {
                return $this->fields;
            }
        };
    }
552597
public function setRows($rows)
    {
        intval($rows);
        if ($rows < 1) {
            $rows = 1;
        }

        $this->rows = $rows;

        return $this;
    }
758445
public function toArray($returnFields = array())
    {
        if (!$this->isColl) {
            $data = array_fill_keys($returnFields ?: $this->getFields(), null);
            if (!$returnFields) {
                return $this->data + $data;
            } else {
                $data = array_fill_keys($returnFields, null);
                return array_intersect_key($this->data, $data) + $data;
            }
        } else {
            $data = array();
            /** @var $record Record */
            foreach ($this->data as $key => $record) {
                $data[$key] = $record->toArray($returnFields);
            }
            return $data;
        }
    }
1078367
protected function _format_return(array $calls, $return_type)
	{
		switch ($return_type)
		{
			case 'array':
				return $calls;
				break;
			case 'json':
				return json_encode($calls);
				break;
			case 'none':
				return;
			case 'serialized':
				return serialize($calls);
				break;
			case 'string':
				$str = '';
				foreach ($calls as $call)
				{
					$str .= $call;
				}
				return $str;
				break;
			default:
				return $calls;
				break;
		}

		return false;
	}
641705
public static function batchInsert(string $className, array $rows): ResultInterface
    {
        $instance = self::getInstance($className);

        return Query::table($className)->selectInstance($instance)->batchInsert($rows);
    }
1211730
protected static function indexByChild($rows)
    {
        $child = [];

        foreach ($rows as $row) {
            $child[(int)$row['child_id']] = (int) $row['parent_id'];
        }

        return $child;
    }
1113446
public static function fromObject($data, $returnType = 'HpsCardinalMPIAuthorizeResponse')
    {
        $response = parent::fromObject($data, $returnType);
        $response->authorizationCode = self::readDataKey($data, 'AuthorizationCode');
        $response->avsResult = self::readDataKey($data, 'AvsResult');
        $response->cardBin = self::readDataKey($data, 'CardBin');
        $response->cardExpMonth = self::readDataKey($data, 'CardExpMonth');
        $response->cardExpYear = self::readDataKey($data, 'CardExpYear');
        $response->cardLastFour = self::readDataKey($data, 'CardLastFour');
        $response->cardType = self::readDataKey($data, 'CardType');
        $response->longAccessToken = self::readDataKey($data, 'LongAccessToken');
        $response->nameOnCard = self::readDataKey($data, 'NameOnCard');
        $response->processorBillingAddress1 = self::readDataKey($data, 'ProcessorBillingAddress1');
        $response->processorBillingAddress2 = self::readDataKey($data, 'ProcessorBillingAddress2');
        $response->processorBillingCity = self::readDataKey($data, 'ProcessorBillingCity');
        $response->processorBillingCountryCode = self::readDataKey($data, 'ProcessorBillingCountryCode');
        $response->processorBillingFirstName = self::readDataKey($data, 'ProcessorBillingFirstName');
        $response->processorBillingLastName = self::readDataKey($data, 'ProcessorBillingLastName');
        $response->processorBillingMiddleName = self::readDataKey($data, 'ProcessorBillingMiddleName');
        $response->processorBillingPhone = self::readDataKey($data, 'ProcessorBillingPhone');
        $response->processorBillingPostalCode = self::readDataKey($data, 'ProcessorBillingPostalCode');
        $response->processorBillingState = self::readDataKey($data, 'ProcessorBillingState');
        $response->processorCavv = self::readDataKey($data, 'ProcessorCavv');
        $response->processorEciFlag = self::readDataKey($data, 'ProcessorEciFlag');
        $response->processorEmail = self::readDataKey($data, 'ProcessorEmail');
        $response->processorPayresStatus = self::readDataKey($data, 'ProcessorPayresStatus');
        $response->processorShippingAddress1 = self::readDataKey($data, 'ProcessorShippingAddress1');
        $response->processorShippingAddress2 = self::readDataKey($data, 'ProcessorShippingAddress2');
        $response->processorShippingCity = self::readDataKey($data, 'ProcessorShippingCity');
        $response->processorShippingCountryCode = self::readDataKey($data, 'ProcessorShippingCountryCode');
        $response->processorShippingFullName = self::readDataKey($data, 'ProcessorShippingFullName');
        $response->processorShippingPhone = self::readDataKey($data, 'ProcessorShippingPhone');
        $response->processorShippingPostalCode = self::readDataKey($data, 'ProcessorShippingPostalCode');
        $response->processorShippingState = self::readDataKey($data, 'ProcessorShippingState');
        return $response;
    }
1312146
private function buildEventAggregate(array $events, $returnType)
    {
        if ($returnType === self::RETURN_AS_ARRAY) {
            return $this->buildEventAggregateAsArray($events);
        }

        return $this->buildEventAggregateAsObject($events);
    }
391537
private function formatRows(array $rows) {
        foreach ($rows as $rowIndex => $row) {
            $type = $row['type'];
            $indent = $this->indent;
            $gutter = str_repeat(' ', $this->gutter);
            $verticalSeparator = $this->verticalSeparator;

            if ($type === '@section') {
                $indent = $this->sectionIndent;
            }

            foreach ($row['cols'] as $colIndex => $col) {
                if ($colIndex === 0) {
                    $col = str_repeat(' ', $indent) . $col;
                } else {
                    $col = $gutter . $verticalSeparator . $gutter . $col;
                }

                array_set($row['cols'], $colIndex, $col);
            }

            array_set($rows, $rowIndex, $row);
        }

        return $rows;
    }
284931
protected function loadFromRows(array $rows, $typeIdentifier, $status)
    {
        $types = $this->mapper->extractTypesFromRows($rows);
        if (count($types) !== 1) {
            throw new Exception\TypeNotFound($typeIdentifier, $status);
        }

        return $types[0];
    }
868153
public function toFeatureCollection($rows)
    {
        /** @var Feature $feature */
        foreach ($rows as $k => $feature) {
            $rows[ $k ] = $feature->toGeoJson(true);
        }
        return array("type"     => "FeatureCollection",
                     "features" => $rows);
    }