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: * Wishlist Report collection
30: *
31: * @category Mage
32: * @package Mage_Reports
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Reports_Model_Resource_Wishlist_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Wishlist table name
39: *
40: * @var string
41: */
42: protected $_wishlistTable;
43:
44: /**
45: * Resource initialization
46: *
47: */
48: protected function _construct()
49: {
50: $this->_init('wishlist/wishlist');
51: $this->setWishlistTable($this->getTable('wishlist/wishlist'));
52: }
53: /**
54: * Set wishlist table name
55: *
56: * @param string $value
57: * @return Mage_Reports_Model_Resource_Wishlist_Collection
58: */
59: public function setWishlistTable($value)
60: {
61: $this->_wishlistTable = $value;
62: return $this;
63: }
64:
65: /**
66: * retrieve wishlist table name
67: *
68: * @return string
69: */
70: public function getWishlistTable()
71: {
72: return $this->_wishlistTable;
73: }
74:
75: /**
76: * Retrieve wishlist customer count
77: *
78: * @return array
79: */
80: public function getWishlistCustomerCount()
81: {
82: /** @var $collection Mage_Customer_Model_Resource_Customer_Collection */
83: $collection = Mage::getResourceModel('customer/customer_collection');
84:
85: $customersSelect = $collection->getSelectCountSql();
86:
87: $countSelect = clone $customersSelect;
88: $countSelect->joinLeft(
89: array('wt' => $this->getWishlistTable()),
90: 'wt.customer_id = e.entity_id',
91: array()
92: )
93: ->group('wt.wishlist_id');
94: $count = $collection->count();
95: $resultSelect = $this->getConnection()->select()
96: ->union(array($customersSelect, $count), Zend_Db_Select::SQL_UNION_ALL);
97: list($customers, $count) = $this->getConnection()->fetchCol($resultSelect);
98:
99: return array(($count*100)/$customers, $count);
100: }
101:
102: /**
103: * Get shared items collection count
104: *
105: * @return int
106: */
107: public function getSharedCount()
108: {
109: /** @var $collection Mage_Customer_Model_Resource_Customer_Collection */
110: $collection = Mage::getResourceModel('customer/customer_collection');
111: $countSelect = $collection->getSelectCountSql();
112: $countSelect->joinLeft(
113: array('wt' => $this->getWishlistTable()),
114: 'wt.customer_id=e.entity_id',
115: array()
116: )
117: ->where('wt.shared=1')
118: ->group('wt.wishlist_id');
119: return $countSelect->getAdapter()->fetchOne($countSelect);
120: }
121: }
122: