src/Db/ImageAggrDbAgent.php
public function resizeToDb(ARef $aRef, ImageSettingInterface $imageSetting, ResizeSettingInterface $resizeSetting, $attrs = [], $init = false)
    {
        $owner_name = $aRef->getType()->getName();
        $image_name = $imageSetting->getName();
        $resize_name = $resizeSetting->getName();
        $owner_id = $aRef->getId();

        $collection = Resize::where('entity_name', '=', $owner_name)
            ->where('entity_id', '=', $owner_id)
            ->where('image_name', '=', $image_name)
            ->where('name', '=', $resize_name)
            ->get();

        $cache_index = 0;

        $resize = null;

        //Удалим все записи по этому ключу (на всякий случай, т. к. записи в БД уникальны по авто инк. id)
        foreach($collection as $curr_resize)
        {
            if($resize === null)
            {
                $cache_index = $curr_resize->cache_index;
                $resize = $curr_resize;

                if($init)
                {
                    break;
                }
            }
            else
            {
                $curr_resize->delete();
            }
        }

        $db = !$init;

        if($resize === null)
        {
            $resize = new Resize;
            $resize->alt = '';
            $resize->link = '';
            $resize->width = 400;
            $resize->height = 400;
            $db = true;
        }

        $cache_index++;

        if($db)
        {
            if(!array_key_exists('alt', $attrs))
            {
                $attrs['alt'] = $resize->alt;
            }

            if(!array_key_exists('link', $attrs))
            {
                $attrs['link'] = $resize->link;
            }

            if(!array_key_exists('width', $attrs))
            {
                $attrs['width'] = $resize->width;
            }

            if(!array_key_exists('height', $attrs))
            {
                $attrs['height'] = $resize->height;
            }

            $resize->cache_index = $cache_index;
            $resize->entity_name = $owner_name;
            $resize->entity_id   = $owner_id;
            $resize->image_name  = $image_name;
            $resize->name        = $resize_name;
            $resize->alt         = $attrs['alt'];
            $resize->link        = $attrs['link'];
            $resize->width       = $attrs['width'];
            $resize->height      = $attrs['height'];

            $resize->save();
        }
    }
public function resizeToDb(ARef $aRef, ImageSettingInterface $imageSetting, ResizeSettingInterface $resizeSetting, $attrs = [], $init = false)
    {
        $owner_name = $aRef->getType()->getName();
        $image_name = $imageSetting->getName();
        $resize_name = $resizeSetting->getName();
        $owner_id = $aRef->getId();

        $collection = Resize::where('entity_name', '=', $owner_name)
            ->where('entity_id', '=', $owner_id)
            ->where('image_name', '=', $image_name)
            ->where('name', '=', $resize_name)
            ->get();

        $cache_index = 0;

        $resize = null;

        //Удалим все записи по этому ключу (на всякий случай, т. к. записи в БД уникальны по авто инк. id)
        foreach($collection as $curr_resize)
        {
            if($resize === null)
            {
                $cache_index = $curr_resize->cache_index;
                $resize = $curr_resize;

                if($init)
                {
                    break;
                }
            }
            else
            {
                $curr_resize->delete();
            }
        }

        $db = !$init;

        if($resize === null)
        {
            $resize = new Resize;
            $resize->alt = '';
            $resize->link = '';
            $resize->width = 400;
            $resize->height = 400;
            $db = true;
        }

        $cache_index++;

        if($db)
        {
            if(!array_key_exists('alt', $attrs))
            {
                $attrs['alt'] = $resize->alt;
            }

            if(!array_key_exists('link', $attrs))
            {
                $attrs['link'] = $resize->link;
            }

            if(!array_key_exists('width', $attrs))
            {
                $attrs['width'] = $resize->width;
            }

            if(!array_key_exists('height', $attrs))
            {
                $attrs['height'] = $resize->height;
            }

            $resize->cache_index = $cache_index;
            $resize->entity_name = $owner_name;
            $resize->entity_id   = $owner_id;
            $resize->image_name  = $image_name;
            $resize->name        = $resize_name;
            $resize->alt         = $attrs['alt'];
            $resize->link        = $attrs['link'];
            $resize->width       = $attrs['width'];
            $resize->height      = $attrs['height'];

            $resize->save();
        }
    }
@param \Interpro\Core\Contracts\Ref\ARef $aRef
@param \Interpro\ImageAggr\Contracts\Settings\ImageSetting $imageSetting
@param \Interpro\ImageAggr\Contracts\Settings\ResizeSetting $resizeSetting
@param array $attrs

@return void