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_Tag_Customer_Collection extends Mage_Tag_Model_Mysql4_Customer_Collection
00036 {
00037
00038 public function addTagedCount()
00039 {
00040 $this->getSelect()
00041 ->from('', array('taged' => 'count(tr.tag_relation_id)'));
00042
00043 return $this;
00044 }
00045
00046 public function getSelectCountSql()
00047 {
00048 $countSelect = clone $this->getSelect();
00049 $countSelect->reset(Zend_Db_Select::ORDER);
00050 $countSelect->reset(Zend_Db_Select::GROUP);
00051 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00052 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00053
00054 $sql = $countSelect->__toString();
00055
00056 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(DISTINCT tr.customer_id) from ', $sql);
00057
00058 return $sql;
00059 }
00060
00061 public function setOrder($attribute, $dir='desc')
00062 {
00063 switch( $attribute ) {
00064 case 'taged':
00065 $this->getSelect()->order($attribute . ' ' . $dir);
00066 break;
00067
00068 default:
00069 parent::setOrder($attribute, $dir);
00070 }
00071 return $this;
00072 }
00073 }