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_Review_Customer_Collection extends Mage_Review_Model_Mysql4_Review_Collection
00036 {
00037 public function joinCustomers()
00038 {
00039 $customer = Mage::getResourceSingleton('customer/customer');
00040
00041 $firstnameAttr = $customer->getAttribute('firstname');
00042 $firstnameAttrId = $firstnameAttr->getAttributeId();
00043 $firstnameTable = $firstnameAttr->getBackend()->getTable();
00044
00045 if ($firstnameAttr->getBackend()->isStatic()) {
00046 $firstnameField = 'firstname';
00047 $attrCondition = '';
00048 } else {
00049 $firstnameField = 'value';
00050 $attrCondition = ' AND _table_customer_firstname.attribute_id = '.$firstnameAttrId;
00051 }
00052
00053 $this->getSelect()->joinInner(array('_table_customer_firstname' => $firstnameTable),
00054 '_table_customer_firstname.entity_id=detail.customer_id'.$attrCondition, array());
00055
00056 $lastnameAttr = $customer->getAttribute('lastname');
00057 $lastnameAttrId = $lastnameAttr->getAttributeId();
00058 $lastnameTable = $lastnameAttr->getBackend()->getTable();
00059
00060 if ($lastnameAttr->getBackend()->isStatic()) {
00061 $lastnameField = 'lastname';
00062 $attrCondition = '';
00063 } else {
00064 $lastnameField = 'value';
00065 $attrCondition = ' AND _table_customer_lastname.attribute_id = '.$lastnameAttrId;
00066 }
00067
00068 $this->getSelect()->joinInner(array('_table_customer_lastname' => $lastnameTable),
00069 '_table_customer_lastname.entity_id=detail.customer_id'.$attrCondition, array())
00070 ->from("", array(
00071 'customer_name' => "CONCAT(_table_customer_firstname.{$firstnameField}, ' ', _table_customer_lastname.{$lastnameField})",
00072 'review_cnt' => "COUNT(main_table.review_id)"))
00073 ->group('detail.customer_id');
00074
00075 return $this;
00076 }
00077
00078 public function getSelectCountSql()
00079 {
00080 $countSelect = clone $this->_select;
00081 $countSelect->reset(Zend_Db_Select::ORDER);
00082 $countSelect->reset(Zend_Db_Select::GROUP);
00083 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00084 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00085
00086 $sql = $countSelect->__toString();
00087
00088 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(DISTINCT `detail`.`customer_id`) from ', $sql);
00089
00090 return $sql;
00091 }
00092 }