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/bomacon.komma.pro/vendor/komma/kms/src/Core/Attributes/Documents.php
<?php
namespace Komma\KMS\Core\Attributes;
use Komma\KMS\Documents\Models\Document;
use Komma\KMS\Core\Attributes\Models\AbstractImageProperty;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\Models\Traits\HasSubFoldersInterface;
use Komma\KMS\Core\Attributes\Models\Traits\SubFolderTrait;
use Komma\KMS\Core\Attributes\Traits\LabelTrait;

/**
 * Class Documents
 *
 * Note: the mapValueFrom reference value for this attribute can be anything as long as it is unique.
 *
 * @package App\Kms\Core\Attributes
 */
class Documents extends Attribute implements HasSubFoldersInterface
{
    use LabelTrait;
    use SubFolderTrait;

    /** @var int $maxDocuments The maximum amount of documents the attribute can hold*/
    private $maxDocuments;

    /**
     * @var ImageProperty[] $imageProperties When you upload an image, the image will be processed and saved in the sizes you've specified with this variable
     */
    private $imageProperties;

    /** @var $accept string which mime types to accept. Example: video/*,.jpeg */
    private $accept;

    /**
     * @var $extensionThumbsFolder string the folder in which extension thumbs can be found. Relative to the document root
     */
    private $extensionThumbsFolder;

    /**
     * @var $enablePreviewsIfPossible bool whether or not to show thumb previews if possible
     */
    private $enablePreviewsIfPossible;

    /**
     * @var $isSortable bool whether or not the items are sortable
     */
    private $isSortable;

    /**
     * @var $largeDragAndDropArea bool whether the drag and drop area is to big
     */
    private $largeDragAndDropArea;

    public function __construct()
    {
        $this->maxDocuments = null;
        $this->accept = '';
        $this->extensionThumbsFolder = '/img/kms/extension_thumbs/';
        $this->enablePreviewsIfPossible = true;
        $this->isSortable = true;
        $this->largeDragAndDropArea = true;
        $this->imageProperties = [];
        parent::__construct();
    }

    /**
     * Returns a view that visually represents this attribute
     */
    public function render()
    {
        $view = view('KMS::kms/attributes.documents', [
            'attribute' => $this,
            'imageProperties' => json_encode($this->imageProperties)
        ]);

        return $view;
    }

    /**
     * Gets the maximum amount of documents the document uploader can upload or null for unlimited
     *
     * @return int
     */
    public function getMaxDocuments(): ?int
    {
        return $this->maxDocuments;
    }

    /**
     * @param int $maxDocuments
     * @return Documents
     */
    public function setMaxDocuments(int $maxDocuments): Documents
    {
        $this->maxDocuments = $maxDocuments;
        return $this;
    }

    /**
     * @return string
     */
    public function getAccept(): string
    {
        return $this->accept;
    }

    /**
     * @param string $accept
     * @return Documents
     */
    public function setAccept(string $accept): Documents
    {
        $this->accept = $accept;
        return $this;
    }

    /**
     * @return AbstractImageProperty[]
     */
    public function getImageProperties(): array
    {
        return $this->imageProperties;
    }

    /**
     * @param AbstractImageProperty[] $imageProperties
     * @return Documents
     */
    public function setImageProperties(array $imageProperties): Documents
    {
        $this->imageProperties = $imageProperties;
        return $this;
    }

    /**
     * @return string
     */
    public function getExtensionThumbsFolder(): string
    {
        return $this->extensionThumbsFolder;
    }

    /**
     * @param string $extensionThumbsFolder
     * @return Documents
     */
    public function setExtensionThumbsFolder(string $extensionThumbsFolder): Documents
    {
        $this->extensionThumbsFolder = $extensionThumbsFolder;
        return $this;
    }

    /**
     * @return bool
     */
    public function getEnablePreviewsIfPossible(): bool
    {
        return $this->enablePreviewsIfPossible;
    }

    /**
     * @param bool $enablePreviewsIfPossible
     * @return Documents
     */
    public function setEnablePreviewsIfPossible(bool $enablePreviewsIfPossible): Documents
    {
        $this->enablePreviewsIfPossible = $enablePreviewsIfPossible;
        return $this;
    }

    /**
     * @return bool
     */
    public function getIsSortable(): bool
    {
        return $this->isSortable;
    }

    /**
     * @param bool $isSortable
     * @return Documents
     */
    public function setIsSortable(bool $isSortable): Documents
    {
        $this->isSortable = $isSortable;
        return $this;
    }

    /**
     * @return bool
     */
    public function hasSmallDragAndDropArea(): bool
    {
        return !$this->largeDragAndDropArea;
    }

    /**
     * @return Documents
     */
    public function setSmallDragAndDropArea(): Documents
    {
        $this->largeDragAndDropArea = false;
        return $this;
    }

    /**
     * @return Documents
     */
    public function onlyAllowImages(): Documents
    {
        return $this->setAccept('image/*');
    }

    /**
     * @param $value
     * @return \Illuminate\Support\Collection
     */
    public function prepareValueForViewComponent($value)
    {
        // Create new empty collection
        $documents = collect();

        // Parse value to array
        $values = json_decode($value,true);

        foreach($values as $value)
        {
            // Skip if state is deleted, bug when deleted an image in components
            if($value['state'] == 'deleted') continue;

            /** @var Document $document */
            $document = (new Document())->fill($value);
            $documents->push($document);
        }

        // If there is more then 1 image we apply the sort_order to the collection
        if($documents->count() > 1) {
            $documents = $documents->sortBy('sort_order');
        }

        return $documents;
    }
}