From 3e02d5aff85babc3ffbfcf52313f2108e313aa23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:46:43 +0200 Subject: Adding upstream version 2.12.1. Signed-off-by: Daniel Baumann --- application/forms/Control/LimiterControlForm.php | 134 +++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 application/forms/Control/LimiterControlForm.php (limited to 'application/forms/Control') diff --git a/application/forms/Control/LimiterControlForm.php b/application/forms/Control/LimiterControlForm.php new file mode 100644 index 0000000..88adf4b --- /dev/null +++ b/application/forms/Control/LimiterControlForm.php @@ -0,0 +1,134 @@ + '10', + 25 => '25', + 50 => '50', + 100 => '100', + 500 => '500' + ); + + public static $defaultElementDecorators = [ + ['Label', ['tag' => 'span', 'separator' => '']], + ['ViewHelper', ['separator' => '']], + ]; + + /** + * Default limit for this instance + * + * @var int|null + */ + protected $defaultLimit; + + /** + * {@inheritdoc} + */ + public function init() + { + $this->setAttrib('class', static::CSS_CLASS_LIMITER); + } + + /** + * Get the default limit + * + * @return int + */ + public function getDefaultLimit() + { + return $this->defaultLimit !== null ? $this->defaultLimit : static::DEFAULT_LIMIT; + } + + /** + * Set the default limit + * + * @param int $defaultLimit + * + * @return $this + */ + public function setDefaultLimit($defaultLimit) + { + $defaultLimit = (int) $defaultLimit; + + if (! isset(static::$limits[$defaultLimit])) { + static::$limits[$defaultLimit] = $defaultLimit; + } + + $this->defaultLimit = $defaultLimit; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getRedirectUrl() + { + return $this->getRequest()->getUrl() + ->setParam('limit', $this->getElement('limit')->getValue()) + ->without('page'); + } + + /** + * {@inheritdoc} + */ + public function createElements(array $formData) + { + $options = static::$limits; + $pageSize = (int) $this->getRequest()->getUrl()->getParam('limit', $this->getDefaultLimit()); + + if (! isset($options[$pageSize])) { + $options[$pageSize] = $pageSize; + } + + $this->addElement( + 'select', + 'limit', + array( + 'autosubmit' => true, + 'escape' => false, + 'label' => '#', + 'multiOptions' => $options, + 'value' => $pageSize + ) + ); + } + + /** + * Limiter control is always successful + * + * @return bool + */ + public function onSuccess() + { + return true; + } +} -- cgit v1.2.3