File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Inventories/Kms/InventorySection.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Inventories\Kms;
//The new object oriented attributes
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\AutocompleteInput;
use App\Komma\Kms\Core\Attributes\DataTable;
use App\Komma\Kms\Core\Attributes\Models\DataTableColumn;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\Seperator;
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\AllUsedLanguagesTabsDirector;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\SectionTabGroups;
use App\Komma\Kms\Core\Sections\SectionTabItem;
use App\Komma\Kms\Core\Sections\SectionTabsBuilder;
use App\Komma\Kms\Core\ValidationSet;
use App\Komma\PricingLabels\Kms\PricingLabelService;
use App\Komma\Routes\RouteService;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Database\Eloquent\Collection;
class InventorySection extends Section
{
protected $slug = 'inventories';
/**
* PageSection constructor.
* @param InventoryService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
// function __construct(Kms $kms, PageRepository $repository)
public function __construct(InventoryService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new AllUsedLanguagesTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
}
/**
* 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 PageRepository::saveModel()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): Collection
{
// \Log::info("PageSection::Generating attributes");
$numberValidationSet = (new ValidationSet())
->setRules('nullable|numeric')
->setMessages(['numeric' => __('validation.numeric'), 'nullable' => '']);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$siteOptionModels = $this->siteService->getOptionsForSelect();
$attributes[] = (new AutocompleteInput())
->setItems($siteOptionModels->toArray())
->setLabelText(__('kms/sites.type'))
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromItself, 'site_id');
$pageOptionModels = $this->sectionService->getOptionsForSelect();
$attributes[] = (new Select())
->setItems($pageOptionModels->toArray())
->setLabelText(__('kms/pages.parent_page'))
->setExcludeCurrentModelItem(true)
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromModel, 'parent_id');
$attributes[] = (new Seperator())
->setStyleClass('hidden');
$attributes[] = (new OnOff())
->setLabelText('Popular product?')
->mapValueFrom(Attribute::ValueFromModel, 'popular_product');
$attributes[] = (new TextField('Price Euro'))
->setValidationSet($numberValidationSet)
->setReadOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'price_eu');
$attributes[] = (new TextField('Price Dollar'))
->setValidationSet($numberValidationSet)
->setReadOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'price_usd');
$attributes[] = (new OnOff())
->setLabelText('Enterprise product?')
->mapValueFrom(Attribute::ValueFromModel, 'enterprise_product')
->setExplanation('If selected, texts will be displayed instead of the prices above. (See language tabs.)');
$attributes[] = (new Seperator());
$attributes[] = (new Title('Linked labels'));
$attributes[] = (new AutocompleteInput())
->setLabelText('Labels')
->fillWith(PricingLabelService::class.'@getOptionsForSelect')
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'pricinglabels|id')
->setExplanation('Only select the labels/ properties that this package has. <br>Save after deleting labels before adding new labels.');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
(new OnOff())
->setLabelText(__('kms/global.active'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'active'),
(new TextField(__('kms/global.name')))
->setPlaceholderText(__('kms/global.enterName'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new TextArea())
->setLabelText(__('kms/global.description'))
->setPlaceholderText(__('kms/global.enterDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
(new TextField('Price text'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'price_text')
->setPlaceholderText('Ex.: Custom')
->setExplanation('Only if Enterprise'),
(new TextField('Additional price text'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'price_text_additional')
->setPlaceholderText('Ex.: Custom plans and pricing to suit your needs')
->setExplanation('Only if Enterprise'),
(new TextField('Button text'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'button_text')
->setPlaceholderText('Ex.: Let\'s talk!')
->setExplanation('Only if Enterprise'),
(new TextField('Features text'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'features_text')
->setPlaceholderText('Ex.: Everything included in pro plus:')
->setExplanation('Only if Enterprise'),
(new TextField('Bottom CTA button text'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'cta_button_text')
->setPlaceholderText('Ex.: Talk to an expert')
->setExplanation('Only if Enterprise'),
(new DataTable())
->setLabelText('Features table')
->setExplanation('Make sure al the labels between packages are identical, a typo can cause a label to not be displayed.')
->setTableStructure([
new DataTableColumn(DataTableColumn::INPUT_TEXT, 'Label'),
new DataTableColumn(DataTableColumn::TEXTAREA, 'Tooltip'),
new DataTableColumn(DataTableColumn::ON_OFF, 'Feature is category?', false, 2),
new DataTableColumn(DataTableColumn::ON_OFF, 'Has feature?', false, 2),
])
->mapValueFrom(Attribute::ValueFromTranslationModel, 'features'),
]);
//****************************************************************************************************************************************\\
//*** 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 [];
}
}