You need to sign in or sign up before continuing.
Newer
Older
<?php
/**
* This file contains \QUI\Bricks\Controls\Pagination
*/
namespace QUI\Bricks\Controls;
use QUI;
/**
* Pagination
*
* @author www.pcsg.de (Henning Leutz)
* @licence For copyright and license information, please view the /README.md
*/
class Pagination extends QUI\Control
{
/**
* GET Params
*
* @var array
*/
*/
public function __construct($attributes = array())
{
$this->setAttributes(array(
'showLimit' => false,
'limits' => '[10,20,50]',
'limit' => 10,
'order' => false,
'sheet' => 1,
'useAjax' => false,
'showmax' => 10,
'anchor' => false
));
parent::__construct($attributes);
$this->addCSSFile(
dirname(__FILE__) . '/Pagination.css'
if ($this->getAttribute('useAjax')) {
$this->setAttribute(
'data-qui',
'package/quiqqer/bricks/bin/Controls/Pagination'
);
} else {
$this->setAttribute('data-qui', false);
}
$this->setAttribute('class', 'quiqqer-pagination grid-100 grid-parent');
}
/**
* (non-PHPdoc)
*
* @see \QUI\Control::create()
*/
public function getBody()
{
$Engine = QUI::getTemplateManager()->getEngine();
$Site = $this->getAttribute('Site');
$Project = $Site->getProject();
$count = $this->getAttribute('sheets');

Patrick Müller
committed
if ($count === false) {
if ($this->getAttribute('limit') &&
$this->getAttribute('count')
) {

Patrick Müller
committed
$count = ceil(
(int)$this->getAttribute('count') /
(int)$this->getAttribute('limit')
);
$this->setAttribute('sheets', $count);
}
}
$limits = $this->getAttribute('limits');
if ($this->getAttribute('useAjax')) {
$this->setAttribute(
'data-qui',
'package/quiqqer/bricks/bin/Controls/Pagination'
);
} else {
$this->setAttribute('data-qui', false);
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
}
if ($limits && is_string($limits)) {
$limits = json_decode($limits, true);
if (!is_array($limits)) {
$limits = false;
}
}
$active = $this->getAttribute('sheet');
$anchor = '';
if ($this->getAttribute('anchor')) {
$anchor = $this->getAttribute('anchor');
}
if ($showmax >= $count) {
$showmax = false;
}
if (!$showmax) {
$showmax = $count * 2;
}
$gap = floor($showmax / 2);
$start = $active - $gap;
$end = $active + $gap;
$end--; // -1, weil aktuelle seite nicht mit berechnet werden soll
}
// get params
$limit = $this->getAttribute('limit');
$order = $this->getAttribute('order');
$sheet = $this->getAttribute('sheet');
$this->getParams['sheet'] = $sheet;
$this->getParams['limit'] = $limit;

Henning Leutz
committed
if (!empty($order)) {

Henning Leutz
committed
}

Patrick Müller
committed
if ((!$count || $count == 1)
&& $this->getAttribute('limit') === false
) {
return '';
}
$Engine->assign(array(
'this' => $this,
'count' => $count,
'start' => $start,
'end' => $end,
'active' => $active,
'pathParams' => $this->urlParams,
'getParams' => $this->getParams,
'anchor' => $anchor,
'limit' => $limit,
'limits' => $limits,
'Site' => $Site,
'Project' => $Project
));
return $Engine->fetch(dirname(__FILE__) . '/Pagination.html');
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
}
/**
* Load the GET request variables into the sheet
*/
public function loadFromRequest()
{
$limit = $this->getAttribute('limit');
$order = $this->getAttribute('order');
$sheet = $this->getAttribute('sheet');
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$limit = (int)$_GET['limit'];
}
if (isset($_GET['order'])) {
$order = $_GET['order'];
}
if (isset($_GET['sheet'])) {
$sheet = $_GET['sheet'];
}
$this->setAttribute('limit', $limit);
$this->setAttribute('order', $order);
$this->setAttribute('sheet', $sheet);
}
/**
* Return SQL params
*
* @example $this->getSQLParams() : array(
* 'limit' => '0,20',
* 'order' => 'field'
* )
*
* @return array
*/
public function getSQLParams()
{

Henning Leutz
committed
$result = array();

Henning Leutz
committed
$result['limit'] = $this->getStart()
. ',' . $this->getAttribute('limit');

Henning Leutz
committed
if ($this->getAttribute('order')) {
$result['order'] = $this->getAttribute('order');
}

Henning Leutz
committed
return $result;
}
/**
* Return the start
*
* @return integer
*/
public function getStart()
{
$limit = $this->getAttribute('limit');
$sheet = $this->getAttribute('sheet');
return ($sheet - 1) * $limit;
}
/**
* Set GET parameter to the links
*
* @param $name
* @param $value
*/
public function setGetParams($name, $value)
{
$name = QUI\Utils\Security\Orthos::clear($name);
$value = QUI\Utils\Security\Orthos::clearFormRequest($value);
if (isset($this->getParams[$name])) {
unset($this->getParams[$name]);
}
/**
* Set URL parameter to the links
*
* @param $name
* @param $value
*/
public function setUrlParams($name, $value)
{
$name = QUI\Utils\Security\Orthos::clear($name);
$value = QUI\Utils\Security\Orthos::clear($value);
if (empty($value)) {
if (isset($this->urlParams[$name])) {
unset($this->urlParams[$name]);