70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace plugin\produce\app\dao;
|
|
|
|
use core\base\BaseDao;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use plugin\produce\app\model\StepRelation;
|
|
|
|
class StepRelationDao extends BaseDao
|
|
{
|
|
protected function setModel(): string
|
|
{
|
|
return StepRelation::class;
|
|
}
|
|
|
|
protected function getKeywordFields(): array
|
|
{
|
|
return ['relation_type', 'description'];
|
|
}
|
|
|
|
public function selectList(
|
|
array $where,
|
|
string|array $field = '*',
|
|
int $page = 0,
|
|
int $limit = 0,
|
|
string $order = '',
|
|
array $with = [],
|
|
bool $search = false,
|
|
?array $withoutScopes = null
|
|
): ?Collection {
|
|
$with = array_unique(array_merge($with, ['fromStep', 'toStep']));
|
|
$order = $order ?: 'priority asc, sort asc, id desc';
|
|
|
|
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
|
}
|
|
|
|
public function handleSearch(array $where, bool $isPage = true): Builder
|
|
{
|
|
$query = parent::handleSearch($where, $isPage);
|
|
|
|
if (($where['from_step_id'] ?? '') !== '') {
|
|
$query->where('from_step_id', $where['from_step_id']);
|
|
}
|
|
|
|
if (($where['to_step_id'] ?? '') !== '') {
|
|
$query->where('to_step_id', $where['to_step_id']);
|
|
}
|
|
|
|
if (($where['relation_type'] ?? '') !== '') {
|
|
$query->where('relation_type', $where['relation_type']);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function getPreviousSteps(int|string $currentStepId): array
|
|
{
|
|
return $this->getModel()::query()
|
|
->where('to_step_id', $currentStepId)
|
|
->where('status', 1)
|
|
->orderBy('priority', 'asc')
|
|
->orderBy('sort', 'asc')
|
|
->get(['id', 'from_step_id', 'to_step_id', 'relation_type'])
|
|
->toArray();
|
|
}
|
|
}
|