<?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($I10ja) { goto oJRsk; Th5u4: return $I10ja; goto Tj9QA; aTWsQ: $I10ja['_url'] = self::url($I10ja); goto Th5u4; oJRsk: if (empty($I10ja)) { return $I10ja; } goto aTWsQ; Tj9QA: } public static function url($I10ja) { if ($I10ja['alias']) { return modstart_web_url('article/' . $I10ja['alias']); } return modstart_web_url('article/' . $I10ja['id']); } public static function get($DcXJr) { $g0b4V = ModelUtil::get('article', $DcXJr); return self::buildRecord($g0b4V); } public static function getByAlias($CCxku) { return self::buildRecord(ModelUtil::get('article', array('alias' => $CCxku))); } public static function listByPosition($v1C6R = 'home') { $Ge6HJ = ModelUtil::model('article')->where(array('position' => $v1C6R))->orderBy('sort', 'asc')->get()->toArray(); return array_map(function ($zEBpl) { return self::buildRecord($zEBpl); }, $Ge6HJ); } public static function listByPositionWithCache($v1C6R = 'home', $COWz6 = 600) { return Cache::remember(self::CACHE_KEY_PREFIX . $v1C6R, $COWz6, function () use($v1C6R) { return self::listByPosition($v1C6R); }); } public static function clearCache() { foreach (ArticlePosition::getList() as $d2HEV => $K0KRy) { Cache::forget(self::CACHE_KEY_PREFIX . $d2HEV); } } }