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_Product_Collection extends Mage_Tag_Model_Mysql4_Product_Collection
00036 {
00037 public function addUniqueTagedCount()
00038 {
00039 $this->getSelect()
00040 ->from('', array('utaged' => 'count(DISTINCT(relation.tag_id))'));
00041
00042 return $this;
00043 }
00044
00045 public function addAllTagedCount()
00046 {
00047 $this->getSelect()
00048 ->from('', array('taged' => 'count(relation.tag_id)'));
00049
00050 return $this;
00051 }
00052
00053 public function addTagedCount()
00054 {
00055 $this->getSelect()
00056 ->from('', array('taged' => 'count(relation.tag_relation_id)'));
00057
00058 return $this;
00059 }
00060
00061 public function addGroupByProduct()
00062 {
00063 $this->getSelect()
00064 ->group('relation.product_id');
00065 $this->setJoinFlag('distinct');
00066 return $this;
00067 }
00068
00069 public function addGroupByTag()
00070 {
00071 $this->getSelect()
00072 ->group('relation.tag_id');
00073 $this->setJoinFlag('distinct');
00074 $this->setJoinFlag('group_tag');
00075 return $this;
00076 }
00077
00078 public function addProductFilter($customerId)
00079 {
00080 $this->getSelect()
00081 ->where('relation.product_id = ?', $customerId);
00082 $this->_customerFilterId = $customerId;
00083 return $this;
00084 }
00085
00086
00087
00088 public function setOrder($attribute, $dir='desc')
00089 {
00090 if ($attribute == 'utaged' || $attribute == 'taged' || $attribute == 'tag_name') {
00091 $this->getSelect()->order($attribute . ' ' . $dir);
00092 } else {
00093 parent::setOrder($attribute, $dir);
00094 }
00095
00096 return $this;
00097 }
00098
00099
00100 protected function _joinFields()
00101 {
00102 $tagTable = Mage::getSingleton('core/resource')->getTableName('tag/tag');
00103 $tagRelationTable = Mage::getSingleton('core/resource')->getTableName('tag/relation');
00104 $this->addAttributeToSelect('name');
00105 $this->getSelect()
00106 ->join(array('relation' => $tagRelationTable), "relation.product_id = e.entity_id")
00107 ->join(array('t' => $tagTable), "t.tag_id =relation.tag_id", array(
00108 'tag_id', 'status', 'tag_name' => 'name'
00109 ));
00110
00111
00112 }
00113 }