<?php

namespace Diamond\Repositories;

use Core\Repository\CrudInterface;
use Core\Repository\PropelQueryAbstract;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;


/**
 * Description of ContentCategory
 *
 * @author Admin
 */
class Domain extends PropelQueryAbstract implements CrudInterface, \Core\Repository\DropDownInterface
#,
  #  \Shop\Contracts\ShopCurrentInterface
{

    #use \Shop\Concrete\ShopAuthUserTrait;

    public function buildEntity()
    {
        return new \Diamond\Infrastructure\Models\Domain\Domain();
    }

    public function buildQuery()
    {
        return \Diamond\Infrastructure\Models\Domain\DomainQuery::create();
    }

    public function getDropdownList():array
    {
        /**
         * @todo Реализовать работу с поддоменами на уровне новых CRUD репозиторий и критерий выборки
         */
        #$id = is_a($this->curShop,ActiveRecordInterface::class) ? $this->curShop->getId() : 0;
        $id = 0;
        return $this->buildQuery()
            ->orderByName()
            ->_if($id > 0)
            ->addJoin("_domains.id", "`shop_shops`.`domain_id`")
            ->where("`shop_shops`.`id` = " . $id)
            ->_endif()
            ->find()
            ->toKeyValue('id', 'name');
    }
}
