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/ZelfVerkopen/zelfverkopen.nl/app/KommaApp/PostAuthors/Kms/PostAuthorService.php
<?php

namespace App\KommaApp\PostAuthors\Kms;

use App\KommaApp\Kms\Core\Attributes\Models\SelectOption;
use App\KommaApp\Kms\Core\Sections\SectionService;
use App\KommaApp\Kms\SidebarListItem;
use App\KommaApp\PostAuthors\Models\PostAuthor;

class PostAuthorService extends SectionService
{
    protected $sortable = false;

    function __construct()
    {
        $this->forModelName = PostAuthor::class;

        parent::__construct();
    }

    /**
     * This method will get all the models.
     * And add these to the sidebarList.
     *
     * @return array $sidebarList
     */
    public function getModelsForSideBar():array
    {

        $authors = PostAuthor::all();

        $sidebarList = [];
        foreach ($authors as $author) {

            //New SidebarListItem
            $sidebarListItem = new SidebarListItem();
            $this->setThumbnail($author);
            $this->generateThumbnail($author);
            //Set the values for the sidebar
            $sidebarListItem->setId($author->id);
            $sidebarListItem->setName($author->name);
            $sidebarListItem->setThumbnail($author->thumbnail);

            $sidebarList[] = $sidebarListItem;
        }

        return $sidebarList;
    }

    /**
     * @param int|null $languageId
     * @param int|null $excludeId
     * @return array
     */
    public function getOptionsForSelect($languageId = null, int $excludeId = null): array
    {

        $entities = [];

        $authors = PostAuthor::all();

        foreach($authors as $author){
            $entities[] = (new SelectOption())
                ->setValue($author->id)
                ->setContent($author->id)
                ->setHtmlContent($author->name);
        }
        return $entities;

    }
}