<?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($MLpgq, $BjHij, $TSeSR) { $YMF1Z = intval(ModelUtil::max('nav', 'sort')) + 1; ModelUtil::insert('nav', array('position' => $MLpgq, 'name' => $BjHij, 'link' => $TSeSR, 'sort' => $YMF1Z)); } public static function tree() { $KZY1l = TreeUtil::modelToTree('nav', array('position' => 'position', 'name' => 'name', 'openType' => 'openType', 'link' => 'link', 'icon' => 'icon'), 'id', 'pid', 'sort', array('enable' => true)); return $KZY1l; } public static function listByPosition($MLpgq = 'header') { $KZY1l = self::tree(); return array_filter($KZY1l, function ($vPOhn) use($MLpgq) { return $vPOhn['position'] == $MLpgq; }); } public static function listByPositionWithCache($MLpgq = 'header', $jlaFt = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $MLpgq, $jlaFt, function () use($MLpgq) { return self::listByPosition($MLpgq); }); } public static function hasData($MLpgq = 'header') { $XoEfM = self::listByPositionWithCache($MLpgq); return !empty($XoEfM); } public static function clearCache() { foreach (NavPosition::getList() as $JdFJR => $hx4PQ) { Cache::forget(self::CACHE_KEY_PREFIX . $JdFJR); } } }