1
|
|
|
<?php namespace NukaCode\Users\Repositories\User; |
2
|
|
|
|
3
|
|
|
use NukaCode\Users\Models\User\Preference; |
4
|
|
|
use NukaCode\Core\Repositories\BaseRepository; |
5
|
|
|
use NukaCode\Core\Ajax\Ajax; |
6
|
|
|
|
7
|
|
|
class PreferenceRepository extends BaseRepository { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var \NukaCode\Core\Models\User\Preference |
11
|
|
|
*/ |
12
|
|
|
protected $preference; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Ajax |
16
|
|
|
*/ |
17
|
|
|
protected $ajax; |
18
|
|
|
|
19
|
|
|
public function __construct(Preference $preference, Ajax $ajax) |
20
|
|
|
{ |
21
|
|
|
$this->model = $preference; |
22
|
|
|
$this->ajax = $ajax; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function set($preference) |
26
|
|
|
{ |
27
|
|
|
if ($preference instanceof Preference) { |
28
|
|
|
$this->entity = $preference; |
29
|
|
|
} else { |
30
|
|
|
throw new \InvalidArgumentException('Invalid preference passed.'); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function create($input) |
35
|
|
|
{ |
36
|
|
|
$preference = new Preference(); |
37
|
|
|
$preference->name = $input['name']; |
38
|
|
|
$preference->keyName = $input['keyName']; |
39
|
|
|
$preference->description = $input['description']; |
40
|
|
|
$preference->value = $input['value']; |
41
|
|
|
$preference->default = $input['default']; |
42
|
|
|
$preference->display = $input['display']; |
43
|
|
|
$preference->hiddenFlag = $input['hiddenFlag']; |
44
|
|
|
|
45
|
|
|
$this->entity = $preference; |
46
|
|
|
|
47
|
|
|
$result = $this->save(); |
48
|
|
|
|
49
|
|
|
return $result; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $input |
54
|
|
|
*/ |
55
|
|
|
public function update($input) |
56
|
|
|
{ |
57
|
|
|
$this->checkEntity(); |
58
|
|
|
$this->requireSingle(); |
59
|
|
|
|
60
|
|
|
$input = e_array($input); |
61
|
|
|
|
62
|
|
|
if ($input != null) { |
63
|
|
|
$this->entity->name = $this->arrayOrEntity('name', $input); |
64
|
|
|
$this->entity->keyName = $this->arrayOrEntity('keyName', $input); |
65
|
|
|
$this->entity->description = $this->arrayOrEntity('description', $input); |
66
|
|
|
$this->entity->value = $this->arrayOrEntity('value', $input); |
67
|
|
|
$this->entity->default = $this->arrayOrEntity('default', $input); |
68
|
|
|
$this->entity->display = $this->arrayOrEntity('display', $input); |
69
|
|
|
$this->entity->hiddenFlag = $this->arrayOrEntity('hiddenFlag', $input); |
70
|
|
|
|
71
|
|
|
$this->save(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |