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: * Events model
29: *
30: * @method Mage_Reports_Model_Resource_Event _getResource()
31: * @method Mage_Reports_Model_Resource_Event getResource()
32: * @method string getLoggedAt()
33: * @method Mage_Reports_Model_Event setLoggedAt(string $value)
34: * @method int getEventTypeId()
35: * @method Mage_Reports_Model_Event setEventTypeId(int $value)
36: * @method int getObjectId()
37: * @method Mage_Reports_Model_Event setObjectId(int $value)
38: * @method int getSubjectId()
39: * @method Mage_Reports_Model_Event setSubjectId(int $value)
40: * @method int getSubtype()
41: * @method Mage_Reports_Model_Event setSubtype(int $value)
42: * @method int getStoreId()
43: * @method Mage_Reports_Model_Event setStoreId(int $value)
44: *
45: * @category Mage
46: * @package Mage_Reports
47: * @author Magento Core Team <core@magentocommerce.com>
48: */
49: class Mage_Reports_Model_Event extends Mage_Core_Model_Abstract
50: {
51: const EVENT_PRODUCT_VIEW = 1;
52: const EVENT_PRODUCT_SEND = 2;
53: const EVENT_PRODUCT_COMPARE = 3;
54: const EVENT_PRODUCT_TO_CART = 4;
55: const EVENT_PRODUCT_TO_WISHLIST = 5;
56: const EVENT_WISHLIST_SHARE = 6;
57:
58: /**
59: * Initialize resource
60: *
61: */
62: protected function _construct()
63: {
64: $this->_init('reports/event');
65: }
66:
67: /**
68: * Before Event save process
69: *
70: * @return Mage_Reports_Model_Event
71: */
72: protected function _beforeSave()
73: {
74: $this->setLoggedAt(Mage::getModel('core/date')->gmtDate());
75: return parent::_beforeSave();
76: }
77:
78: /**
79: * Update customer type after customer login
80: *
81: * @param int $visitorId
82: * @param int $customerId
83: * @param array $types
84: * @return Mage_Reports_Model_Event
85: */
86: public function updateCustomerType($visitorId, $customerId, $types = null)
87: {
88: if (is_null($types)) {
89: $types = array();
90: foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) {
91: if ($eventType->getCustomerLogin()) {
92: $types[$eventType->getId()] = $eventType->getId();
93: }
94: }
95: }
96: $this->getResource()->updateCustomerType($this, $visitorId, $customerId, $types);
97: return $this;
98: }
99:
100: /**
101: * Clean events (visitors)
102: *
103: * @return Mage_Reports_Model_Event
104: */
105: public function clean()
106: {
107: $this->getResource()->clean($this);
108: return $this;
109: }
110: }
111: