File: D:/HostingSpaces/SBogers10/vangogh.komma.pro/app/Komma/WebsiteConfig/WebsiteConfigSection.php
<?php
namespace App\Komma\WebsiteConfig;
use App\Helpers\KommaHelpers;
use App\Komma\Buttons\Kms\ButtonService;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Documents;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\MultiSelect;
use App\Komma\Kms\Core\Attributes\Seperator;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\NoLanguageTabsDirector;
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\Routes\RouteService;
use App\Komma\Servicepoints\Kms\ServicepointService;
use App\Komma\Servicepoints\Models\Servicepoint;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUserRole;
use App\Komma\WebsiteConfig\Model\WebsiteConfig;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Contracts\View\View;
use Illuminate\Support\MessageBag;
class WebsiteConfigSection extends Section
{
protected $title = "Website";
protected $subTitle = "Configurations";
protected $slug = "websiteconfig";
public $showSave = 'all'; // Options: 'all' | 'admin' (SuperAdmin only) | 'none' (or anything else what isn't all or admin)
public $showDelete = 'admin';
public $showCreate = 'admin';
/**
* PageSection constructor.
* @param PostService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct(WebsiteConfigService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new NoLanguageTabsDirector(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
* @throws \Exception
*/
protected function generateAttributes(): Collection
{
$tabItems = $this->generateFixedAttributes();
return $tabItems;
}
/**
* Generate fixed attributes
*
* @return Collection
*/
private function generateFixedAttributes():Collection
{
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new Title('Bedrijfsgegevens'));
$attributes[] = (new TextField('Url'))
->mapValueFrom(Attribute::ValueFromModel, 'company_url');
$attributes[] = (new TextField('Bedrijfsnaam'))
->mapValueFrom(Attribute::ValueFromModel, 'company_name');
$attributes[] = (new TextField('Adres'))
->mapValueFrom(Attribute::ValueFromModel, 'company_address');
$attributes[] = (new TextField('Postcode'))
->mapValueFrom(Attribute::ValueFromModel, 'company_zip');
$attributes[] = (new TextField('Stad'))
->mapValueFrom(Attribute::ValueFromModel, 'company_city');
$attributes[] = (new TextField('Land'))
->mapValueFrom(Attribute::ValueFromModel, 'company_country');
$attributes[] = (new TextField('KVK'))
->mapValueFrom(Attribute::ValueFromModel, 'company_kvk');
$attributes[] = (new TextField('E-mail'))
->mapValueFrom(Attribute::ValueFromModel, 'company_email');
$attributes[] = (new TextField('Telefoon link'))
->mapValueFrom(Attribute::ValueFromModel, 'company_phone_call');
$attributes[] = (new TextField('Telefoon weergave'))
->mapValueFrom(Attribute::ValueFromModel, 'company_phone_display');
$attributes[] = (new Seperator());
$attributes[] = (new Title('Sociale media'));
$attributes[] = (new TextField('Facebook'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_facebook');
$attributes[] = (new TextField('Linkedin'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_linkedin');
$attributes[] = (new TextField('Instagram'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_instagram');
$attributes[] = (new TextField('Twitter'))
->mapValueFrom(Attribute::ValueFromModel, 'company_social_twitter');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/global.logos')));
$attributes[] = (new Documents())
->setLabelText(__('kms/global.logo_on_light'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(147)->setHeight(48),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'logo_on_light');
$attributes[] = (new Documents())
->setLabelText(__('kms/global.logo_on_dark'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(1)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(152)->setHeight(50),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'logo_on_dark');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/global.hero')));
$attributes[] = (new Documents())
->setLabelText(__('kms/global.images'))
->onlyAllowImages()
->setSmallDragAndDropArea()
->setMaxDocuments(5)
->setSubFolder('home')
->setImageProperties([
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Fit)->setWidth(1152)->setHeight(640),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Fit)->setWidth(920)->setHeight(460),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(837)->setHeight(465),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'home_heroes');
$attributes[] = (new TextField(__('kms/global.heroTitle')))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'home_hero_title');
$attributes[] = (new Seperator());
$attributes[] = (new Title(__('kms/global.cta')));
$attributes[] = (new TextField('CTA Heading'))
->mapValueFrom(Attribute::ValueFromModel, 'global_CTA_heading');
$servicepointService = \App::make(ServicepointService::class);
$servicepointOptions = $servicepointService->getOptionsForSelect(false, true);
$attributes[] = (new MultiSelect())
->setItems($servicepointOptions->toArray())
->setLabelText(__('CTA contactpersoon'))
->setMaxItemsToSelect(1)
->canBeLinkedWith(Servicepoint::class)
->mapValueFrom(Attribute::ValueFromModel, 'global_CTA_servicepoint_id');
$buttonsService = \App::make(ButtonService::class);
$buttonModels = $buttonsService->getOptionsForSelect();
$attributes[] = (new MultiSelect())
->setItems($buttonModels->toArray())
->setMaxItemsToSelect(1)
->setLabelText('CTA Button')
->mapValueFrom(Attribute::ValueFromModel, 'global_CTA_button_id');
$tabItems = new Collection();
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
return $tabItems;
}
/**
* Makes the view and returns it
*
* @return View
*/
protected function makeView(): View
{
$tabslug = null !== \Input::get('tabslug') ? \Input::get('tabslug') : \Session::get('tabslug', '');
$sessionData = [
'tabslug' => $tabslug
];
$saveRoute = $this->routeService->getSaveRoute($this->getSlug(), $this->getModelId());
$successes = (\Session::has('successes')) ? \Session::get('successes') : new MessageBag();
return view('kms/section.website_config', [
'siteSlug' => !$this->siteService->getCurrentSite()->exists ? null : $this->siteService->getCurrentSite()->slug,
'section' => $this,
'saveRoute' => $saveRoute,
'successes' => $successes,
'maxUploadSize' => KommaHelpers::fileUploadMaxSize(),
'maxPostSize' => KommaHelpers::maxPostSize(),
'preventNavigationTranslation' => json_encode(__('kms/prevent-navigation'))
])->with($sessionData);
}
/**
* Returns a rendered view
*
* @return View
*/
public function render()
{
$this->generateAttributesAndAddThemToTabs();
$this->getSectionService()->fillAttributesWithData($this->sectionTabItems, new WebsiteConfig());
return $this->makeView();
}
public function getThumbnail()
{
return '<img src="/kms/img/icons/settings-icon.gif">';
}
}