1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Dmitriy Ostashev <[email protected]>
|
4
|
|
|
* @property string $actionUrl
|
5
|
|
|
*/
|
6
|
|
|
class BPagination extends CPagination
|
7
|
|
|
{
|
8
|
|
|
const MAX_PAGE_SIZE = PHP_INT_MAX;
|
9
|
|
|
|
10
|
|
|
/**
|
11
|
|
|
* Массив элементов, используемых для вывода
|
12
|
|
|
* в форме вариантов отображения элементов страниц
|
13
|
|
|
* @var array
|
14
|
|
|
*/
|
15
|
|
|
public $pageSizeList = [10 => 10, 50 => 50, 100 => 100, 500 => 500, 1000 => 1000, 5000 => 5000, self::MAX_PAGE_SIZE => 'Все'];
|
16
|
|
|
|
17
|
|
|
/** @var int Идентефикатор переменной кол-ва элементов на странице */
|
18
|
|
|
public $pageSizeVar;
|
19
|
|
|
|
20
|
|
|
/** @var string Url сабмита формы - выбора кол-ва элементов на странице */
|
21
|
|
|
protected $_actionUrl;
|
22
|
|
|
|
23
|
|
|
protected $_pageSize = self::DEFAULT_PAGE_SIZE;
|
24
|
|
|
|
25
|
|
|
protected $_itemCount = 0;
|
26
|
|
|
|
27
|
7 |
|
public function getPageSize()
|
28
|
|
|
{
|
29
|
7 |
|
if( !empty($_GET[$this->pageSizeVar]) )
|
30
|
7 |
|
$this->_pageSize = $_GET[$this->pageSizeVar];
|
31
|
|
|
|
32
|
7 |
|
return (int)$this->_pageSize === 0 ? self::DEFAULT_PAGE_SIZE : $this->_pageSize;
|
33
|
|
|
}
|
34
|
|
|
|
35
|
|
|
/**
|
36
|
|
|
* @param $val
|
37
|
|
|
*/
|
38
|
|
|
public function setActionUrl($val)
|
39
|
|
|
{
|
40
|
|
|
$this->_actionUrl = $val;
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* @return string
|
45
|
|
|
*/
|
46
|
1 |
|
public function getActionUrl()
|
47
|
|
|
{
|
48
|
1 |
|
if( $this->_actionUrl === null )
|
49
|
1 |
|
{
|
50
|
1 |
|
$route = Yii::app()->controller instanceof CController ? Yii::app()->controller->route : '';
|
|
|
|
|
51
|
1 |
|
$params = $_GET;
|
52
|
1 |
|
unset($params[$this->pageSizeVar], $params['ajax']);
|
53
|
1 |
|
$this->_actionUrl = Yii::app()->createUrl($route, $params);
|
54
|
1 |
|
}
|
55
|
|
|
|
56
|
1 |
|
return $this->_actionUrl;
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
/**
|
60
|
|
|
* @return integer number of pages
|
61
|
|
|
*/
|
62
|
|
|
public function getPageCount()
|
63
|
|
|
{
|
64
|
|
|
return (int)(($this->_itemCount + $this->_pageSize - 1) / $this->_pageSize);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* @param integer $value total number of items.
|
69
|
|
|
*/
|
70
|
10 |
|
public function setItemCount($value)
|
71
|
|
|
{
|
72
|
10 |
|
if( ($this->_itemCount = $value) < 0 )
|
73
|
10 |
|
$this->_itemCount = 0;
|
74
|
10 |
|
}
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* Создание формы для отображения вариантов количества элементов
|
78
|
|
|
* @return string of form
|
79
|
|
|
*/
|
80
|
1 |
|
public function getPageSizeForm()
|
81
|
|
|
{
|
82
|
1 |
|
$formProperties = ['class' => 'page-size'];
|
83
|
|
|
|
84
|
1 |
|
$form = CHtml::beginForm($this->actionUrl, 'get', $formProperties);
|
85
|
1 |
|
$form .= CHtml::tag('span', ['class' => 'page-size-title'], 'Отображать по: ');
|
86
|
1 |
|
$form .= CHtml::dropDownList($this->pageSizeVar, $this->getPageSize(), $this->pageSizeList);
|
87
|
1 |
|
$form .= CHtml::endForm();
|
88
|
|
|
|
89
|
|
|
$formChangeHandler = <<<JS
|
90
|
1 |
|
$('body').on('change', '.{$formProperties['class']} select', function(){
|
91
|
|
|
if ( window.History.enabled ) {
|
92
|
|
|
var url = $(this).parents('form').attr('action').split('?');
|
93
|
|
|
var params = url[1] === undefined ? [] : $.deparam.querystring('?'+url[1]);
|
94
|
|
|
params[$(this).attr('id')] = $(this).val();
|
95
|
|
|
window.History.pushState(null, document.title, decodeURIComponent($.param.querystring(url[0], params)));
|
96
|
|
|
} else {
|
97
|
1 |
|
$(this).parents('.{$formProperties['class']}').submit();
|
98
|
|
|
}
|
99
|
1 |
|
});
|
100
|
1 |
|
JS;
|
101
|
1 |
|
Yii::app()->getClientScript()->registerScript('pageSizeChangeHandler', $formChangeHandler, CClientScript::POS_READY);
|
102
|
|
|
|
103
|
1 |
|
return $form;
|
104
|
|
|
}
|
105
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.