/** * Add events log to a collection * The collection id field is used without corellation, so it must be unique. * DESC ordering by event will be added to the collection * * @param \Magento\Framework\Data\Collection\AbstractDb $collection * @param int $eventTypeId * @param int $eventSubjectId * @param int $subtype * @param array $skipIds * @return $this */ public function applyLogToCollection(\Magento\Framework\Data\Collection\AbstractDb $collection, $eventTypeId, $eventSubjectId, $subtype, $skipIds = []) { $idFieldName = $collection->getResource()->getIdFieldName(); $derivedSelect = $this->getConnection()->select()->from($this->getTable('report_event'), ['event_id' => new \Zend_Db_Expr('MAX(event_id)'), 'object_id'])->where('event_type_id = ?', (int) $eventTypeId)->where('subject_id = ?', (int) $eventSubjectId)->where('subtype = ?', (int) $subtype)->where('store_id IN(?)', $this->getCurrentStoreIds())->group('object_id'); if ($skipIds) { if (!is_array($skipIds)) { $skipIds = [(int) $skipIds]; } $derivedSelect->where('object_id NOT IN(?)', $skipIds); } $collection->getSelect()->joinInner(['evt' => new \Zend_Db_Expr("({$derivedSelect})")], "{$idFieldName} = evt.object_id", [])->order('evt.event_id ' . \Magento\Framework\DB\Select::SQL_DESC); return $this; }
/** * Apply fulltext filters * * @param DbCollection $collection * @param array $filters * @return void */ public function apply(DbCollection $collection, $filters) { $columns = $this->getFulltextIndexColumns($collection->getResource(), $collection->getMainTable()); if (!$columns) { return; } foreach ($filters as $filter) { $collection->getSelect() ->where( 'MATCH(' . implode(',', $columns) . ') AGAINST(?)', $filter['condition'] ); } }