Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractDataProvider.php
Go to the documentation of this file.
1 <?php
7 
10 
15 abstract class AbstractDataProvider implements DataProviderInterface, \Countable
16 {
22  protected $name;
23 
29  protected $primaryFieldName;
30 
36  protected $requestFieldName;
37 
41  protected $meta = [];
42 
48  protected $data = [];
49 
53  protected $collection;
54 
62  public function __construct(
63  $name,
66  array $meta = [],
67  array $data = []
68  ) {
69  $this->name = $name;
70  $this->primaryFieldName = $primaryFieldName;
71  $this->requestFieldName = $requestFieldName;
72  $this->meta = $meta;
73  $this->data = $data;
74  }
75 
79  public function getCollection()
80  {
81  return $this->collection;
82  }
83 
89  public function getName()
90  {
91  return $this->name;
92  }
93 
99  public function getPrimaryFieldName()
100  {
102  }
103 
109  public function getRequestFieldName()
110  {
112  }
113 
117  public function getMeta()
118  {
119  return $this->meta;
120  }
121 
128  public function getFieldSetMetaInfo($fieldSetName)
129  {
130  return isset($this->meta[$fieldSetName]) ? $this->meta[$fieldSetName] : [];
131  }
132 
137  public function getFieldsMetaInfo($fieldSetName)
138  {
139  return isset($this->meta[$fieldSetName]['children']) ? $this->meta[$fieldSetName]['children'] : [];
140  }
141 
147  public function getFieldMetaInfo($fieldSetName, $fieldName)
148  {
149  return isset($this->meta[$fieldSetName]['children'][$fieldName])
150  ? $this->meta[$fieldSetName]['children'][$fieldName]
151  : [];
152  }
153 
157  public function addFilter(\Magento\Framework\Api\Filter $filter)
158  {
159  $this->getCollection()->addFieldToFilter(
160  $filter->getField(),
161  [$filter->getConditionType() => $filter->getValue()]
162  );
163  }
164 
170  public function getSearchCriteria()
171  {
172  //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids
173  return null;
174  }
175 
181  public function getSearchResult()
182  {
183  //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids
184  return $this->getCollection();
185  }
186 
194  public function addField($field, $alias = null)
195  {
196  $this->getCollection()->addFieldToSelect($field, $alias);
197  }
198 
206  public function addOrder($field, $direction)
207  {
208  $this->getCollection()->addOrder($field, $direction);
209  }
210 
218  public function setLimit($offset, $size)
219  {
220  $this->getCollection()->setPageSize($size);
221  $this->getCollection()->setCurPage($offset);
222  }
223 
231  public function removeField($field, $isAlias = false)
232  {
233  $this->getCollection()->removeFieldFromSelect($field, $isAlias);
234  }
235 
241  public function removeAllFields()
242  {
243  $this->getCollection()->removeAllFieldsFromSelect();
244  }
245 
251  public function getData()
252  {
253  return $this->getCollection()->toArray();
254  }
255 
261  public function count()
262  {
263  return $this->getCollection()->count();
264  }
265 
271  public function getConfigData()
272  {
273  return isset($this->data['config']) ? $this->data['config'] : [];
274  }
275 
282  public function setConfigData($config)
283  {
284  $this->data['config'] = $config;
285  }
286 
293  public function getAllIds()
294  {
295  return $this->getCollection()->getAllIds();
296  }
297 }
__construct( $name, $primaryFieldName, $requestFieldName, array $meta=[], array $data=[])
$config
Definition: fraud_order.php:17
addFilter(\Magento\Framework\Api\Filter $filter)
if(!trim($html)) $alias
Definition: details.phtml:20