/** * 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 Varien_Data_Collection_Db $collection * @param int $eventTypeId * @param int $eventSubjectId * @param int $subtype * @param array $skipIds */ public function applyLogToCollection(Varien_Data_Collection_Db $collection, $eventTypeId, $eventSubjectId, $subtype, $skipIds = array()) { $idFieldName = $collection->getResource()->getIdFieldName(); $derivedSelect = $this->getReadConnection()->select()->from($this->getTable('reports/event'), array('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 = array((int) $skipIds); } $derivedSelect->where('object_id NOT IN(?)', $skipIds); } $collection->getSelect()->joinInner(array('evt' => new Zend_Db_Expr("({$derivedSelect})")), "`{$idFieldName}`=evt.object_id", array())->order('evt.event_id DESC'); }
/** * Inner join the groupscatalog index table to hide entities not visible to the specified customer group id * * @param Varien_Data_Collection_Db $collection * @param int $groupId The customer group id * @return void */ public function addGroupsCatalogFilterToCollection(Varien_Data_Collection_Db $collection, $groupId) { /* @var $helper Netzarbeiter_GroupsCatalog2_Helper_Data */ $helper = Mage::helper('netzarbeiter_groupscatalog2'); /** * This is slightly complicated but it works with products and * categories whether the flat tables enabled or not * * @var $entityType string * @var $entity Mage_Catalog_Model_Abstract */ $entity = $collection->getNewEmptyItem(); $entityType = $helper->getEntityTypeCodeFromEntity($entity); $this->_init($helper->getIndexTableByEntityType($entityType), 'id'); if ($this->_doesIndexExists()) { $filterTable = $collection->getResource()->getTable($helper->getIndexTableByEntityType($entityType)); $entityIdField = "{$this->_getCollectionTableAlias($collection)}.entity_id"; $this->_addGroupsCatalogFilterToSelect($collection->getSelect(), $filterTable, $groupId, $collection->getStoreId(), $entityIdField); } }