File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Kms/Core/Attributes/Documents.php
<?php
namespace App\Komma\Kms\Core\Attributes;
use App\Komma\Documents\Models\Document;
use App\Komma\Kms\Core\Attributes\Models\AbstractImageProperty;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasSubFoldersInterface;
use App\Komma\Kms\Core\Attributes\Models\Traits\SubFolderTrait;
use App\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\Komma\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::make('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);
}
return $documents;
}
}