mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-23 20:00:27 +08:00
96 lines
2.4 KiB
PHP
96 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
* @license https://opensource.org/licenses/GPL-2.0
|
|
* @link https://www.koogua.com
|
|
*/
|
|
|
|
namespace App\Repos;
|
|
|
|
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
|
use App\Models\Task as TaskModel;
|
|
use Phalcon\Mvc\Model;
|
|
use Phalcon\Mvc\Model\Resultset;
|
|
use Phalcon\Mvc\Model\ResultsetInterface;
|
|
|
|
class Task extends Repository
|
|
{
|
|
|
|
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
|
|
{
|
|
$builder = $this->modelsManager->createBuilder();
|
|
|
|
$builder->from(TaskModel::class);
|
|
|
|
$builder->where('1 = 1');
|
|
|
|
if (!empty($where['id'])) {
|
|
$builder->andWhere('id = :id:', ['id' => $where['id']]);
|
|
}
|
|
|
|
if (!empty($where['item_id'])) {
|
|
$builder->andWhere('item_id = :item_id:', ['item_id' => $where['item_id']]);
|
|
}
|
|
|
|
if (!empty($where['item_type'])) {
|
|
$builder->andWhere('item_type = :item_type:', ['item_type' => $where['item_type']]);
|
|
}
|
|
|
|
if (!empty($where['status'])) {
|
|
$builder->andWhere('status = :status:', ['status' => $where['status']]);
|
|
}
|
|
|
|
if (isset($where['locked'])) {
|
|
$builder->andWhere('locked = :locked:', ['locked' => $where['locked']]);
|
|
}
|
|
|
|
switch ($sort) {
|
|
case 'oldest':
|
|
$orderBy = 'id ASC';
|
|
break;
|
|
case 'latest':
|
|
$orderBy = 'id DESC';
|
|
break;
|
|
default:
|
|
$orderBy = 'priority ASC, id ASC';
|
|
break;
|
|
}
|
|
|
|
$builder->orderBy($orderBy);
|
|
|
|
$pager = new PagerQueryBuilder([
|
|
'builder' => $builder,
|
|
'page' => $page,
|
|
'limit' => $limit,
|
|
]);
|
|
|
|
return $pager->paginate();
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return TaskModel|Model|bool
|
|
*/
|
|
public function findById($id)
|
|
{
|
|
return TaskModel::findFirst([
|
|
'conditions' => 'id = :id:',
|
|
'bind' => ['id' => $id],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array $ids
|
|
* @param array|string $columns
|
|
* @return ResultsetInterface|Resultset|TaskModel[]
|
|
*/
|
|
public function findByIds($ids, $columns = '*')
|
|
{
|
|
return TaskModel::query()
|
|
->columns($columns)
|
|
->inWhere('id', $ids)
|
|
->execute();
|
|
}
|
|
|
|
}
|