Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Paging.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Ui\Component;
7 
13 {
14  const NAME = 'paging';
15 
21  protected $_data = [
22  'config' => [
23  'options' => [
24  '20' => [
25  'value' => 20,
26  'label' => 20
27  ],
28  '30' => [
29  'value' => 30,
30  'label' => 30
31  ],
32  '50' => [
33  'value' => 50,
34  'label' => 50
35  ],
36  '100' => [
37  'value' => 100,
38  'label' => 100
39  ],
40  '200' => [
41  'value' => 200,
42  'label' => 200
43  ],
44  ],
45  'pageSize' => 20,
46  'current' => 1
47  ]
48  ];
49 
55  public function getComponentName()
56  {
57  return static::NAME;
58  }
59 
65  public function prepare()
66  {
67  $this->prepareOptions();
68  $paging = $this->getContext()->getRequestParam('paging');
69  if (!isset($paging['notLimits'])) {
70  $this->getContext()
71  ->getDataProvider()
72  ->setLimit($this->getOffset($paging), $this->getSize($paging));
73  }
74 
75  parent::prepare();
76  }
77 
83  protected function prepareOptions()
84  {
85  $config = $this->getData('config');
86  if (isset($config['options'])) {
87  $config['options'] = array_values($config['options']);
88  foreach ($config['options'] as &$item) {
89  $item['value'] = (int) $item['value'];
90  }
91  unset($item);
92  $this->setData('config', $config);
93  }
94  }
95 
102  protected function getOffset($paging)
103  {
104  $defaultPage = $this->getData('config/current') ?: 1;
105  return (int) (isset($paging['current']) ? $paging['current'] : $defaultPage);
106  }
107 
114  protected function getSize($paging)
115  {
116  $defaultLimit = $this->getData('config/pageSize') ?: 20;
117  return (int) (isset($paging['pageSize']) ? $paging['pageSize'] : $defaultLimit);
118  }
119 }
$config
Definition: fraud_order.php:17