Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SearchResult.php
Go to the documentation of this file.
1 <?php
7 
11 use Psr\Log\LoggerInterface as Logger;
16 
21 {
25  private $userContext;
26 
30  private $statusMapper;
31 
35  private $operationStatus;
36 
40  private $calculatedStatusSql;
41 
56  public function __construct(
57  EntityFactory $entityFactory,
58  Logger $logger,
59  FetchStrategy $fetchStrategy,
60  EventManager $eventManager,
61  UserContextInterface $userContextInterface,
62  StatusMapper $statusMapper,
63  CalculatedStatusSql $calculatedStatusSql,
64  $mainTable = 'magento_bulk',
65  $resourceModel = null,
66  $identifierName = 'uuid'
67  ) {
68  $this->userContext = $userContextInterface;
69  $this->statusMapper = $statusMapper;
70  $this->calculatedStatusSql = $calculatedStatusSql;
71  parent::__construct(
72  $entityFactory,
73  $logger,
74  $fetchStrategy,
75  $eventManager,
76  $mainTable,
78  $identifierName
79  );
80  }
81 
85  protected function _initSelect()
86  {
87  $this->getSelect()->from(
88  ['main_table' => $this->getMainTable()],
89  [
90  '*',
91  'status' => $this->calculatedStatusSql->get($this->getTable('magento_operation'))
92  ]
93  )->where(
94  'user_id=?',
95  $this->userContext->getUserId()
96  );
97  return $this;
98  }
99 
103  protected function _afterLoad()
104  {
106  foreach ($this->getItems() as $item) {
107  $item->setStatus($this->statusMapper->operationStatusToBulkSummaryStatus($item->getStatus()));
108  }
109  return parent::_afterLoad();
110  }
111 
115  public function addFieldToFilter($field, $condition = null)
116  {
117  if ($field == 'status') {
118  if (is_array($condition)) {
119  foreach ($condition as $value) {
120  $this->operationStatus = $this->statusMapper->bulkSummaryStatusToOperationStatus($value);
121  if (is_array($this->operationStatus)) {
122  foreach ($this->operationStatus as $statusValue) {
123  $this->getSelect()->orHaving('status = ?', $statusValue);
124  }
125  continue;
126  }
127  $this->getSelect()->having('status = ?', $this->operationStatus);
128  }
129  }
130  return $this;
131  }
132  return parent::addFieldToFilter($field, $condition);
133  }
134 
138  public function getSelectCountSql()
139  {
140  $select = parent::getSelectCountSql();
141  $select->columns(['status' => $this->calculatedStatusSql->get($this->getTable('magento_operation'))]);
142  //add grouping by status if filtering by status was executed
143  if (isset($this->operationStatus)) {
144  $select->group('status');
145  }
146  return $select;
147  }
148 }
$logger
__construct(EntityFactory $entityFactory, Logger $logger, FetchStrategy $fetchStrategy, EventManager $eventManager, UserContextInterface $userContextInterface, StatusMapper $statusMapper, CalculatedStatusSql $calculatedStatusSql, $mainTable='magento_bulk', $resourceModel=null, $identifierName='uuid')
$value
Definition: gender.phtml:16
$resourceModel
Definition: tablerates.php:10