File: D:/HostingSpaces/SBogers10/momsecurity.komma.nl/app/Components/Types/QuestionImage.php
<?php
namespace App\Components\Types;
use App\Components\ComponentTypes;
use App\QuestionCategories\Models\QuestionCategory;
use App\Testimonials\Models\Testimonial;
use Komma\KMS\Components\Component\ViewComponent;
use Komma\KMS\Components\ComponentType\Types\AbstractComponentType;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\ModelServiceInterface;
class QuestionImage extends AbstractComponentType
{
protected int $id = ComponentTypes::QUESTION_IMAGE;
protected string $name = 'question-image';
public function defineAttributesAndTabs()
{
/** @var ModelServiceInterface $questionSetModels */
$questionSetModels = app(ModelServiceInterface::class);
$questionSetModels->setModelClassName(QuestionCategory::class);
$this->addItems([
(new TextField())
->setReference('title' )
->setLabelText(__('KMS::attributes/components.title')),
(new Select())
->setReference('question_set')
->setLabelText('Vragenset')
->setItems($questionSetModels->getOptionsForSelect()->toArray()),
(new Seperator()),
(new Documents())
->setReference('image')
->onlyAllowImages()
->setSubFolder('component_uploads')
->setMaxDocuments(1)
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(900),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(740),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(375),
])
->setSmallDragAndDropArea(),
(new Seperator()),
(new Title())
->setLabelText(__('KMS::attributes/components.options')),
(new OnOff())
->setReference('reversed')
->setLabelText(__('KMS::attributes/components.swap_text_image')),
(new Select())
->setItems(ComponentTypes::shapeOptions())
->setLabelText('Vorm')
->setReference('shape'),
]);
}
public function prepare(ViewComponent $viewComponent)
{
$viewComponent->faqItems = QuestionCategory::where('id', $viewComponent->question_set)
->first()
->questions()
->with('translation')
->get();
}
}