Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProvider.php
Go to the documentation of this file.
1 <?php
8 
13 {
17  protected $collection;
18 
22  private $operationDetails;
23 
27  private $request;
28 
40  public function __construct(
41  $name,
44  \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory $bulkCollectionFactory,
45  \Magento\AsynchronousOperations\Model\Operation\Details $operationDetails,
46  \Magento\Framework\App\RequestInterface $request,
47  array $meta = [],
48  array $data = []
49  ) {
50  $this->collection = $bulkCollectionFactory->create();
51  $this->operationDetails = $operationDetails;
52  $this->request = $request;
53  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
54  $this->meta = $this->prepareMeta($this->meta);
55  }
56 
63  private function getSummaryReport($operationDetails)
64  {
65  if (0 == $operationDetails['operations_successful'] && 0 == $operationDetails['operations_failed']) {
66  return __('Pending, in queue...');
67  }
68 
69  $summaryReport = __('%1 items selected for mass update', $operationDetails['operations_total'])->__toString();
70  if ($operationDetails['operations_successful'] > 0) {
71  $summaryReport .= __(', %1 successfully updated', $operationDetails['operations_successful']);
72  }
73 
74  if ($operationDetails['operations_failed'] > 0) {
75  $summaryReport .= __(', %1 failed to update', $operationDetails['operations_failed']);
76  }
77 
78  return $summaryReport;
79  }
80 
86  public function getData()
87  {
88  $data = [];
89  $items = $this->collection->getItems();
90  if (count($items) == 0) {
91  return $data;
92  }
93  $bulk = array_shift($items);
95  $data = $bulk->getData();
96  $operationDetails = $this->operationDetails->getDetails($data['uuid']);
97  $data['summary'] = $this->getSummaryReport($operationDetails);
98  $data = array_merge($data, $operationDetails);
99 
100  return [$bulk->getBulkId() => $data];
101  }
102 
109  public function prepareMeta($meta)
110  {
111  $requestId = $this->request->getParam($this->requestFieldName);
112  $operationDetails = $this->operationDetails->getDetails($requestId);
113 
114  if (isset($operationDetails['failed_retriable']) && !$operationDetails['failed_retriable']) {
115  $meta['retriable_operations']['arguments']['data']['disabled'] = true;
116  }
117 
118  if (isset($operationDetails['failed_not_retriable']) && !$operationDetails['failed_not_retriable']) {
119  $meta['failed_operations']['arguments']['data']['disabled'] = true;
120  }
121 
122  return $meta;
123  }
124 }
__()
Definition: __.php:13
__construct( $name, $primaryFieldName, $requestFieldName, \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory $bulkCollectionFactory, \Magento\AsynchronousOperations\Model\Operation\Details $operationDetails, \Magento\Framework\App\RequestInterface $request, array $meta=[], array $data=[])
$items