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\Applications; |
20
|
|
|
use Zend\Db\Sql\Select; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* class Admin\Model\ApplicationsTable |
24
|
|
|
* |
25
|
|
|
* @author bba |
26
|
|
|
* @package ApplicationsTable |
27
|
|
|
*/ |
28
|
|
|
class ApplicationsTable |
29
|
|
|
{ |
30
|
|
|
protected $tableGateway; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* @param TableGateway $tableGateway |
35
|
|
|
*/ |
36
|
|
|
public function __construct(TableGateway $tableGateway) |
37
|
|
|
{ |
38
|
|
|
$this->tableGateway = $tableGateway; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* @param string $scope |
44
|
|
|
* @return \Zend\Db\ResultSet\ResultSet |
45
|
|
|
*/ |
46
|
|
|
public function fetchAll($scope = '') |
47
|
|
|
{ |
48
|
|
|
$resultSet = $this->tableGateway->select( |
49
|
|
|
function (Select $select) use ($scope) { |
50
|
|
|
if (!empty($scope)) { |
51
|
|
|
$select->where('scope = \''.$scope.'\'')->order('type, name ASC'); |
52
|
|
|
} else { |
53
|
|
|
$select->order('name ASC'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
); |
57
|
|
|
return $resultSet; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @param string $scope |
63
|
|
|
* @return \Zend\Db\Adapter\Driver\ResultInterface |
64
|
|
|
*/ |
65
|
|
|
public function fetchAllFull($scope = '') |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$sqlSelect = $this->tableGateway->getSql()->select(); |
68
|
|
|
$sqlSelect->join( |
69
|
|
|
'clients', |
70
|
|
|
'applications.client_id = clients.clients_id', |
71
|
|
|
array( |
72
|
|
|
'clientname' => 'name', |
73
|
|
|
), |
74
|
|
|
Select::JOIN_LEFT |
75
|
|
|
); |
76
|
|
|
$statement = $this->tableGateway->getSql()->prepareStatementForSqlObject($sqlSelect); |
77
|
|
|
$resultSet = $statement->execute(); |
78
|
|
|
|
79
|
|
|
return $resultSet; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getApplication($id) |
83
|
|
|
{ |
84
|
|
|
$id = (int) $id; |
85
|
|
|
$rowset = $this->tableGateway->select(array('application_id' => $id)); |
86
|
|
|
$row = $rowset->current(); |
87
|
|
|
if (!$row) { |
88
|
|
|
throw new \Exception("Could not find row $id"); |
89
|
|
|
} |
90
|
|
|
return $row; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function saveApplication(Applications $applications) |
94
|
|
|
{ |
95
|
|
|
$data = array( |
96
|
|
|
'name' => $applications->name, |
97
|
|
|
'shortname' => $applications->shortname, |
98
|
|
|
'path' => $applications->path, |
99
|
|
|
'url' => $applications->url, |
100
|
|
|
'email' => $applications->email, |
101
|
|
|
'client_id' => $applications->client_id, |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$id = (int)$applications->application_id; |
105
|
|
|
if ($id == 0) { |
106
|
|
|
$this->tableGateway->insert($data); |
107
|
|
|
} else { |
108
|
|
|
if ($this->getApplications($id)) { |
|
|
|
|
109
|
|
|
$this->tableGateway->update($data, array('application_id' => $id)); |
110
|
|
|
} else { |
111
|
|
|
throw new \Exception('Form id does not exist'); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function deleteApplication($id) |
117
|
|
|
{ |
118
|
|
|
$this->tableGateway->delete(array('application_id' => $id)); |
119
|
|
|
} |
120
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.