<?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($m2hNL) { goto IwHuk; dmyWU: return $m2hNL; goto rOj3Z; iQXvL: $m2hNL['_url'] = self::url($m2hNL); goto dmyWU; IwHuk: if (empty($m2hNL)) { return $m2hNL; } goto iQXvL; rOj3Z: } public static function url($m2hNL) { if ($m2hNL['alias']) { return modstart_web_url('article/' . $m2hNL['alias']); } return modstart_web_url('article/' . $m2hNL['id']); } public static function get($M3rBS) { $nnCtx = ModelUtil::get('article', $M3rBS); return self::buildRecord($nnCtx); } public static function getByAlias($Ue3nn) { return self::buildRecord(ModelUtil::get('article', array('alias' => $Ue3nn))); } public static function listByPosition($z8wh0 = 'home') { $XsrNI = ModelUtil::model('article')->where(array('position' => $z8wh0))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($Z32UA) { return self::buildRecord($Z32UA); }, $XsrNI); } public static function listByPositionWithCache($z8wh0 = 'home', $seQTq = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $z8wh0, $seQTq, function () use($z8wh0) { return self::listByPosition($z8wh0); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $MFVkb => $FViDa) { Cache::forget(self::CACHE_KEY_PREFIX . $MFVkb); } } }