<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Article\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use Module\Article\Type\ArticlePosition; class ArticleUtil { const CACHE_KEY_PREFIX = 'article:'; public static function buildRecord($nnVRs) { goto A_7wT; rQw9X: return $nnVRs; goto kzhMI; A_7wT: if (empty($nnVRs)) { return $nnVRs; } goto UZdDX; UZdDX: $nnVRs['_url'] = self::url($nnVRs); goto rQw9X; kzhMI: } public static function url($nnVRs) { if ($nnVRs['alias']) { return modstart_web_url('article/' . $nnVRs['alias']); } return modstart_web_url('article/' . $nnVRs['id']); } public static function get($gZ39D) { $QjHVP = ModelUtil::get('article', $gZ39D); return self::buildRecord($QjHVP); } public static function getByAlias($qQoKh) { return self::buildRecord(ModelUtil::get('article', array('alias' => $qQoKh))); } public static function listByPosition($zeOUe = 'home') { $MCyeh = ModelUtil::model('article')->where(array('position' => $zeOUe))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($YaV4m) { return self::buildRecord($YaV4m); }, $MCyeh); } public static function listByPositionWithCache($zeOUe = 'home', $Vr9BY = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $zeOUe, $Vr9BY, function () use($zeOUe) { return self::listByPosition($zeOUe); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $KAKiA => $NMB1l) { Cache::forget(self::CACHE_KEY_PREFIX . $KAKiA); } } }