<?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($QpIae) { goto cK0VB; cK0VB: if (empty($QpIae)) { return $QpIae; } goto sjvTx; pmu0S: return $QpIae; goto jeLPM; sjvTx: $QpIae['_url'] = self::url($QpIae); goto pmu0S; jeLPM: } public static function url($QpIae) { if ($QpIae['alias']) { return modstart_web_url('article/' . $QpIae['alias']); } return modstart_web_url('article/' . $QpIae['id']); } public static function get($pNLgg) { $zvlJr = ModelUtil::get('article', $pNLgg); return self::buildRecord($zvlJr); } public static function getByAlias($WT90X) { return self::buildRecord(ModelUtil::get('article', array('alias' => $WT90X))); } public static function listByPosition($MLpgq = 'home') { $qhpxU = ModelUtil::model('article')->where(array('position' => $MLpgq))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($vPOhn) { return self::buildRecord($vPOhn); }, $qhpxU); } public static function listByPositionWithCache($MLpgq = 'home', $jlaFt = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $MLpgq, $jlaFt, function () use($MLpgq) { return self::listByPosition($MLpgq); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $JdFJR => $hx4PQ) { Cache::forget(self::CACHE_KEY_PREFIX . $JdFJR); } } }