resourceConnection = $resourceConnection; $this->objectManager = $objectManager; $this->selectParts = $selectParts; } /** * @return array */ private function getSelectParts() { return array_merge($this->predefinedSelectParts, $this->selectParts); } /** * Extracts Select metadata parts * * @param Select $select * @return array * @throws \Zend_Db_Select_Exception */ public function extract(Select $select) { $parts = []; foreach ($this->getSelectParts() as $partName) { $parts[$partName] = $select->getPart($partName); } return $parts; } /** * @param array $selectParts * @return Select */ public function recreate(array $selectParts) { $select = $this->resourceConnection->getConnection()->select(); $select = $this->processColumns($select, $selectParts); foreach ($selectParts as $partName => $partValue) { $select->setPart($partName, $partValue); } return $select; } /** * Process COLUMNS part values and add this part into select. * * If each column contains information about select expression * an object with the type of this expression going to be created and assigned to this column. * * @param Select $select * @param array $selectParts * @return Select */ private function processColumns(Select $select, array &$selectParts) { if (!empty($selectParts[Select::COLUMNS]) && is_array($selectParts[Select::COLUMNS])) { $part = []; foreach ($selectParts[Select::COLUMNS] as $columnEntry) { list($correlationName, $column, $alias) = $columnEntry; if (is_array($column) && !empty($column['class'])) { $expression = $this->objectManager->create( $column['class'], isset($column['arguments']) ? $column['arguments'] : [] ); $part[] = [$correlationName, $expression, $alias]; } else { $part[] = $columnEntry; } } $select->setPart(Select::COLUMNS, $part); unset($selectParts[Select::COLUMNS]); } return $select; } }