public function getLinkedColumn($entityName, $propColumn) { /** @var Adapter $adapter */ $adapter = $this->dbTable->getAdapter(); $mysqlManager = new TableManagerMysql($adapter); $columnsNames = $mysqlManager->getColumnsNames($this->dbTable->table); //'prop_name.column_name' or 'prop_name' $linkedColumn = strpos($propColumn, '.') ? isset(explode('.', $propColumn)[1]) && in_array(explode('.', $propColumn)[1], $columnsNames) ? explode('.', $propColumn)[1] : null : (in_array($entityName . SysEntities::ID_SUFFIX, $columnsNames) ? $entityName . SysEntities::ID_SUFFIX : (in_array(SysEntities::TABLE_NAME . SysEntities::ID_SUFFIX, $columnsNames) ? SysEntities::TABLE_NAME . SysEntities::ID_SUFFIX : null)); return $linkedColumn; }
protected function joinedEntitiesItemHandler($itemData, callable $handler) { /** @var Adapter $adapter */ $adapter = $this->dbTable->getAdapter(); $itemInserted = []; /** @var Entity $entity */ foreach ($this->joinedEntities as $entity) { if (is_object($entity)) { $entityItem = []; $mysqlManager = new TableManagerMysql($adapter); $columnsNames = $mysqlManager->getColumnsNames($entity->getEntityTableName()); foreach ($columnsNames as $columnName) { if (isset($itemData[$columnName])) { $entityItem[$columnName] = $itemData[$columnName]; } } $entityItem = $handler($entity, $entityItem); $itemInserted = array_merge($itemInserted, $entityItem); } } return $itemInserted; }