|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Table; |
|
4
|
|
|
|
|
5
|
|
|
use Yaro\Jarboe\Table\Actions\ActionsContainer; |
|
6
|
|
|
use Yaro\Jarboe\Table\CrudTraits\BatchCheckboxesTrait; |
|
7
|
|
|
use Yaro\Jarboe\Table\CrudTraits\ColumnsAndFieldsTrait; |
|
8
|
|
|
use Yaro\Jarboe\Table\CrudTraits\FormClassTrait; |
|
9
|
|
|
use Yaro\Jarboe\Table\CrudTraits\LocalesTrait; |
|
10
|
|
|
use Yaro\Jarboe\Table\CrudTraits\PaginateTrait; |
|
11
|
|
|
use Yaro\Jarboe\Table\CrudTraits\PreferencesHelperTrait; |
|
12
|
|
|
use Yaro\Jarboe\Table\CrudTraits\SoftDeleteTrait; |
|
13
|
|
|
use Yaro\Jarboe\Table\CrudTraits\SortableWeightTrait; |
|
14
|
|
|
use Yaro\Jarboe\Table\CrudTraits\TabsTrait; |
|
15
|
|
|
use Yaro\Jarboe\Table\CrudTraits\ToolbarTrait; |
|
16
|
|
|
use Yaro\Jarboe\Table\CrudTraits\UrlTrait; |
|
17
|
|
|
use Yaro\Jarboe\Table\Repositories\ModelRepository; |
|
18
|
|
|
use Yaro\Jarboe\Table\Repositories\ModelRepositoryInterface; |
|
19
|
|
|
use Yaro\Jarboe\Table\Repositories\PreferencesRepository; |
|
20
|
|
|
|
|
21
|
|
|
class CRUD |
|
22
|
|
|
{ |
|
23
|
|
|
use BatchCheckboxesTrait; |
|
24
|
|
|
use ColumnsAndFieldsTrait; |
|
25
|
|
|
use FormClassTrait; |
|
26
|
|
|
use LocalesTrait; |
|
27
|
|
|
use PaginateTrait; |
|
28
|
|
|
use PreferencesHelperTrait; |
|
29
|
|
|
use SoftDeleteTrait; |
|
30
|
|
|
use SortableWeightTrait; |
|
31
|
|
|
use TabsTrait; |
|
32
|
|
|
use ToolbarTrait; |
|
33
|
|
|
use UrlTrait; |
|
34
|
|
|
|
|
35
|
|
|
const BASE_URL_DELIMITER = '/~/'; |
|
36
|
|
|
|
|
37
|
|
|
private $model = ''; |
|
38
|
|
|
private $repo; |
|
39
|
|
|
private $preferences; |
|
40
|
|
|
private $actions; |
|
41
|
|
|
|
|
42
|
18 |
|
public function __construct(ModelRepository $repo, PreferencesRepository $preferences, ActionsContainer $actions) |
|
43
|
|
|
{ |
|
44
|
18 |
|
$this->repo = $repo; |
|
45
|
18 |
|
$this->preferences = $preferences; |
|
46
|
18 |
|
$this->actions = $actions; |
|
47
|
18 |
|
} |
|
48
|
|
|
|
|
49
|
13 |
|
public function setModel($model) |
|
50
|
|
|
{ |
|
51
|
13 |
|
$this->model = $model; |
|
52
|
|
|
|
|
53
|
13 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
13 |
|
public function repo(): ModelRepositoryInterface |
|
57
|
|
|
{ |
|
58
|
13 |
|
$this->repo->setCrud($this); |
|
59
|
|
|
|
|
60
|
13 |
|
return $this->repo; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
public function preferences() |
|
64
|
|
|
{ |
|
65
|
4 |
|
return $this->preferences; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function order(string $column, string $direction) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->repo()->order($column, $direction); |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
13 |
|
public function filter(\Closure $callback) |
|
76
|
|
|
{ |
|
77
|
13 |
|
$this->repo()->filter($callback); |
|
78
|
|
|
|
|
79
|
13 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
13 |
|
public function getModel() |
|
83
|
|
|
{ |
|
84
|
13 |
|
return $this->model; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
17 |
|
public function actions() |
|
88
|
|
|
{ |
|
89
|
17 |
|
return $this->actions; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|