| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\App\Models; |
| 4 |
|
| 5 |
use FluentBoards\App\Models\Board; |
| 6 |
use FluentBoards\App\Models\BoardTerm; |
| 7 |
use FluentBoards\App\Models\Task; |
| 8 |
use FluentBoards\Framework\Database\Orm\Builder; |
| 9 |
use FluentBoards\App\Services\Constant; |
| 10 |
|
| 11 |
/** Store custom-field data so native imports do not require the Pro addon. */ |
| 12 |
class CustomField extends BoardTerm |
| 13 |
{ |
| 14 |
/** Scope custom fields to their shared board-term type. */ |
| 15 |
public static function boot() |
| 16 |
{ |
| 17 |
parent::boot(); |
| 18 |
static::creating(function ($model) { |
| 19 |
$model->type = $model->type ?: Constant::BOARD_TERM_CUSTOM_FIELD; |
| 20 |
}); |
| 21 |
|
| 22 |
static::addGlobalScope('type', function (Builder $builder) { |
| 23 |
$builder->where('type', '=', Constant::BOARD_TERM_CUSTOM_FIELD); |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
/** Return tasks using this custom field. */ |
| 28 |
public function tasks() |
| 29 |
{ |
| 30 |
return $this->belongsToMany( |
| 31 |
Task::class, |
| 32 |
'fbs_relations', |
| 33 |
'foreign_id', |
| 34 |
'object_id' |
| 35 |
)->withTimestamps() |
| 36 |
->wherePivot('object_type', Constant::TASK_CUSTOM_FIELD) |
| 37 |
->withPivot('settings', 'preferences'); |
| 38 |
} |
| 39 |
|
| 40 |
/** Return the board that owns this field. */ |
| 41 |
public function board() |
| 42 |
{ |
| 43 |
return $this->belongsTo(Board::class, 'board_id', 'id'); |
| 44 |
} |
| 45 |
} |