<?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($kmRgK) { goto LWx04; gP2YM: return $kmRgK; goto aKVEh; LWx04: if (empty($kmRgK)) { return $kmRgK; } goto ZX518; ZX518: $kmRgK['_url'] = self::url($kmRgK); goto gP2YM; aKVEh: } public static function url($kmRgK) { if ($kmRgK['alias']) { return modstart_web_url('article/' . $kmRgK['alias']); } return modstart_web_url('article/' . $kmRgK['id']); } public static function get($ULYbu) { $Kwhgm = ModelUtil::get('article', $ULYbu); return self::buildRecord($Kwhgm); } public static function getByAlias($Gc2Op) { return self::buildRecord(ModelUtil::get('article', array('alias' => $Gc2Op))); } public static function listByPosition($FcLCS = 'home') { $sX2oK = ModelUtil::model('article')->where(array('position' => $FcLCS))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($jIWZA) { return self::buildRecord($jIWZA); }, $sX2oK); } public static function listByPositionWithCache($FcLCS = 'home', $K9IuV = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $FcLCS, $K9IuV, function () use($FcLCS) { return self::listByPosition($FcLCS); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $kEhTf => $plloB) { Cache::forget(self::CACHE_KEY_PREFIX . $kEhTf); } } }