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/somerenslust.komma.pro/app/KommaApp/Countries/CountryRepository.php
<?php

namespace App\KommaApp\Countries;

use App\KommaApp\Kms\Core\Attributes\Models\SelectOption;
use App\KommaApp\Kms\Core\KmsRepository;
use App\KommaApp\Countries\Models\Country;
use Illuminate\Database\Eloquent\Model;

class CountryRepository extends KmsRepository
{
    /**
     * @var Country
     */
    protected $countryModel;

    function __construct()
    {
        $this->countryModel = new Country();
    }

    public function getOptionModelsForSelect(int $siteId = null, int $languageId = null, int $excludeId = null): array
    {
        $countriesCollection = $this->allCountries();

        /** @var $optionModels SelectOption[] */
        $optionModels = [];

        $countriesCollection->each(function($country) use(&$optionModels) {
            /** @var Country $country */
            $selectOptionsModel = new SelectOption();
            $selectOptionsModel->setHtmlContent($country->name)->setContent($country->name)->setModel($country);

            $optionModels[] = $selectOptionsModel;
        });

        return $optionModels;
    }

    public function allCountries()
    {
        return Country::all();
    }

    public function siteCountry()
    {
        return \DB::table('countries')
            ->join('sites', 'sites.country_id', '=', 'countries.id')
            ->select('countries.iso_2')
            ->where('sites.id', \Site::getId() )
            ->first();
    }

    public function getCountryByIso2($iso2)
    {
        return $this->countryModel
            ->where('iso_2', $iso2)
            ->first();
    }

    public function newModel($siteId = null): Model
    {
        return new Country();
    }

    /**
     * This method will get a model based on the id.
     * When the id is NULL or the model does not exist, we will generate a new.
     *
     * @see KmsSection::loadModel()
     * @param int $modelId
     * @return Model
     */
    public function getModel($modelId = null): Model
    {
        // TODO: Implement getModel() method.
    }
}