|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jidaikobo\Kontiki\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
|
6
|
|
|
use Illuminate\Database\Query\Builder; |
|
7
|
|
|
|
|
8
|
|
|
class CategoryModel extends BaseModel |
|
9
|
|
|
{ |
|
10
|
|
|
use Traits\CRUDTrait; |
|
11
|
|
|
use Traits\MetaDataTrait; |
|
|
|
|
|
|
12
|
|
|
use Traits\IndexTrait; |
|
13
|
|
|
|
|
14
|
|
|
protected string $table = 'terms'; |
|
15
|
|
|
|
|
16
|
|
|
protected function defineFieldDefinitions(array $params = []): void |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$id = 1; |
|
19
|
|
|
$fields = [ |
|
|
|
|
|
|
20
|
|
|
'id' => $this->getIdField(), |
|
21
|
|
|
'name' => $this->getNameField(), |
|
22
|
|
|
'slug' => $this->getSlugField($id), |
|
23
|
|
|
'parent_id' => $this->getParentIdField($id), |
|
24
|
|
|
'term_order' => $this->getTermOrederField(), |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
// $MetaData = $this->getMetaDataFieldDefinitions($params); |
|
28
|
|
|
// $this->fieldDefinitions = array_merge($fields, $MetaData); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private function getNameField(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->getField( |
|
34
|
|
|
__('name'), |
|
35
|
|
|
[ |
|
36
|
|
|
'rules' => ['required'], |
|
37
|
|
|
'display_in_list' => true |
|
38
|
|
|
] |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function getSlugField(?int $id): array |
|
43
|
|
|
{ |
|
44
|
|
|
$slug_exp = __('slug_exp', 'The "slug" is used as the URL. It can contain alphanumeric characters and hyphens.'); |
|
45
|
|
|
|
|
46
|
|
|
return $this->getField( |
|
47
|
|
|
__('slug'), |
|
48
|
|
|
[ |
|
49
|
|
|
'description' => $slug_exp, |
|
50
|
|
|
'rules' => [ |
|
51
|
|
|
'required', |
|
52
|
|
|
'slug', |
|
53
|
|
|
['lengthMin', 3], |
|
54
|
|
|
['unique', $this->table, 'slug', $id] |
|
55
|
|
|
], |
|
56
|
|
|
] |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function getParentIdField($id): array |
|
61
|
|
|
{ |
|
62
|
|
|
$type = false ? 'hidden' : 'select'; |
|
63
|
|
|
return $this->getField( |
|
64
|
|
|
__('parent'), |
|
65
|
|
|
[ |
|
66
|
|
|
'type' => $type, |
|
67
|
|
|
'options' => [], |
|
68
|
|
|
'default' => '', |
|
69
|
|
|
'rules' => [ |
|
70
|
|
|
'required', |
|
71
|
|
|
'slug', |
|
72
|
|
|
['lengthMin', 3], |
|
73
|
|
|
['unique', $this->table, 'slug', $id] |
|
74
|
|
|
], |
|
75
|
|
|
] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private function getTermOrederField(): array |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getField( |
|
82
|
|
|
__('order'), |
|
83
|
|
|
[ |
|
84
|
|
|
'display_in_list' => true |
|
85
|
|
|
] |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|