<?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($glXLo) { goto xpFma; grj3r: return $glXLo; goto TIPx1; xpFma: if (empty($glXLo)) { return $glXLo; } goto Eh99t; Eh99t: $glXLo['_url'] = self::url($glXLo); goto grj3r; TIPx1: } public static function url($glXLo) { if ($glXLo['alias']) { return modstart_web_url('article/' . $glXLo['alias']); } return modstart_web_url('article/' . $glXLo['id']); } public static function get($StE5h) { $a_yFh = ModelUtil::get('article', $StE5h); return self::buildRecord($a_yFh); } public static function getByAlias($YqLGG) { return self::buildRecord(ModelUtil::get('article', array('alias' => $YqLGG))); } public static function listByPosition($A0M_7 = 'home') { $Y9WQp = ModelUtil::model('article')->where(array('position' => $A0M_7))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($FSL7c) { return self::buildRecord($FSL7c); }, $Y9WQp); } public static function listByPositionWithCache($A0M_7 = 'home', $W7jBq = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $A0M_7, $W7jBq, function () use($A0M_7) { return self::listByPosition($A0M_7); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $D5qRP => $FtPNG) { Cache::forget(self::CACHE_KEY_PREFIX . $D5qRP); } } }