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/SBogers96/smilefotografie.nl/app/Komma/Albums/AlbumService.php
<?php


namespace Komma\Albums;


class AlbumService
{
    /**
     * @var AlbumRepository
     */
    private $repository;

    /**
     * @param AlbumRepository $repository
     */
    public function __construct(AlbumRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * Get all albums from a page
     *
     * @param $page
     * @return mixed
     */
    public function albumsByPage($page)
    {
        // Push page info to repository
        $this->repository->setPage($page);

        // Return filtered albums from page
        if($filter = $this->getFilter($page)) return $this->repository->albumsByPage($filter);

        // Return all albums from page
        return $this->repository->albumsByPage();
    }

    /**
     * @param $page
     * @param $albumId
     * @return mixed
     */
    public function albumByPageAndId($page, $albumId)
    {
        // Push page info to repository
        $this->repository->setPage($page);

        if($filter = $this->getFilter($page))
        {
            // If filter is needed, the second argument is true
            $album = $this->repository->albumById($albumId, true);
        }
        else
        {
            // Get album information
            $album = $this->repository->albumById($albumId);
        }

        // Get album images
        $album = $this->addImagesToAlbum($album);

        return $album;
    }

    /**
     * Determine if page has (or should have) a filter
     */
    public function getFilter($page)
    {
        // Return false if page doesn't require filters
        if( ! has_filter($page->code_name)) return false;

        // If we have a queryString with filter take that value
        // Or else get the default filter from the array above
        \Request::has('filter') ?
            $filter = \Request::get('filter') :
            $filter = \Config::get('komma.filteredPages')[$page->code_name];

        return $filter;
    }

    /**
     * @param $album
     * @return object
     */
    private function addImagesToAlbum($album)
    {
        // Convert to array so we can add images
        $album = (array) $album;

        // Add images
        $album['images'] = $this->repository->imagesFromAlbum($album['id']);

        // Return album as StdClass again
        return (object) $album;
    }
}