File: D:/HostingSpaces/SBogers10/conmeq.komma.pro/app/Komma/Shop/ShipmentGroups/ShipmentGroupSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Shop\ShipmentGroups;
//The new object oriented attributes
use App\Helpers\KommaHelpers;
use App\Komma\Globalization\RegionInfo;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Models\SelectOption;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\View;
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\Shop\Shipments\Shipment;
use App\Komma\Shop\Shipments\ShipmentService;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\MessageBag;
class ShipmentGroupSection extends Section
{
protected $slug = 'shipmentgroups';
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/** @var ShipmentGroupService */
protected $shipmentGroupService;
/**
* @var ShipmentService
*/
private $shipmentService;
/** @var RegionInfo */
private $regionInfo;
/**
* ProductSection constructor.
*
* @param ShipmentGroupService $sectionService
* @param ShipmentService $shipmentService
* @param ShipmentGroupService $shipmentGroupService
* @param SiteServiceInterface $siteService
* @param RouteService $routeService
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct(ShipmentGroupService $sectionService, ShipmentService $shipmentService, ShipmentGroupService $shipmentGroupService, SiteServiceInterface $siteService, RouteService $routeService)
{
$sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
$this->shipmentService = $shipmentService;
$this->regionInfo = new RegionInfo('NL');
$this->shipmentGroupService = $shipmentGroupService;
}
/**
* 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
{
/** @var ShipmentGroup $model */
$model = $this->getModel();
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Determine and define status dropdown data ***\\
//*****************************************************************************************\\
$statusOptions = [];
foreach(ShipmentGroupStatus::getAsArray() as $shipmentGroupStatus) {
$statusOptions[] = (new SelectOption())->setContent(__('shop/shipmentGroups.status.'.$shipmentGroupStatus))->setHtmlContent(__('shop/shipmentGroups.status.'.$shipmentGroupStatus))->setValue($shipmentGroupStatus);
}
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new Select())
->setItems($statusOptions)
->setLabelText(__('shop/shipmentGroups.status_name'))
->mapValueFrom(Attribute::ValueFromModel, 'status');
$attributes[] = (new View('shop.partials.shipmentGroups.show'))->setViewData([
'saveRoute' => $this->routeService->getSaveRoute($this->getSlug(), $this->getModelId()),
'shipmentGroup' => $model,
'shipmentGroupShipments' => $model->shipments()->with('order')->get(),
'shipments' => Shipment::whereDoesntHave('shipmentGroup')->get(),
'regionInfo' => $this->regionInfo,
]);
//****************************************************************************************************************************************\\
//*** 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));
return $tabItems;
}
/**
* For the index controller action
*
* @return \Illuminate\Contracts\View\View
*/
public function renderShipmentGroupIndex() {
$saveRoute = $this->routeService->getSaveRoute($this->getSlug(), $this->getModelId());
$successes = (\Session::has('successes')) ? \Session::get('successes') : new MessageBag();
return view('kms/shop/shipmentGroups/index', [
'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'))
]);
}
/**
* Makes a full width view. The sidebar is not needed
*
* @return \Illuminate\Contracts\View\View
*/
protected function makeView(): \Illuminate\Contracts\View\View
{
$saveRoute = $this->routeService->getSaveRoute($this->getSlug(), $this->getModelId());
$successes = (\Session::has('successes')) ? \Session::get('successes') : new MessageBag();
return view('kms/section.fullwidth', [
'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')),
]);
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}