00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Reports_Model_Mysql4_Wishlist_Product_Collection extends Mage_Wishlist_Model_Mysql4_Product_Collection
00036 {
00037 protected function _construct()
00038 {
00039 $this->_init('wishlist/wishlist');
00040 }
00041
00042 public function addWishlistCount()
00043 {
00044 $wishlistItemTable = Mage::getSingleton('core/resource')->getTableName('wishlist/item');
00045
00046 $this->getSelect()
00047 ->from(array('wi' => $wishlistItemTable), 'count(wishlist_item_id) as wishlists')
00048 ->where('wi.product_id=e.entity_id')
00049 ->group('wi.product_id');
00050
00051 $this->getEntity()->setStore(0);
00052 return $this;
00053 }
00054
00055 public function getCustomerCount()
00056 {
00057 $this->getSelect()->reset();
00058 $this->getSelect()->from("wishlist", array("count(wishlist_id) as wishlist_cnt"))
00059 ->group("wishlist.customer_id");
00060 return $this;
00061 }
00062
00063 public function getSelectCountSql()
00064 {
00065 $countSelect = clone $this->getSelect();
00066 $countSelect->reset(Zend_Db_Select::ORDER);
00067 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00068 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00069 $countSelect->reset(Zend_Db_Select::GROUP);
00070
00071 $sql = $countSelect->__toString();
00072
00073 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(*) from ', $sql);
00074
00075 return $sql;
00076 }
00077
00078 public function setOrder($attribute, $dir='desc')
00079 {
00080 switch ($attribute)
00081 {
00082 case 'wishlists':
00083 $this->getSelect()->order($attribute . ' ' . $dir);
00084 break;
00085 default:
00086 parent::setOrder($attribute, $dir);
00087 }
00088
00089 return $this;
00090 }
00091
00092 }