mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-05 00:11:30 +08:00
45 lines
843 B
PHP
45 lines
843 B
PHP
<?php
|
|
|
|
namespace App\Caches;
|
|
|
|
use App\Models\Category as CategoryModel;
|
|
use Phalcon\Mvc\Model\Resultset;
|
|
|
|
class CategoryList extends Cache
|
|
{
|
|
|
|
protected $lifetime = 365 * 86400;
|
|
|
|
public function getLifetime()
|
|
{
|
|
return $this->lifetime;
|
|
}
|
|
|
|
public function getKey($id = null)
|
|
{
|
|
return 'category_list';
|
|
}
|
|
|
|
/**
|
|
* @param null $id
|
|
* @return array
|
|
*/
|
|
public function getContent($id = null)
|
|
{
|
|
/**
|
|
* @var Resultset $categories
|
|
*/
|
|
$categories = CategoryModel::query()
|
|
->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path'])
|
|
->where('published = 1 AND deleted = 0')
|
|
->execute();
|
|
|
|
if ($categories->count() == 0) {
|
|
return [];
|
|
}
|
|
|
|
return $categories->toArray();
|
|
}
|
|
|
|
}
|