File: D:/HostingSpaces/SBogers10/medvalue.komma.pro/app/KommaApp/Shop/Discounts/DiscountSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Shop\Discounts;
//The new object oriented attributes
use App\KommaApp\Kms\Core\Attributes\DatePicker;
use App\KommaApp\Kms\Core\Attributes\Select;
use App\KommaApp\Kms\Core\Sections\AllUsedLanguagesTabsDirector;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\Seperator;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\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 DiscountService $sectionService
* @param RouteService $routeService
*/
// function __construct(Kms $kms, discountRepository $repository)
function __construct(DiscountService $sectionService, RouteService $routeService)
{
$sectionTabDirector = new AllUsedLanguagesTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
parent::__construct($sectionService, $routeService, $sectionTabDirector);
}
/**
* Generates the attributes for this section. They all must extend the App\KommaApp\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()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): 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 = $this->getSectionService();
$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 Seperator()),
(new TextField(__('kms/global.description')))
->setPlaceholderText(__('kms/global.description'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
]);
//****************************************************************************************************************************************\\
//*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection ***\\
//****************************************************************************************************************************************\\
$tabItems = new Collection();
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
foreach($languageIndexedAttributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
return $tabItems;
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
public function getModelTitle()
{
//If there is an title set use this
if ($this->getModel() && $this->getModel()->exists && ($this->getModel()->title || $this->getModel()->title != "")) {
return $this->getModel()->title;
}
return ucfirst(\Lang::get('kms'.DIRECTORY_SEPARATOR.'global.new_plural')) . ' ' . lcfirst(__('shop/discounts.discount'));
}
}