HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/vebon.komma.pro/app/KommaApp/Images/ImageService.php
<?php

/**
 *
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

namespace KommaApp\Images;

use KommaApp\Images\Models\Image;

class ImageService
{

    private $imageableType = '';

    public function setImageableType($imageableType)
    {
        $this->imageableType = $imageableType;
    }

    public function saveImages($images, $id, $imageableType = null)
    {

        if($imageableType == null) $imageableType = $this->imageableType;

        if (is_array($images)) {
            foreach ($images as $image) {
                if (isset($image->delete) && $image->delete == true) {
                    Image::destroy($image->id);
                    continue;
                } else {
                    $model = Image::find($image->id) ? Image::find($image->id) : new Image();
                    if (isset($image->original)) {
                        $model->original_image_url = $image->original;
                    }
                    if (isset($image->large)) {
                        $model->large_image_url = $image->large;
                    }
                    if (isset($image->medium)) {
                        $model->medium_image_url = $image->medium;
                    }
                    if (isset($image->small)) {
                        $model->small_image_url = $image->small;
                    }
                    if (isset($image->thumb)) {
                        $model->thumb_image_url = $image->thumb;
                    }
                    $model->imageble_type = $imageableType;
                    $model->imageble_id = $id;
                    $model->save();
                }
            }

        }
    }

    public function getImages($id, $imageableType = null)
    {

        if($imageableType == null) $imageableType = $this->imageableType;

        $images = [];
        $imageRecords = Image::where('imageble_type', $imageableType)->where('imageble_id', $id)->get();
        foreach ($imageRecords as $record) {
            $image = $images[] = new \stdClass();
            $image->id = $record->id;
            $image->original = $record->original_image_url;
            $image->large = $record->large_image_url;
            $image->medium = $record->medium_image_url;
            $image->small = $record->small_image_url;
            $image->thumb = $record->thumb_image_url;
        }
        return $images;
    }

}