<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Nav\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\TreeUtil; use Module\Nav\Type\NavPosition; class NavUtil { const CACHE_KEY_PREFIX = 'nav:'; public static function add($yNvL_, $TTiWe, $ZWOTY) { $PA0lb = intval(ModelUtil::max('nav', 'sort')) + 1; ModelUtil::insert('nav', array('position' => $yNvL_, 'name' => $TTiWe, 'link' => $ZWOTY, 'sort' => $PA0lb)); } public static function tree() { $Z1XeS = TreeUtil::modelToTree('nav', array('position' => 'position', 'name' => 'name', 'openType' => 'openType', 'link' => 'link', 'icon' => 'icon'), 'id', 'pid', 'sort', array('enable' => true)); return $Z1XeS; } public static function listByPosition($yNvL_ = 'header') { $Z1XeS = self::tree(); return array_filter($Z1XeS, function ($kHxHl) use($yNvL_) { return $kHxHl['position'] == $yNvL_; }); } public static function listByPositionWithCache($yNvL_ = 'header', $nrH5w = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $yNvL_, $nrH5w, function () use($yNvL_) { return self::listByPosition($yNvL_); }); } public static function hasData($yNvL_ = 'header') { $uA2kT = self::listByPositionWithCache($yNvL_); return !empty($uA2kT); } public static function clearCache() { foreach (NavPosition::getList() as $ynzcc => $zabGJ) { Cache::forget(self::CACHE_KEY_PREFIX . $ynzcc); } } }