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_Wishlist
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: * Wishlist resource model
30: *
31: * @category Mage
32: * @package Mage_Wishlist
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Wishlist_Model_Resource_Wishlist extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: /**
38: * Store wishlist items count
39: *
40: * @var null|int
41: */
42: protected $_itemsCount = null;
43:
44: /**
45: * Store customer ID field name
46: *
47: * @var string
48: */
49: protected $_customerIdFieldName = 'customer_id';
50:
51: /**
52: * Set main entity table name and primary key field name
53: */
54: protected function _construct()
55: {
56: $this->_init('wishlist/wishlist', 'wishlist_id');
57: }
58:
59: /**
60: * Prepare wishlist load select query
61: *
62: * @param string $field
63: * @param mixed $value
64: * @param mixed $object
65: * @return Zend_Db_Select
66: */
67: protected function _getLoadSelect($field, $value, $object)
68: {
69: $select = parent::_getLoadSelect($field, $value, $object);
70: if ($field == $this->_customerIdFieldName) {
71: $select->order('wishlist_id ' . Zend_Db_Select::SQL_ASC)
72: ->limit(1);
73: }
74: return $select;
75: }
76:
77: /**
78: * Getter for customer ID field name
79: *
80: * @return string
81: */
82: public function getCustomerIdFieldName()
83: {
84: return $this->_customerIdFieldName;
85: }
86:
87: /**
88: * Setter for customer ID field name
89: *
90: * @param $fieldName
91: *
92: * @return Mage_Wishlist_Model_Resource_Wishlist
93: */
94: public function setCustomerIdFieldName($fieldName)
95: {
96: $this->_customerIdFieldName = $fieldName;
97: return $this;
98: }
99:
100: /**
101: * Retrieve wishlist items count
102: *
103: * @deprecated after 1.6.0.0-rc2
104: * @see Mage_Wishlist_Model_Wishlist::getItemsCount()
105: *
106: * @param Mage_Wishlist_Model_Wishlist $wishlist
107: *
108: * @return int
109: */
110: public function fetchItemsCount(Mage_Wishlist_Model_Wishlist $wishlist)
111: {
112: if (is_null($this->_itemsCount)) {
113: $this->_itemsCount = $wishlist->getItemsCount();
114: }
115:
116: return $this->_itemsCount;
117: }
118:
119: }
120: