src/Db/ImageBMapper.php
private function resultsToCollection(AType $ownerType, $images_result, $resizes_result, $crops_result)
    {
        $collection = new MapImageCollection($this->capGenerator);

        $gens = [];

        foreach($images_result as $item_array)
        {
            $field_name = $item_array['name'];

            if($ownerType->fieldExist($field_name))
            {
                $imageField = $ownerType->getField($field_name);

                $imageItem = $this->createImage($imageField, $item_array);

                $ref = new \Interpro\Core\Ref\ARef($ownerType, $item_array['entity_id']);

                $collection->addItem($ref, $field_name, $imageItem);

                $key = $item_array['name'].'_'.$item_array['entity_id'];
                $gens[$key] = ['resizes' => [], 'crops' => [], 'item' => $imageItem, 'name' => $item_array['name']];
            }
        }

        //-----------------------------------------------------------

        foreach($resizes_result as $resize_arr)
        {
            $key = $resize_arr['image_name'].'_'.$resize_arr['entity_id'];

            if(array_key_exists($key, $gens)) //Записи без соответствия картинке отметаем
            {
                $gens[$key]['resizes'][$resize_arr['name']] = $resize_arr;
            }
        }

        foreach($crops_result as $crop_arr)
        {
            $key = $crop_arr['image_name'].'_'.$crop_arr['entity_id'];

            if(array_key_exists($key, $gens)) //Записи без соответствия картинке отметаем
            {
                $gens[$key]['crops'][$crop_arr['name']] = $crop_arr;
            }
        }
        //-----------------------------------------------------------

        foreach($gens as $gen_arr)
        {
            $image_name = $gen_arr['name'];

            if($ownerType->fieldExist($image_name))
            {
                $imageField = $ownerType->getField($image_name);

                //Костыль, чтобы не заводить экземпляр таксономии в этот класс
                $imageType = $imageField->getFieldType();
                $subs = $imageType->getSubs('original');
                $resizeType = $subs->getSub('resize');
                $cropType = $subs->getSub('crop');
                //--------------------------------------

                $resizes = $gen_arr['resizes'];
                $crops = $gen_arr['crops'];
                $imageItem = $gen_arr['item'];

                foreach($resizes as $resize_arr)
                {
                    $resizeItem = $this->createResize($resizeType, $resize_arr);

                    $resizeItem->getRef('original')->setItem($imageItem);

                    $imageItem->addResize($resizeItem);
                }

                foreach($crops as $crop_arr)
                {
                    $cropItem = $this->createCrop($cropType, $crop_arr);

                    $cropItem->getRef('original')->setItem($imageItem);
                    $cropItem->getRef('man')->setItem($imageItem->getResize($crop_arr['man_name']));
                    $cropItem->getRef('target')->setItem($imageItem->getResize($crop_arr['target_name']));

                    $imageItem->addCrop($cropItem);
                }
            }
        }

        return $collection;
    }
private function resultsToCollection(AType $ownerType, $images_result, $resizes_result, $crops_result)
    {
        $collection = new MapImageCollection($this->capGenerator);

        $gens = [];

        foreach($images_result as $item_array)
        {
            $field_name = $item_array['name'];

            if($ownerType->fieldExist($field_name))
            {
                $imageField = $ownerType->getField($field_name);

                $imageItem = $this->createImage($imageField, $item_array);

                $ref = new \Interpro\Core\Ref\ARef($ownerType, $item_array['entity_id']);

                $collection->addItem($ref, $field_name, $imageItem);

                $key = $item_array['name'].'_'.$item_array['entity_id'];
                $gens[$key] = ['resizes' => [], 'crops' => [], 'item' => $imageItem, 'name' => $item_array['name']];
            }
        }

        //-----------------------------------------------------------

        foreach($resizes_result as $resize_arr)
        {
            $key = $resize_arr['image_name'].'_'.$resize_arr['entity_id'];

            if(array_key_exists($key, $gens)) //Записи без соответствия картинке отметаем
            {
                $gens[$key]['resizes'][$resize_arr['name']] = $resize_arr;
            }
        }

        foreach($crops_result as $crop_arr)
        {
            $key = $crop_arr['image_name'].'_'.$crop_arr['entity_id'];

            if(array_key_exists($key, $gens)) //Записи без соответствия картинке отметаем
            {
                $gens[$key]['crops'][$crop_arr['name']] = $crop_arr;
            }
        }
        //-----------------------------------------------------------

        foreach($gens as $gen_arr)
        {
            $image_name = $gen_arr['name'];

            if($ownerType->fieldExist($image_name))
            {
                $imageField = $ownerType->getField($image_name);

                //Костыль, чтобы не заводить экземпляр таксономии в этот класс
                $imageType = $imageField->getFieldType();
                $subs = $imageType->getSubs('original');
                $resizeType = $subs->getSub('resize');
                $cropType = $subs->getSub('crop');
                //--------------------------------------

                $resizes = $gen_arr['resizes'];
                $crops = $gen_arr['crops'];
                $imageItem = $gen_arr['item'];

                foreach($resizes as $resize_arr)
                {
                    $resizeItem = $this->createResize($resizeType, $resize_arr);

                    $resizeItem->getRef('original')->setItem($imageItem);

                    $imageItem->addResize($resizeItem);
                }

                foreach($crops as $crop_arr)
                {
                    $cropItem = $this->createCrop($cropType, $crop_arr);

                    $cropItem->getRef('original')->setItem($imageItem);
                    $cropItem->getRef('man')->setItem($imageItem->getResize($crop_arr['man_name']));
                    $cropItem->getRef('target')->setItem($imageItem->getResize($crop_arr['target_name']));

                    $imageItem->addCrop($cropItem);
                }
            }
        }

        return $collection;
    }
@param AType $ownerType
@param $images_result
@param $resizes_result
@param $crops_result

@return MapImageCollection