Completed
Push — master ( c2074a...b8ebce )
by Andrii
04:40
created

IndexPage::renderPerPage()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
ccs 0
cts 16
cp 0
rs 9.4285
cc 2
eloc 11
nc 1
nop 0
crap 6
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 = [])
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
    {
116
        return LinkSorter::widget(array_merge([
117
            'show'  => true,
118
            'sort'  => $this->dataProvider->getSort(),
119
        ], $options));
120
    }
121
122
}
123