<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Res\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ArrayUtil; use ModStart\Core\Util\TreeUtil; class ResCategoryUtil { const CACHE_KEY = 'ResCategory:'; public static function clearCache() { Cache::forget(self::CACHE_KEY . 'tree'); Cache::forget(self::CACHE_KEY . 'all'); } public static function all() { return Cache::rememberForever(self::CACHE_KEY . 'all', function () { return ModelUtil::all('res_category', array(), array('*'), array('sort', 'asc')); }); } public static function getByTitle($yP0KF) { foreach (self::all() as $jIWZA) { if ($jIWZA['title'] == $yP0KF) { return $jIWZA; } } return null; } public static function get($ULYbu) { foreach (self::all() as $jIWZA) { if ($jIWZA['id'] == $ULYbu) { return $jIWZA; } } return null; } public static function childrenByTitle($yP0KF) { $WDJxG = self::getByTitle($yP0KF); return self::children($WDJxG['id']); } public static function children($tKN9l) { goto U6KIf; PZz8f: $ffvpo = array(); goto J6kUq; zn9TE: return $ffvpo; goto roaoL; U6KIf: $jMboY = self::all(); goto PZz8f; J6kUq: foreach ($jMboY as $xeubY) { if ($xeubY['pid'] == $tKN9l) { $ffvpo[] = $xeubY; } } goto zn9TE; roaoL: } public static function chainIds($tKN9l) { goto hU0tY; ed7Wy: $HhtsS = TreeUtil::nodesChain($jMboY, $tKN9l); goto OlUmZ; OlUmZ: return ArrayUtil::flatItemsByKey($HhtsS, 'id'); goto Y6LF9; hU0tY: $jMboY = self::all(); goto ed7Wy; Y6LF9: } public static function childIds($tKN9l) { $jMboY = self::all(); return TreeUtil::nodesChildrenIds($jMboY, $tKN9l); } public static function categoryTree() { return Cache::rememberForever(self::CACHE_KEY . 'tree', function () { return TreeUtil::modelToTree('res_category', array('title' => 'title', 'cover' => 'cover', 'desc' => 'desc', 'showHome' => 'showHome', 'resCount' => 'resCount')); }); } public static function mergeCategories(&$sX2oK, $bVwO9 = 'categoryId', $Sj78R = '_category') { foreach ($sX2oK as $kEhTf => $y2Ltn) { $sX2oK[$kEhTf][$Sj78R] = self::get($y2Ltn[$bVwO9]); } } }