|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SoliDry\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use SoliDry\Extension\BaseFormRequest; |
|
6
|
|
|
use SoliDry\Types\ModelsInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class SqlOptions |
|
10
|
|
|
* @package SoliDry\Helpers |
|
11
|
|
|
* |
|
12
|
|
|
* @property BaseFormRequest formRequest |
|
13
|
|
|
*/ |
|
14
|
|
|
class SqlOptions |
|
15
|
|
|
{ |
|
16
|
|
|
public $id = 0; |
|
17
|
|
|
public $limit = ModelsInterface::DEFAULT_LIMIT; |
|
18
|
|
|
public $page = ModelsInterface::DEFAULT_PAGE; |
|
19
|
|
|
public $orderBy = []; |
|
20
|
|
|
public $data = ModelsInterface::DEFAULT_DATA; |
|
21
|
|
|
public $filter = []; |
|
22
|
|
|
public $formRequest; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return int |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getLimit() : int |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->limit; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param int $limit |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setLimit($limit) : void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->limit = $limit; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return int |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getPage() : int |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->page; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param int $page |
|
50
|
|
|
*/ |
|
51
|
|
|
public function setPage(int $page) : void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->page = $page; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getOrderBy() : array |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->orderBy; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array $orderBy |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setOrderBy($orderBy) : void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->orderBy = $orderBy; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getData() : array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->data; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param array $data |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setData($data) : void |
|
84
|
|
|
{ |
|
85
|
|
|
// id must be there anyway |
|
86
|
|
|
$this->data = $data; |
|
87
|
|
|
if(\in_array(ModelsInterface::ID, $this->data, true) === false) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->data[] = ModelsInterface::ID; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// this fix cases where oneToMany/oneToOne relationships need binding by entity_id |
|
93
|
|
|
$rules = $this->formRequest->rules(); |
|
94
|
|
|
foreach ($rules as $key => $val) { |
|
95
|
|
|
|
|
96
|
|
|
if (mb_strpos($key, '_id') !== false) { |
|
97
|
|
|
if (\in_array($key, $this->data, true) === false) { |
|
98
|
|
|
$this->data[] = $key; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getFilter() : array |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->filter; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param array $filter |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setFilter($filter) : void |
|
116
|
|
|
{ |
|
117
|
|
|
$this->filter = $filter; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return int|string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getId() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->id; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param int|string $id |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setId($id) : void |
|
132
|
|
|
{ |
|
133
|
|
|
$this->id = $id; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param BaseFormRequest $formRequest |
|
138
|
|
|
*/ |
|
139
|
|
|
public function setFormRequest(BaseFormRequest $formRequest): void |
|
140
|
|
|
{ |
|
141
|
|
|
$this->formRequest = $formRequest; |
|
142
|
|
|
} |
|
143
|
|
|
} |