File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/KommaApp/Companies/Kms/CompanySection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Companies\Kms;
//The new object oriented attributes
use App\KommaApp\CompanyCategories\Kms\CompanyCategoryService;
use App\KommaApp\Kms\Core\Attributes\MultiSelect;
use App\KommaApp\Kms\Core\Attributes\Documents;
use App\KommaApp\Kms\Core\Attributes\Models\ImageProperty;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Regions\Kms\RegionService;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Sites\SiteServiceInterface;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\Images;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\Select;
use App\KommaApp\Kms\Core\Attributes\Seperator;
use App\KommaApp\Kms\Core\Attributes\TextArea;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Sections\CurrentSiteLanguagesTabsDirector;
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 App\KommaApp\Users\Kms\UserService;
use Illuminate\Database\Eloquent\Collection;
class CompanySection extends Section
{
protected $slug = "companies";
public $showSave = 'all';
public $showDelete = 'all';
public $showCreate = 'all';
/**
* CompanySection constructor.
* @param CompanyService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
// function __construct(Kms $kms, CompanyRepository $repository)
function __construct(CompanyService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new CurrentSiteLanguagesTabsDirector(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\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 CompanyRepository::saveModel()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): Collection
{
// \Log::info("CompanySection::Generating attributes");
/** @var CompanyService $companyService */
$companyService = $this->getSectionService();
/** @var Model $model */
$model = $this->loadModel($this->getModel());
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$nameValidationSet = (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 TextField(__('kms/sites.type')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromItself, 'site_name')
->setStyleClass('hidden');
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$attributes[] = (new TextField(__('kms/companies.title')))
->setPlaceholderText(__('kms/companies.enterTitle'))
->setValidationSet($nameValidationSet)
->mapValueFrom(Attribute::ValueFromModel, 'name');
$attributes[] = (new Documents())
->setLabelText(__('kms/companies.logo'))
->onlyAllowImages()
->setMaxDocuments(1)
->setSubFolder('companies')
->setSmallDragAndDropArea()
->setImageProperties([
(new ImageProperty())->setName('original')->setCropMethod(ImageProperty::Resize)->setWidth(2000),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(500),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(300),
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(128)
])
->mapValueFrom(Attribute::ValueFromDocuments, 'logo');
$companyCategoryService = \App::make(CompanyCategoryService::class);
$companyCategoryModels= $companyCategoryService->getOptionsForSelect(true);
$attributes[] = (new Select())
->setItems($companyCategoryModels->toArray())
->setLabelText(__('kms/companies.company_category'))
->mapValueFrom(Attribute::ValueFromModel, 'company_category_id');
$regionService = \App::make(RegionService::class);
$regionModels= $regionService->getOptionsForSelect(true, true);
$attributes[] = (new Select())
->setItems($regionModels->toArray())
->setLabelText(__('kms/companies.region'))
->mapValueFrom(Attribute::ValueFromModel, 'region_id');
$attributes[] = (new Documents())
->setLabelText(__('kms/companies.detailPage'))
->onlyAllowImages()
->setMaxDocuments(5)
->setSubFolder('companies')
->mapValueFrom(Attribute::ValueFromDocuments, 'impression');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/companies.contactInformation')));
$attributes[] = (new TextField(__('kms/companies.address')))
->setPlaceholderText(__('kms/companies.enterAddress'))
->mapValueFrom(Attribute::ValueFromModel, 'address');
$attributes[] = (new TextField(__('kms/companies.postal')))
->setPlaceholderText(__('kms/companies.enterPostal'))
->mapValueFrom(Attribute::ValueFromModel, 'postal');
$attributes[] = (new TextField(__('kms/companies.city')))
->setPlaceholderText(__('kms/companies.enterCity'))
->mapValueFrom(Attribute::ValueFromModel, 'city');
$attributes[] = (new TextField(__('kms/companies.email')))
->setPlaceholderText(__('kms/companies.enterEmail'))
->mapValueFrom(Attribute::ValueFromModel, 'email');
$attributes[] = (new TextField(__('kms/companies.phone')))
->setPlaceholderText(__('kms/companies.enterPhone'))
->mapValueFrom(Attribute::ValueFromModel, 'phone');
$attributes[] = (new TextField(__('kms/companies.site')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'site_url');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/companies.invoiceInformation')));
$attributes[] = (new OnOff())
->setLabelText(__('kms/companies.preFillInvoiceCompany'))
->switchOn()
->setStyleClass('hidden')
->mapValueFrom(Attribute::ValueFromModel, 'pre_fill_invoice_to_company');
$attributes[] = (new TextField(__('kms/companies.address')))
->setPlaceholderText(__('kms/companies.enterAddress'))
->mapValueFrom(Attribute::ValueFromModel, 'invoice_address');
$attributes[] = (new TextField(__('kms/companies.postal')))
->setPlaceholderText(__('kms/companies.enterPostal'))
->mapValueFrom(Attribute::ValueFromModel, 'invoice_postal');
$attributes[] = (new TextField(__('kms/companies.city')))
->setPlaceholderText(__('kms/companies.enterCity'))
->mapValueFrom(Attribute::ValueFromModel, 'invoice_city');
$attributes[] = (new TextField(__('kms/companies.email')))
->setPlaceholderText(__('kms/companies.enterEmail'))
->mapValueFrom(Attribute::ValueFromModel, 'invoice_email');
$attributes[] = (new TextField(__('kms/companies.phone')))
->setPlaceholderText(__('kms/companies.enterPhone'))
->mapValueFrom(Attribute::ValueFromModel, 'invoice_phone');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/companies.socialMedia')));
$attributes[] = (new TextField(__('kms/companies.instagram')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'instagram');
$attributes[] = (new TextField(__('kms/companies.linkedin')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'linkedin');
$attributes[] = (new TextField(__('kms/companies.facebook')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'facebook');
$attributes[] = (new TextField(__('kms/companies.twitter')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'twitter');
$attributes[] = (new TextField(__('kms/companies.youtube')))
->setPlaceholderText(__('kms/companies.enterUrl'))
->mapValueFrom(Attribute::ValueFromModel, 'youtube');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/companies.team')));
$userService = \App::make(UserService::class);
$userSelectModels = $userService->getNonBindOrToThisCompanyOptionsForAutocompletInput($model);
$attributes[] = (new MultiSelect())
->setLabelText(__('kms/companies.teamMembers'))
->setItems($userSelectModels->toArray())
->enableSortable()
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'users|id');
// $attributes[] = (new Documents())
// ->setLabelText(__('kms/global.documents'))
// ->setSubFolder('companies')
//// ->setMaxDocuments(4)
// ->setEnablePreviewsIfPossible(true)
// ->mapValueFrom(Attribute::ValueFromDocuments, 'documents');
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new TextArea())
->setLabelText(__('kms/global.description'))
->setPlaceholderText(__('kms/global.enterDescription'))
->enableTinymceEditor()
->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 [];
}
}