|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\widgets; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\base\Widget; |
|
7
|
|
|
use yii\base\InvalidParamException; |
|
8
|
|
|
use yii\bootstrap\ButtonDropdown; |
|
9
|
|
|
use yii\helpers\Html; |
|
10
|
|
|
use yii\helpers\Url; |
|
11
|
|
|
|
|
12
|
|
|
class IndexPage extends Widget |
|
13
|
|
|
{ |
|
14
|
|
|
public $model; |
|
15
|
|
|
|
|
16
|
|
|
public $dataProvider; |
|
17
|
|
|
|
|
18
|
|
|
public $contents = []; |
|
19
|
|
|
|
|
20
|
|
|
protected $_current = null; |
|
21
|
|
|
|
|
22
|
|
|
public function beginContent($name, $params = []) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
if ($this->_current) { |
|
25
|
|
|
throw new InvalidParamException('Already started content for ' . $this->_current); |
|
26
|
|
|
} |
|
27
|
|
|
$this->_current = $name; |
|
28
|
|
|
ob_start(); |
|
29
|
|
|
ob_implicit_flush(false); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function endContent() |
|
33
|
|
|
{ |
|
34
|
|
|
if (!$this->_current) { |
|
35
|
|
|
throw new InvalidParamException('Not started content'); |
|
36
|
|
|
} |
|
37
|
|
|
$this->contents[$this->_current] = ob_get_contents(); |
|
38
|
|
|
ob_end_clean(); |
|
39
|
|
|
$this->_current = null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function renderContent($name) |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->contents[$name]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function run() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->render('horizontal' . 'IndexPage'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
public function renderSearchForm(array $data = [], $advancedSearchOptions = []) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
ob_start(); |
|
55
|
|
|
ob_implicit_flush(false); |
|
56
|
|
|
try { |
|
57
|
|
|
$search = $this->beginSearchForm($advancedSearchOptions); |
|
58
|
|
|
foreach (['per_page', 'representation'] as $key) { |
|
59
|
|
|
echo Html::hiddenInput($key, Yii::$app->request->get($key)); |
|
60
|
|
|
} |
|
61
|
|
|
echo Yii::$app->view->render('_search', array_merge(compact('search'), $data)); |
|
62
|
|
|
$search->end(); |
|
63
|
|
|
} catch (\Exception $e) { |
|
64
|
|
|
ob_end_clean(); |
|
65
|
|
|
throw $e; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return ob_get_clean(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function beginSearchForm($options = []) |
|
72
|
|
|
{ |
|
73
|
|
|
return AdvancedSearch::begin(array_merge(['model' => $this->model], $options)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function renderSearchButton() |
|
77
|
|
|
{ |
|
78
|
|
|
return AdvancedSearch::renderButton() . "\n"; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
View Code Duplication |
public function renderPerPage() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
return ButtonDropdown::widget([ |
|
84
|
|
|
'label' => Yii::t('app', 'Per page') . ': ' . (Yii::$app->request->get('per_page') ?: 25), |
|
85
|
|
|
'options' => ['class' => 'btn-default'], |
|
86
|
|
|
'dropdown' => [ |
|
87
|
|
|
'items' => [ |
|
88
|
|
|
['label' => '25', 'url' => Url::current(['per_page' => null])], |
|
89
|
|
|
['label' => '50', 'url' => Url::current(['per_page' => 50])], |
|
90
|
|
|
['label' => '100', 'url' => Url::current(['per_page' => 100])], |
|
91
|
|
|
['label' => '200', 'url' => Url::current(['per_page' => 200])], |
|
92
|
|
|
['label' => '500', 'url' => Url::current(['per_page' => 500])], |
|
93
|
|
|
], |
|
94
|
|
|
], |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
View Code Duplication |
public function renderRepresentation() |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$representation = Yii::$app->request->get('representation') ?: 'common'; |
|
101
|
|
|
|
|
102
|
|
|
return ButtonDropdown::widget([ |
|
103
|
|
|
'label' => Yii::t('synt', 'View') . ': ' . Yii::t('app', $representation), |
|
104
|
|
|
'options' => ['class' => 'btn-default'], |
|
105
|
|
|
'dropdown' => [ |
|
106
|
|
|
'items' => [ |
|
107
|
|
|
['label' => Yii::t('app', 'common'), 'url' => Url::current(['representation' => null])], |
|
108
|
|
|
['label' => Yii::t('app', 'report'), 'url' => Url::current(['representation' => 'report'])], |
|
109
|
|
|
], |
|
110
|
|
|
], |
|
111
|
|
|
]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
View Code Duplication |
public function renderSorter(array $options) |
|
|
|
|
|
|
115
|
|
|
{ |
|
116
|
|
|
return LinkSorter::widget(array_merge([ |
|
117
|
|
|
'show' => true, |
|
118
|
|
|
'sort' => $this->dataProvider->getSort(), |
|
119
|
|
|
], $options)); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.