Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Summary.php
Go to the documentation of this file.
1 <?php
7 
9 
16 {
22  protected function _construct()
23  {
24  $this->_init('review_entity_summary', 'entity_pk_value');
25  }
26 
35  protected function _getLoadSelect($field, $value, $object)
36  {
37  $select = parent::_getLoadSelect($field, $value, $object);
38  $select->where('store_id = ?', (int)$object->getStoreId());
39  return $select;
40  }
41 
48  public function reAggregate($summary)
49  {
50  $connection = $this->getConnection();
51  $select = $connection->select()->from(
52  $this->getMainTable(),
53  ['primary_id' => new \Zend_Db_Expr('MAX(primary_id)'), 'store_id', 'entity_pk_value']
54  )->group(
55  ['entity_pk_value', 'store_id']
56  );
57  foreach ($connection->fetchAll($select) as $row) {
58  if (isset($summary[$row['store_id']]) && isset($summary[$row['store_id']][$row['entity_pk_value']])) {
59  $summaryItem = $summary[$row['store_id']][$row['entity_pk_value']];
60  if ($summaryItem->getCount()) {
61  $ratingSummary = round($summaryItem->getSum() / $summaryItem->getCount());
62  } else {
63  $ratingSummary = $summaryItem->getSum();
64  }
65  } else {
66  $ratingSummary = 0;
67  }
68  $connection->update(
69  $this->getMainTable(),
70  ['rating_summary' => $ratingSummary],
71  $connection->quoteInto('primary_id = ?', $row['primary_id'])
72  );
73  }
74  return $this;
75  }
76 }
$value
Definition: gender.phtml:16
$connection
Definition: bulk.php:13