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/SBogers85/equichecker.com/app/KommaApp/Kms/Core/KmsRepository.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

namespace KommaApp\Kms\Core;

use Illuminate\Support\Collection;
use KommaApp\Images\Models\Image;

abstract class KmsRepository
{
    protected $kms;
    protected $sortable = false;

    function __construct(Kms $kms)
    {
        $this->kms = $kms;
    }

    /*
    abstract public function newEntity();
    abstract public function getEntity($id);
    abstract public function getEntities();
    abstract public function saveEntity($entity);
    abstract public function destroyEntity($id);
    */

    /**
     * This method will delete all the images of this page
     * @param $id
     */
    public function deleteModelImages($id)
    {
        if (!method_exists($this, 'getImages')) return false;
        //Load images, if none return
        if (!$images = $this->getImages($id)) return;
        //loop trough the images
        foreach ($images as $image) {
            //remove image from db and server
            Image::destroy($image->id);
        }
        return;
    }

    public function getSortable()
    {
        return $this->sortable;
    }

    public function getModelsForSelect($siteId = null, $languageId = null, $excludeId = null)
    {
        //Check if the getModelsAsTree metod exist
        if (!method_exists($this, 'getModelsAsTree')) {
            //No basic model, get Models
            $models = $this->getModels($siteId);

            $entities = [['value' => '/', 'content' => '/']];
            if ($excludeId == 'empty') $entities = [];
            foreach ($models as $model) {
                $entity = [];
                $entity['value'] = $model->getId();
                $entity['content'] = $model->getName();
                $entities[] = $entity;
            }
            return $entities;
        }
        if (!$siteId) $siteId = $this->kms->getCurrentSiteId();
        $tree = $this->getModelsAsTree($siteId, $languageId);
        if ($excludeId) $tree->removeFromIndex((int)$excludeId);
        // QnD !!! Indexing trees per language (multiple queries)
        $treePerLanguage = [];
        foreach ($this->kms->getSiteLanguages($siteId) as $language) {
            $treePerLanguage[$language->id] = $this->getModelsAsTree($siteId, $language->id);
        }
        // End QnD !!!
        $entities = [];
        foreach ($tree->getIndex() as $record) {

            $entity = [];
            $entity['value'] = $record->node->id;

            $nodeName = null;


            $entity['routes'] = [];

            $paths = [];
            foreach ($this->kms->getSiteLanguages($siteId) as $language) {

                //Get the primary route for the current language
                $path = $treePerLanguage[$language->id]->getEntityById($entity['value'])->getPrimaryRouteAlias($language);
                //Set to the routes
                $entity['routes'][$language->id] = $path ? $path . '/' : '';

                //If $nodeName exist, continue
                if ($nodeName) continue;
                //No nodeName, get one
                $nodeName = $treePerLanguage[$language->id]->getEntityById($entity['value'])->getTranslationField('name', $language);
            }
            //Todo: remove this line when it is realy not necessary
            //  $entity['fullValue'] = json_encode($paths);

            //content for chosen value
            $entity['content'] = (empty($nodeName) ? '\\' : $nodeName);

            //Set the spaces for an indent (three)
            $indent = str_repeat('&nbsp;&nbsp;&nbsp;', $record->getDepth());

            //Set the content for the dropdown list
            $entity['htmlContent'] = $indent . (empty($nodeName) ? '\\' : $nodeName);

            $entities[] = $entity;
        }
        return $entities;
    }
}