HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Shop/Shipments/ShipmentSection.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\Shop\Shipments;

//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\Link;
use App\Komma\Kms\Core\Attributes\Models\SelectOption;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
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\Sites\SiteServiceInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\MessageBag;

class ShipmentSection extends Section
{

    protected $slug = 'shipments';

    public $showSave = 'all';
    public $showDelete = [1];
    public $showCreate = [1];

    /** @var RegionInfo */
    private $regionInfo;

    /**
     * ProductSection constructor.
     *
     * @param ShipmentService $shipmentService
     * @param SiteServiceInterface $siteService
     * @param RouteService $routeService
     */
//    function __construct(Kms $kms, PageRepository $repository)
    function __construct(ShipmentService $sectionService, 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->regionInfo = new RegionInfo('NL');
    }

    /**
     * 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 Shipment $model */
        $model = $this->getModel();

        //*****************************************************************************************\\
        //*** Define attribute validation sets                                                  ***\\
        //*****************************************************************************************\\


        //*****************************************************************************************\\
        //*** Determine and define status dropdown data                                         ***\\
        //*****************************************************************************************\\
        $statusOptions = [];
        foreach(ShipmentStatus::getAsArray() as $shipmentStatus) {
            $statusOptions[] = (new SelectOption())->setContent(__('shop/shipments.status.'.$shipmentStatus))->setHtmlContent(__('shop/shipments.status.'.$shipmentStatus))->setValue($shipmentStatus);
        }


        //*****************************************************************************************\\
        //*** Generate the attributes                                                           ***\\
        //*****************************************************************************************\\
        $attributes = [];

        $attributes[] = (new Select())
            ->setItems($statusOptions)
            ->setLabelText(__('shop/shipments.status_name'))
            ->mapValueFrom(Attribute::ValueFromModel, 'status');

        $attributes[] = (new Link(__('shop/orders.order'), 'order'))
            ->setLink(route('orders.show', ['order' => $model->order]))
            ->setLinkText($model->order->order_number.' ('.$model->order->customer->first_name.' '.$model->order->customer->last_name.')');

        if($model->shipmentGroup) {
            $attributes[] = (new Link(__('shop/shipmentgroups.shipmentGroup'), 'shipment_group'))
                ->setLink(route('shipmentgroups.show', ['shipmentgroups' => $model->shipmentGroup]))
                ->setLinkText($model->shipmentGroup->id . '  (' . $model->shipmentGroup->created_at . ')');
        } else {
            $attributes[] = (new TextField(__('shop/shipmentgroups.shipmentGroup')))
                ->setValue(__('shop/shipmentgroups.no_shipmentGroup'))
                ->setReadOnly(true)
                ->mapValueFrom(Attribute::ValueFromItself, 'no_shipping_group_textfield');
        }

        $attributes[] = (new TextField(__('shop/shipments.tracking_code')))
            ->mapValueFrom(Attribute::ValueFromModel, 'tracking_code');

        $attributes[] = (new TextArea())
            ->setLabelText(__('shop/shipments.comment'))
            ->mapValueFrom(Attribute::ValueFromModel, 'comment');

        //****************************************************************************************************************************************\\
        //*** 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 renderShipmentIndex() {
        $saveRoute = $this->routeService->getSaveRoute($this->getSlug(), $this->getModelId());

        $successes = (\Session::has('successes')) ? \Session::get('successes') : new MessageBag();

        return view('kms/shop/shipments/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 [];
    }
}