This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
FilesetTable.php
127 lines (107 loc) · 3.8 KB
/
FilesetTable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Fileset\Model;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Bareos\Db\Sql\BareosSqlCompatHelper;
class FilesetTable implements ServiceLocatorAwareInterface
{
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function getDbDriverConfig() {
$config = $this->getServiceLocator()->get('Config');
return $config['db']['driver'];
}
public function fetchAll($paginated=false)
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("FileSet"));
if($paginated) {
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Fileset());
$paginatorAdapter = new DbSelect(
$select,
$this->tableGateway->getAdapter(),
$resultSetPrototype
);
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
$resultSet = $this->tableGateway->select();
return $resultSet;
}
public function getFileset($id)
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$id = (int) $id;
$rowset = $this->tableGateway->select(array(
$bsqlch->strdbcompat("FileSetId") => $id));
$row = $rowset->current();
if(!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}
public function getFilesetHistory($id)
{
$fset = $this->getFileSet($id);
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("FileSet"));
$select->where($bsqlch->strdbcompat("FileSet") . " = '". $fset->fileset . "'");
$select->order($bsqlch->strdbcompat("CreateTime") . " DESC");
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
public function getFilesetNum()
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("FileSet"));
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Fileset());
$rowset = new DbSelect(
$select,
$this->tableGateway->getAdapter(),
$resultSetPrototype
);
$num = $rowset->count();
return $num;
}
}