|
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
|
|
|
|
|
10
|
|
|
namespace Application\Table; |
|
11
|
|
|
|
|
12
|
|
|
use ZfTable\AbstractTable; |
|
13
|
|
|
|
|
14
|
|
|
class ImportListTable extends AbstractTable |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
protected $config = array( |
|
18
|
|
|
'name' => 'Lista importów', |
|
19
|
|
|
'showPagination' => true, |
|
20
|
|
|
'showQuickSearch' => true, |
|
21
|
|
|
'showItemPerPage' => true, |
|
22
|
|
|
'itemCountPerPage' => 20, |
|
23
|
|
|
'areFilters' => true, |
|
24
|
|
|
'rowAction' => 'updateRow' |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array Definition of headers |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $headers = array( |
|
31
|
|
|
'category_title' => array('title' => 'Marka', 'filters' => 'text' , 'sortable' => true , 'separatable' => true), |
|
32
|
|
|
'created_at' => array('title' => 'Data importu', 'filters' => 'text', 'editable' => true ), |
|
33
|
|
|
'goto-not-voted' => array('title' => 'Nie ocenione', 'sortable' => false), |
|
34
|
|
|
'goto-all' => array('title' => 'Wszystkie', 'sortable' => false), |
|
35
|
|
|
'report' => array('title' => 'Report', 'sortable' => false) |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
protected function init() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->getRow()->addDecorator('separator', array('defaultColumn' => 'category_title')); |
|
41
|
|
|
$this->getRow()->addDecorator('varattr', array('name' => 'data-row' , 'value' => '%s' , 'vars' => array('id'))); |
|
42
|
|
|
|
|
43
|
|
|
$this->getHeader('category_title')->getCell()->addDecorator('editable', array()); |
|
44
|
|
|
|
|
45
|
|
|
$this->getHeader('goto-all')->getCell()->addDecorator('template', array( |
|
46
|
|
|
'template' => '<a href="/application/index/index/%s/1" target="_blank">Click (%s)</a>', |
|
47
|
|
|
'vars' => array('id', 'count-all') |
|
48
|
|
|
)); |
|
49
|
|
|
|
|
50
|
|
|
$this->getHeader('goto-not-voted')->getCell()->addDecorator('template', array( |
|
51
|
|
|
'template' => '<a href="/application/index/index/%s/2" target="_blank">Click (%s)</a>', |
|
52
|
|
|
'vars' => array('id' , 'count-not-voted') |
|
53
|
|
|
)); |
|
54
|
|
|
|
|
55
|
|
|
$this->getHeader('report')->getCell()->addDecorator('template', array( |
|
56
|
|
|
'template' => '<a href="/application/index/report/%s" target="_blank">Generate </a>', |
|
57
|
|
|
'vars' => array('id') |
|
58
|
|
|
)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function initFilters($query) |
|
62
|
|
|
{ |
|
63
|
|
|
if ($value = $this->getParamAdapter()->getValueOfFilter('zff_category_title')) { |
|
|
|
|
|
|
64
|
|
|
$query->where("c.title like '%".$value."%' "); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ($value = $this->getParamAdapter()->getValueOfFilter('zff_created_at')) { |
|
|
|
|
|
|
68
|
|
|
$query->where("i.created_at like '%".$value."%' "); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: