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_Reports
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: * Report event collection
30: *
31: * @category Mage
32: * @package Mage_Reports
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Reports_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Store Ids
39: *
40: * @var array
41: */
42: protected $_storeIds;
43:
44: /**
45: * Use analytic function flag
46: * If true - allows to prepare final select with analytic function
47: *
48: * @var bool
49: */
50: protected $_useAnalyticFunction = true;
51:
52: /**
53: * Resource initializations
54: *
55: */
56: protected function _construct()
57: {
58: $this->_init('reports/event');
59: }
60:
61: /**
62: * Add store ids filter
63: *
64: * @param array $storeIds
65: * @return Mage_Reports_Model_Resource_Event_Collection
66: */
67: public function addStoreFilter(array $storeIds)
68: {
69: $this->_storeIds = $storeIds;
70: return $this;
71: }
72:
73: /**
74: * Add recently filter
75: *
76: * @param int $typeId
77: * @param int $subjectId
78: * @param int $subtype
79: * @param int|array $ignore
80: * @param int $limit
81: * @return Mage_Reports_Model_Resource_Event_Collection
82: */
83: public function addRecentlyFiler($typeId, $subjectId, $subtype = 0, $ignore = null, $limit = 15)
84: {
85: $stores = $this->getResource()->getCurrentStoreIds($this->_storeIds);
86: $select = $this->getSelect();
87: $select->where('event_type_id = ?', $typeId)
88: ->where('subject_id = ?', $subjectId)
89: ->where('subtype = ?', $subtype)
90: ->where('store_id IN(?)', $stores);
91: if ($ignore) {
92: if (is_array($ignore)) {
93: $select->where('object_id NOT IN(?)', $ignore);
94: } else {
95: $select->where('object_id <> ?', $ignore);
96: }
97: }
98: $select->group('object_id')
99: ->limit($limit);
100: return $this;
101: }
102: }
103: