<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Dcat\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;

class SiteAlbumFolder extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'site_album_folder';
    public $titleColumn = 'title';


    public static function selectOptionsEn(\Closure $closure = null, $rootText = null)
    {
        $obj = new static();
        $obj->titleColumn = 'title_en';

        $rootText = $rootText ?: admin_trans_label('root');

        $options = ($obj)->withQuery($closure)->buildSelectOptions();

        return collect($options)->prepend($rootText, 0)->all();
    }


    use HasDateTimeFormatter,
        ModelTree {
        ModelTree::boot as treeBoot;
    }

    public  function setTitleColumn($column)
    {
        $this->titleColumn = $column;
    }


    public function allNodes()
    {
        $result =  $this->callQueryCallbacks(new static())
            ->where('enabled',1)
            ->orderBy($this->getOrderColumn(), 'desc')
            ->get();

        return $result;
    }

}
