src/Db/QSAMapper.php
public function select(SelectionUnit $selectionUnit)
    {
        $key = 'number_'.$selectionUnit->getNumber();

        if(array_key_exists($key, $this->collections))
        {
            return $this->collections[$key];
        }

        //====================================================
        $type = $selectionUnit->getType();
        $type_name = $type->getName();

        $mapCollection = $this->collectionFactory->createMapGroupCollection($type);

        $qb = $this->qsQuerier->selectByUnit($selectionUnit);

        $result_array = Helpers::laravel_db_result_to_array($qb->get());

        $id_set = array_column($result_array, 'id');

        $selectionUnit->addId($id_set);
        $selectionUnit->complete();

        $ownsMetaCollection = $type->getOwns();
        $refsMetaCollection = $type->getRefs();

        $refs_array = $this->qsQuerier->getRefValues($type_name, $id_set);

        foreach($result_array as $item_result)
        {
            $ref = new \Interpro\Core\Ref\ARef($type, (int)$item_result['id']);

            $item = $this->factory->create($ref);

            //====================================================поля
            foreach($ownsMetaCollection as $ownMeta)
            {
                $fieldType = $ownMeta->getFieldType();
                $fieldMode = $ownMeta->getMode();

                $field_name = $ownMeta->getName();

                if($this->local($field_name)) //все поля локального хранения - С типы
                {
                    $newField = $this->createLocalCField($item, $ownMeta, $item_result);
                }
                else
                {
                    if($fieldMode === TypeMode::MODE_B)
                    {
                        $mapper = $this->mappersMediator->getBMapper($fieldType->getFamily());
                        $map = $mapper->select($selectionUnit);//Селект кэшируется в маппере полей, обращаемся каждий раз при поиске поля
                        $newField = $this->createExternalBFieldByRef($item, $ownMeta, $map);
                    }
                    elseif($fieldMode === TypeMode::MODE_C)
                    {
                        $mapper = $this->mappersMediator->getCMapper($fieldType->getFamily());
                        $map = $mapper->select($selectionUnit);//Селект кэшируется в маппере полей, обращаемся каждий раз при поиске поля
                        $newField = $this->createExternalCFieldByRef($item, $ownMeta, $map);
                    }
                    else
                    {
                        throw new QSException('В типе '.$type_name.' обнаружено поле-собственность типа отличного от В или С: '.$field_name.'('.$fieldMode.')!');
                    }
                }

                $item->setOwn($newField);
                $item->setField($newField);
            }

            //====================================================ссылки
            foreach($refsMetaCollection as $refMeta)
            {
                $newField = $this->createRefField($item, $refMeta, $refs_array);

                $item->setRef($newField);
                $item->setField($newField);
            }

            $mapCollection->addItem($item);
        }

        $this->collections[$key] = $mapCollection;

        return $mapCollection;
    }
public function select(SelectionUnit $selectionUnit)
    {
        $key = 'number_'.$selectionUnit->getNumber();

        if(array_key_exists($key, $this->collections))
        {
            return $this->collections[$key];
        }

        //====================================================
        $type = $selectionUnit->getType();
        $type_name = $type->getName();

        $mapCollection = $this->collectionFactory->createMapGroupCollection($type);

        $qb = $this->qsQuerier->selectByUnit($selectionUnit);

        $result_array = Helpers::laravel_db_result_to_array($qb->get());

        $id_set = array_column($result_array, 'id');

        $selectionUnit->addId($id_set);
        $selectionUnit->complete();

        $ownsMetaCollection = $type->getOwns();
        $refsMetaCollection = $type->getRefs();

        $refs_array = $this->qsQuerier->getRefValues($type_name, $id_set);

        foreach($result_array as $item_result)
        {
            $ref = new \Interpro\Core\Ref\ARef($type, (int)$item_result['id']);

            $item = $this->factory->create($ref);

            //====================================================поля
            foreach($ownsMetaCollection as $ownMeta)
            {
                $fieldType = $ownMeta->getFieldType();
                $fieldMode = $ownMeta->getMode();

                $field_name = $ownMeta->getName();

                if($this->local($field_name)) //все поля локального хранения - С типы
                {
                    $newField = $this->createLocalCField($item, $ownMeta, $item_result);
                }
                else
                {
                    if($fieldMode === TypeMode::MODE_B)
                    {
                        $mapper = $this->mappersMediator->getBMapper($fieldType->getFamily());
                        $map = $mapper->select($selectionUnit);//Селект кэшируется в маппере полей, обращаемся каждий раз при поиске поля
                        $newField = $this->createExternalBFieldByRef($item, $ownMeta, $map);
                    }
                    elseif($fieldMode === TypeMode::MODE_C)
                    {
                        $mapper = $this->mappersMediator->getCMapper($fieldType->getFamily());
                        $map = $mapper->select($selectionUnit);//Селект кэшируется в маппере полей, обращаемся каждий раз при поиске поля
                        $newField = $this->createExternalCFieldByRef($item, $ownMeta, $map);
                    }
                    else
                    {
                        throw new QSException('В типе '.$type_name.' обнаружено поле-собственность типа отличного от В или С: '.$field_name.'('.$fieldMode.')!');
                    }
                }

                $item->setOwn($newField);
                $item->setField($newField);
            }

            //====================================================ссылки
            foreach($refsMetaCollection as $refMeta)
            {
                $newField = $this->createRefField($item, $refMeta, $refs_array);

                $item->setRef($newField);
                $item->setField($newField);
            }

            $mapCollection->addItem($item);
        }

        $this->collections[$key] = $mapCollection;

        return $mapCollection;
    }
@param \Interpro\Extractor\Contracts\Selection\SelectionUnit $selectionUnit

@return \Interpro\Extractor\Contracts\Collections\MapGroupCollection