bp/app/Modules/Tasks/Models/TaskColumnModel.php

90 lines
2.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Modules\Tasks\Models;
use CodeIgniter\Model;
use App\Models\Traits\TenantScopedModel;
class TaskColumnModel extends Model
{
use TenantScopedModel;
protected $table = 'task_columns';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $tenantField = 'organization_id';
protected $allowedFields = [
'board_id',
'name',
'color',
'order_index',
'is_default',
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
/**
* Получить колонки доски
*/
public function getColumnsByBoard(int $boardId): array
{
return $this->where('board_id', $boardId)
->orderBy('order_index', 'ASC')
->findAll();
}
/**
* Получить следующий порядковый номер для колонки
*/
public function getNextOrderIndex(int $boardId): int
{
$max = $this->selectMax('order_index')
->where('board_id', $boardId)
->first();
return ($max['order_index'] ?? 0) + 1;
}
/**
* Создать дефолтные колонки для новой доски
*/
public function createDefaultColumns(int $boardId): bool
{
$defaultColumns = [
[
'board_id' => $boardId,
'name' => 'К выполнению',
'color' => '#6B7280',
'order_index' => 1,
'is_default' => 0,
],
[
'board_id' => $boardId,
'name' => 'В работе',
'color' => '#3B82F6',
'order_index' => 2,
'is_default' => 0,
],
[
'board_id' => $boardId,
'name' => 'На проверке',
'color' => '#F59E0B',
'order_index' => 3,
'is_default' => 0,
],
[
'board_id' => $boardId,
'name' => 'Завершено',
'color' => '#10B981',
'order_index' => 4,
'is_default' => 0,
],
];
return $this->insertBatch($defaultColumns);
}
}