1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Index
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Index Event Collection
30: *
31: * @category Mage
32: * @package Mage_Index
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Index_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Initialize resource
39: *
40: */
41: protected function _construct()
42: {
43: $this->_init('index/event');
44: }
45:
46: /**
47: * Add filter by entity
48: *
49: * @param string | array $entity
50: * @return Mage_Index_Model_Resource_Event_Collection
51: */
52: public function addEntityFilter($entity)
53: {
54: if (is_array($entity) && !empty($entity)) {
55: $this->addFieldToFilter('entity', array('in'=>$entity));
56: } else {
57: $this->addFieldToFilter('entity', $entity);
58: }
59: return $this;
60: }
61:
62: /**
63: * Add filter by type
64: *
65: * @param string | array $type
66: * @return Mage_Index_Model_Resource_Event_Collection
67: */
68: public function addTypeFilter($type)
69: {
70: if (is_array($type) && !empty($type)) {
71: $this->addFieldToFilter('type', array('in'=>$type));
72: } else {
73: $this->addFieldToFilter('type', $type);
74: }
75: return $this;
76: }
77:
78: /**
79: * Add filter by process and status to events collection
80: *
81: * @param int|array|Mage_Index_Model_Process $process
82: * @param string $status
83: * @return Mage_Index_Model_Resource_Event_Collection
84: */
85: public function addProcessFilter($process, $status = null)
86: {
87: $this->_joinProcessEventTable();
88: if ($process instanceof Mage_Index_Model_Process) {
89: $this->addFieldToFilter('process_event.process_id', $process->getId());
90: } elseif (is_array($process) && !empty($process)) {
91: $this->addFieldToFilter('process_event.process_id', array('in' => $process));
92: } else {
93: $this->addFieldToFilter('process_event.process_id', $process);
94: }
95:
96: if ($status !== null) {
97: if (is_array($status) && !empty($status)) {
98: $this->addFieldToFilter('process_event.status', array('in' => $status));
99: } else {
100: $this->addFieldToFilter('process_event.status', $status);
101: }
102: }
103: return $this;
104: }
105:
106: /**
107: * Join index_process_event table to event table
108: *
109: * @return Mage_Index_Model_Resource_Event_Collection
110: */
111: protected function _joinProcessEventTable()
112: {
113: if (!$this->getFlag('process_event_table_joined')) {
114: $this->getSelect()->join(array('process_event' => $this->getTable('index/process_event')),
115: 'process_event.event_id=main_table.event_id',
116: array('process_event_status' => 'status')
117: );
118: $this->setFlag('process_event_table_joined', true);
119: }
120: return $this;
121: }
122:
123: /**
124: * Reset collection state
125: *
126: * @return Mage_Index_Model_Resource_Event_Collection
127: */
128: public function reset()
129: {
130: $this->_totalRecords = null;
131: $this->_data = null;
132: $this->_isCollectionLoaded = false;
133: $this->_items = array();
134: return $this;
135: }
136: }
137: