|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Table\CrudTraits; |
|
4
|
|
|
|
|
5
|
|
|
trait PreferencesHelperTrait |
|
6
|
|
|
{ |
|
7
|
|
|
private $tableIdentifier; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @param null $ident |
|
11
|
|
|
* @return mixed|void |
|
12
|
|
|
*/ |
|
13
|
17 |
|
public function tableIdentifier($ident = null) |
|
14
|
|
|
{ |
|
15
|
17 |
|
if (is_null($ident)) { |
|
16
|
4 |
|
return $this->tableIdentifier; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
17 |
|
$this->tableIdentifier = $ident; |
|
20
|
17 |
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getCurrentLocale() |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->preferences()->getCurrentLocale($this->tableIdentifier()) ?: key($this->getLocales()); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function saveCurrentLocale($locale) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->preferences()->saveCurrentLocale($this->tableIdentifier(), $locale); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function getPerPageParam() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
1 |
|
return $this->preferences()->getPerPageParam($this->tableIdentifier()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function setPerPageParam($perPage) |
|
38
|
|
|
{ |
|
39
|
1 |
|
$this->preferences()->setPerPageParam($this->tableIdentifier(), $perPage); |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function saveSearchFilterParams(array $params) |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->preferences()->saveSearchFilterParams($this->tableIdentifier(), $params); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function getOrderFilterParam($column) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
1 |
|
return $this->preferences()->getOrderFilterParam($this->tableIdentifier(), $column); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function saveOrderFilterParam($column, $direction) |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->preferences()->saveOrderFilterParam($this->tableIdentifier(), $column, $direction); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function isSortableByWeightActive() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
1 |
|
return $this->preferences()->isSortableByWeightActive($this->tableIdentifier()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setSortableOrderState(bool $active) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->preferences()->setSortableOrderState($this->tableIdentifier(), $active); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
abstract public function preferences(); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.