|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ZfTable ( Module for Zend Framework 2) |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2013 Piotr Duda [email protected] |
|
6
|
|
|
* @license MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace ZfTable\Source; |
|
10
|
|
|
|
|
11
|
|
|
use ZfTable\Source\AbstractSource; |
|
12
|
|
|
use Zend\Paginator\Paginator; |
|
13
|
|
|
use Zend\Paginator\Adapter\DbSelect; |
|
14
|
|
|
|
|
15
|
|
|
class SqlSelect extends AbstractSource |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
* @var \Zend\Db\Sql\Select |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $quickSearchQuery; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
* @var \Zend\Db\Sql\Select |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $select; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @var \Zend\Paginator\Paginator |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $paginator; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* |
|
38
|
|
|
* @param \Zend\Db\Sql\Select $select |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct($select) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->select = $select; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @return \Zend\Db\Sql\Select |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getSelect() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->select; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Zend\Db\Sql\Select |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getSource() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->select; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Return data as PDO statement |
|
65
|
|
|
* |
|
66
|
|
|
* not-used |
|
67
|
|
|
* @return type |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getDataAsPdoStatement() |
|
70
|
|
|
{ |
|
71
|
|
|
$statement = $this->getSql()->prepareStatementForSqlObject($this->select); |
|
|
|
|
|
|
72
|
|
|
return $statement->execute(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* |
|
77
|
|
|
* @return \Zend\Paginator\Paginator |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getPaginator() |
|
80
|
|
|
{ |
|
81
|
|
|
if (!$this->paginator) { |
|
82
|
|
|
$adapter = new DbSelect($this->getSelect(), $this->getTable()->getAdapter()); |
|
83
|
|
|
$this->paginator = new Paginator($adapter); |
|
84
|
|
|
|
|
85
|
|
|
$this->order(); |
|
86
|
|
|
|
|
87
|
|
|
$this->initPaginator(); |
|
88
|
|
|
} |
|
89
|
|
|
return $this->paginator; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Setting ordering |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function order() |
|
96
|
|
|
{ |
|
97
|
|
|
$column = $this->getParamAdapter()->getColumn(); |
|
98
|
|
|
$order = $this->getParamAdapter()->getOrder(); |
|
99
|
|
|
if ($column) { |
|
100
|
|
|
$this->select->reset('order'); |
|
101
|
|
|
$this->select->order($column . ' ' . $order); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/* |
|
106
|
|
|
* Init quick search |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function quickSearch() |
|
109
|
|
|
{ |
|
110
|
|
|
if ($this->getQuickSearchQuery()) { |
|
|
|
|
|
|
111
|
|
|
$where = $this->getQuickSearchQuery()->getRawState('where'); |
|
|
|
|
|
|
112
|
|
|
$this->select->where($where); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.