File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Shop/Discounts/DiscountSection.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Shop\Discounts;
//The new object oriented attributes
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\DatePicker;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class DiscountSection extends Section
{
protected $title = 'Discounts';
protected $subtitle = 'All discounts';
protected $slug = 'discounts';
protected $hasRoutes = true;
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/**
* discountSection constructor.
* @param $slug
*/
public function __construct(string $slug)
{
if (app()->runningInConsole()) {
return;
}
$tabs = new NoLanguageTabs();
parent::__construct($tabs, $slug);
}
/**
* Generates the attributes for this section. They all must extend the App\Komma\Kms\Core\Attributes\Attribute class
* This is the place where you need to setup your sections appearance. Just make sure you build an array of attributes
* and put each attribute in a AbstractSectionTabItem with a SectionTabGroups constant to link them to a tab.
*
* @see discountRepository::saveModel()
* @param Model|null $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
// \Log::info("discountSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$codeNameValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('shop/discounts.discount')));
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
/** @var DiscountService $sectionService */
$sectionService = new DiscountService();
$typeOptionModels = $sectionService->getOptionsModelsForTypeSelect();
$attributes[] = (new Select())
->setItems($typeOptionModels)
->setLabelText(__('shop/discounts.type'))
->mapValueFrom(Attribute::ValueFromModel, 'type');
$attributes[] = (new TextField(__('shop/discounts.condition_settings')))
->setExplanation(__('shop/discounts.condition_settings_explanations'))
->mapValueFrom(Attribute::ValueFromModel, 'condition_settings');
$attributes[] = (new TextField(__('shop/discounts.action_settings')))
->setExplanation(__('shop/discounts.action_settings_explanations'))
->mapValueFrom(Attribute::ValueFromModel, 'action_settings');
$attributes[] = (new DatePicker(__('shop/discounts.valid_from')))
->setAnimation(DatePicker::ANIMATION_SLIDEDOWN)
->setChangeYearAndMonth(true)
->setLanguage(DatePicker::LANGUAGE_DUTCH)
->mapValueFrom(Attribute::ValueFromModel, 'valid_from');
$attributes[] = (new DatePicker(__('shop/discounts.valid_trough')))
->setAnimation(DatePicker::ANIMATION_SLIDEDOWN)
->setChangeYearAndMonth(true)
->setLanguage(DatePicker::LANGUAGE_DUTCH)
->mapValueFrom(Attribute::ValueFromModel, 'valid_trough');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
(new Title(__('kms/global.information'))),
(new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'title'),
(new TextArea(__('kms/global.description')))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
]);
//Return all attributes as a collection
return collect(array_merge($attributes, $languageIndexedAttributes));
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*/
public function loadEntities()
{
return [];
}
}