File: D:/HostingSpaces/SBogers95/rentman.io/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.
*/
class Documents extends Attribute implements HasSubFoldersInterface
{
use LabelTrait;
use SubFolderTrait;
/** @var string This is the sub folder of the path public/uploads where the documents for this attribute wil be placed in */
// private $subFolder;
/** @var int The maximum amount of documents the attribute can hold */
private $maxDocuments;
/**
* @var ImageProperty[] When you upload an image, the image will be processed and saved in the sizes you've specified with this variable
*/
private $imageProperties;
/** @var string which mime types to accept. Example: video/*,.jpeg */
private $accept;
/**
* @var string the folder in which extension thumbs can be found. Relative to the document root
*/
private $extensionThumbsFolder;
/**
* @var bool whether or not to show thumb previews if possible
*/
private $enablePreviewsIfPossible;
/**
* @var bool whether or not the items are sortable
*/
private $isSortable;
/**
* @var bool whether or the items should be append the timestamp in the url
*/
private $useTimestamp;
/**
* @var bool whether the drag and drop area is to big
*/
private $largeDragAndDropArea;
public function __construct()
{
$this->subFolder = '';
$this->maxDocuments = null;
$this->accept = '';
$this->extensionThumbsFolder = '/img/kms/extension_thumbs/';
$this->enablePreviewsIfPossible = true;
$this->isSortable = true;
$this->useTimestamp = 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): self
{
$this->maxDocuments = $maxDocuments;
return $this;
}
/**
* @return string
*/
public function getAccept(): string
{
return $this->accept;
}
/**
* @param string $accept
* @return Documents
*/
public function setAccept(string $accept): self
{
$this->accept = $accept;
return $this;
}
/**
* @return AbstractImageProperty[]
*/
public function getImageProperties(): array
{
return $this->imageProperties;
}
/**
* @param AbstractImageProperty[] $imageProperties
* @return Documents
*/
public function setImageProperties(array $imageProperties): self
{
$this->imageProperties = $imageProperties;
return $this;
}
/**
* @return string
*/
public function getExtensionThumbsFolder(): string
{
return $this->extensionThumbsFolder;
}
/**
* @param string $extensionThumbsFolder
* @return Documents
*/
public function setExtensionThumbsFolder(string $extensionThumbsFolder): self
{
$this->extensionThumbsFolder = $extensionThumbsFolder;
return $this;
}
/**
* @return bool
*/
public function getEnablePreviewsIfPossible(): bool
{
return $this->enablePreviewsIfPossible;
}
/**
* @param bool $enablePreviewsIfPossible
* @return Documents
*/
public function setEnablePreviewsIfPossible(bool $enablePreviewsIfPossible): self
{
$this->enablePreviewsIfPossible = $enablePreviewsIfPossible;
return $this;
}
/**
* @return bool
*/
public function getIsSortable(): bool
{
return $this->isSortable;
}
/**
* @param bool $isSortable
* @return Documents
*/
public function setIsSortable(bool $isSortable): self
{
$this->isSortable = $isSortable;
return $this;
}
/**
* @return bool
*/
public function doesUseTimestamp(): bool
{
return $this->useTimestamp;
}
/**
* @param bool $useTimestamp
* @return Documents
*/
public function setUseTimestamp(bool $useTimestamp): self
{
$this->useTimestamp = $useTimestamp;
return $this;
}
/**
* @return bool
*/
public function hasSmallDragAndDropArea(): bool
{
return ! $this->largeDragAndDropArea;
}
/**
* @return Documents
*/
public function setSmallDragAndDropArea(): self
{
$this->largeDragAndDropArea = false;
return $this;
}
/**
* @return Documents
*/
public function onlyAllowImages(): self
{
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;
}
}