<?php

namespace App\Admin\Repositories;

use App\Models\SiteMenu as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class SiteMenu extends EloquentRepository
{

    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;




    /*
     * 只能显示2层
     */
    public static function selectOptions(\Closure $closure = null)
    {
        if (!$closure) {
            $closure = function ($query) {
                $query =  $query->where('dist_id', getDistributorId())->orderBy('order', 'asc');
                return $query;
            };
        }
        $selectOptions =  Model::class::selectOptions($closure);
        //只显示2层
        foreach ($selectOptions as $key => $value) {
            if (substr_count($value,'&nbsp;') > 2) {
                unset($selectOptions[$key]);
            }
        }
        return $selectOptions;
    }

    /*
    * 获取一个标签
    */
    public static function getOneById($id)
    {
        return Model::where('id', $id)->where('dist_id', getDistributorId())->first();
    }

    public static function createMenuBatch($data) {
        $model = new Model();
        return $model->createMenuBatch($data);
    }

    //生成uri
    public static function generateUri($menuType,$menuConfig,$distId,$isId = true) {
        $model = new Model();
        return $model->generateUri($menuType,$menuConfig,$distId,$isId);
    }

}
