<?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($IDJi3) { goto do2JR; do2JR: if (empty($IDJi3)) { return $IDJi3; } goto b9gi7; DnIqR: return $IDJi3; goto KoAof; b9gi7: $IDJi3['_url'] = self::url($IDJi3); goto DnIqR; KoAof: } public static function url($IDJi3) { if ($IDJi3['alias']) { return modstart_web_url('article/' . $IDJi3['alias']); } return modstart_web_url('article/' . $IDJi3['id']); } public static function get($MkmbZ) { $mF3b2 = ModelUtil::get('article', $MkmbZ); return self::buildRecord($mF3b2); } public static function getByAlias($nj3p1) { return self::buildRecord(ModelUtil::get('article', array('alias' => $nj3p1))); } public static function listByPosition($yNvL_ = 'home') { $ZzHwD = ModelUtil::model('article')->where(array('position' => $yNvL_))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($kHxHl) { return self::buildRecord($kHxHl); }, $ZzHwD); } public static function listByPositionWithCache($yNvL_ = 'home', $nrH5w = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $yNvL_, $nrH5w, function () use($yNvL_) { return self::listByPosition($yNvL_); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $ynzcc => $zabGJ) { Cache::forget(self::CACHE_KEY_PREFIX . $ynzcc); } } }