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/SBogers10/zelfverkopen.komma.pro/app/KommaApp/Customers/Kms/CustomerService.php
<?php

namespace App\KommaApp\Customers\Kms;


use App\KommaApp\Customers\Models\Customer;
use App\KommaApp\Kms\Core\Attributes\Models\SelectOption;
use App\KommaApp\Kms\Core\Sections\SectionService;
use App\KommaApp\Kms\SidebarListItem;
use Illuminate\Database\Eloquent\Model;

class CustomerService extends SectionService
{
    protected $sortable = false;

    function __construct()
    {
        $this->forModelName = Customer::class;
        parent::__construct();
    }

    /**
     * Make gender select
     *
     * @return array
     */
    public function getGenderSelect()
    {

        $categories = [
            Customer::CUSTOMER_GENDER_UNDEFINED,
            Customer::CUSTOMER_GENDER_MALE,
            Customer::CUSTOMER_GENDER_FEMALE,
        ];

        $entities = [];

        foreach ($categories as $category) {
            $entities[] = (new SelectOption())
                ->setValue($category)
                ->setHtmlContent(__('orders.gender.'.$category));
        }

        return $entities;
    }

    public function getCustomersForSelect()
    {
        $customers = Customer::where('status', Customer::CUSTOMER_STATUS_ACTIVE)
            ->orderBy('last_name')
            ->get();

        $entities = [];

        foreach ($customers as $customer) {
            $entities[] = (new SelectOption())
                ->setValue($customer->id)
                ->setHtmlContent(__('orders.genderTitle.'.$customer->gender).' ' . $customer->last_name. ' | '.$customer->zip . ' ' .$customer->city);
        }

        return $entities;
    }

    /**
     * Returns all models for the sidebar menu in the backend
     *
     * @return array
     */
    public function getModelsForSideBar():array
    {
        if(isset($this->orderBy)){
            if($this->orderReverse) $models = $this->forModelName::orderBy($this->orderBy, 'desc')->get();
            else $models = $this->forModelName::orderBy($this->orderBy)->get();
        }
        else $models = $this->forModelName::all();

        $sidebarList = [];
        foreach ($models as $model) {
            $sidebarListItem = new SidebarListItem();
            $this->setThumbnail($model);
            $this->generateThumbnail($model);

            //Set the values for the sidebar
            $sidebarListItem->setId($model->id);
            $sidebarListItem->setStatus($model->status);
            $title = \App\Helpers\KommaHelpers::str_limit_full_word($model->title, 75);
            $sidebarListItem->setName($title);
            $sidebarListItem->setThumbnail($model->thumbnail);

            $sidebarList[] = $sidebarListItem;
        }

        return $sidebarList;
    }

    /**
     * This method will remove an instance
     *
     * @param $model
     * @throws \Exception
     */
    public function destroyModel(Model $model)
    {
        //delete the images
        $this->imageService->deleteModelImages($model);

        $model->customerProperties()->delete();
        $model->delete();
    }
}