Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReviewDataProvider.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
13 
23 {
28  protected $collectionFactory;
29 
34  protected $request;
35 
45  public function __construct(
46  $name,
49  CollectionFactory $collectionFactory,
51  array $meta = [],
52  array $data = []
53  ) {
54  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
55  $this->collectionFactory = $collectionFactory;
56  $this->collection = $this->collectionFactory->create();
57  $this->request = $request;
58  }
59 
64  public function getData()
65  {
66  $this->getCollection()->addEntityFilter($this->request->getParam('current_product_id', 0))
67  ->addStoreData();
68 
69  $arrItems = [
70  'totalRecords' => $this->getCollection()->getSize(),
71  'items' => [],
72  ];
73 
74  foreach ($this->getCollection() as $item) {
75  $arrItems['items'][] = $item->toArray([]);
76  }
77 
78  return $arrItems;
79  }
80 
85  public function addFilter(\Magento\Framework\Api\Filter $filter)
86  {
87  $field = $filter->getField();
88 
89  if (in_array($field, ['review_id', 'created_at', 'status_id'])) {
90  $filter->setField('rt.' . $field);
91  }
92 
93  if (in_array($field, ['title', 'nickname', 'detail'])) {
94  $filter->setField('rdt.' . $field);
95  }
96 
97  if ($field === 'review_created_at') {
98  $filter->setField('rt.created_at');
99  }
100 
101  parent::addFilter($filter);
102  }
103 }
__construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, RequestInterface $request, array $meta=[], array $data=[])