1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BB's Zend Framework 2 Components |
4
|
|
|
* |
5
|
|
|
* AdminModule |
6
|
|
|
* |
7
|
|
|
* @package [MyApplication] |
8
|
|
|
* @package BB's Zend Framework 2 Components |
9
|
|
|
* @package AdminModule |
10
|
|
|
* @author Björn Bartels <[email protected]> |
11
|
|
|
* @link https://gitlab.bjoernbartels.earth/groups/zf2 |
12
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
13
|
|
|
* @copyright copyright (c) 2016 Björn Bartels <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Admin\Model; |
17
|
|
|
|
18
|
|
|
use Zend\Db\TableGateway\TableGateway; |
19
|
|
|
use Admin\Model\Clients; |
20
|
|
|
use Zend\Db\Sql\Select; |
21
|
|
|
|
22
|
|
|
class ClientsTable |
23
|
|
|
{ |
24
|
|
|
protected $tableGateway; |
25
|
|
|
|
26
|
|
|
public function __construct(TableGateway $tableGateway) |
27
|
|
|
{ |
28
|
|
|
$this->tableGateway = $tableGateway; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function fetchAll($scope = '') |
32
|
|
|
{ |
33
|
|
|
$resultSet = $this->tableGateway->select( |
34
|
|
|
function (Select $select) use ($scope) { |
35
|
|
|
if (!empty($scope)) { |
36
|
|
|
$select->where('scope = \''.$scope.'\'')->order('type, name ASC'); |
37
|
|
|
} else { |
38
|
|
|
$select->order('name ASC'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
); |
42
|
|
|
return $resultSet; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function fetchApplication() |
46
|
|
|
{ |
47
|
|
|
return $this->fetchAll('application'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function fetchUser( $id ) |
51
|
|
|
{ |
52
|
|
|
if (!$id) { return array(); |
53
|
|
|
} |
54
|
|
|
$resultSet = $this->tableGateway->select( |
55
|
|
|
function (Select $select) use ($id) { |
56
|
|
|
if (!empty($id)) { |
57
|
|
|
$select->where(array( '(scope = \'user\') AND (ref_id = \''.((int)$id).'\')' ))->order('type, name ASC'); |
58
|
|
|
} else { |
59
|
|
|
$select->order('type, name ASC'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
); |
63
|
|
|
return $resultSet; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getClients($id) |
67
|
|
|
{ |
68
|
|
|
$id = (int) $id; |
69
|
|
|
$rowset = $this->tableGateway->select(array('clients_id' => $id)); |
70
|
|
|
$row = $rowset->current(); |
71
|
|
|
if (!$row) { |
72
|
|
|
throw new \Exception("Could not find row $id"); |
73
|
|
|
} |
74
|
|
|
return $row; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function saveClients(Clients $clients) |
78
|
|
|
{ |
79
|
|
|
$data = array( |
80
|
|
|
'name' => $clients->name, |
81
|
|
|
'extraname' => $clients->extraname, |
82
|
|
|
'homepage' => $clients->homepage, |
83
|
|
|
'email' => $clients->email, |
84
|
|
|
'contact' => $clients->contact, |
85
|
|
|
'phone' => $clients->phone, |
86
|
|
|
'statistics' => $clients->statistics, |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$id = (int)$clients->clients_id; |
90
|
|
|
if ($id == 0) { |
91
|
|
|
$this->tableGateway->insert($data); |
92
|
|
|
} else { |
93
|
|
|
if ($this->getClients($id)) { |
94
|
|
|
$this->tableGateway->update($data, array('clients_id' => $id)); |
95
|
|
|
} else { |
96
|
|
|
throw new \Exception('Form id does not exist'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function deleteClients($id) |
102
|
|
|
{ |
103
|
|
|
$this->tableGateway->delete(array('clients_id' => $id)); |
104
|
|
|
} |
105
|
|
|
} |