1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Reports_Model_Resource_Review_Customer_Collection extends Mage_Review_Model_Resource_Review_Collection
36: {
37: 38: 39: 40: 41:
42: public function joinCustomers()
43: {
44: 45: 46:
47: $this->_useAnalyticFunction = true;
48:
49:
50: $adapter = $this->getConnection();
51:
52: $customer = Mage::getResourceSingleton('customer/customer');
53:
54: $firstnameAttr = $customer->getAttribute('firstname');
55:
56: $lastnameAttr = $customer->getAttribute('lastname');
57:
58: $firstnameCondition = array('table_customer_firstname.entity_id = detail.customer_id');
59:
60: if ($firstnameAttr->getBackend()->isStatic()) {
61: $firstnameField = 'firstname';
62: } else {
63: $firstnameField = 'value';
64: $firstnameCondition[] = $adapter->quoteInto('table_customer_firstname.attribute_id = ?',
65: (int)$firstnameAttr->getAttributeId());
66: }
67:
68: $this->getSelect()->joinInner(
69: array('table_customer_firstname' => $firstnameAttr->getBackend()->getTable()),
70: implode(' AND ', $firstnameCondition),
71: array());
72:
73:
74: $lastnameCondition = array('table_customer_lastname.entity_id = detail.customer_id');
75: if ($lastnameAttr->getBackend()->isStatic()) {
76: $lastnameField = 'lastname';
77: } else {
78: $lastnameField = 'value';
79: $lastnameCondition[] = $adapter->quoteInto('table_customer_lastname.attribute_id = ?',
80: (int)$lastnameAttr->getAttributeId());
81: }
82:
83:
84: $customerFullname = $adapter->getConcatSql(array(
85: "table_customer_firstname.{$firstnameField}",
86: "table_customer_lastname.{$lastnameField}"
87: ), ' ');
88: $this->getSelect()->reset(Zend_Db_Select::COLUMNS)
89: ->joinInner(
90: array('table_customer_lastname' => $lastnameAttr->getBackend()->getTable()),
91: implode(' AND ', $lastnameCondition),
92: array())
93: ->columns(array(
94: 'customer_id' => 'detail.customer_id',
95: 'customer_name' => $customerFullname,
96: 'review_cnt' => 'COUNT(main_table.review_id)'))
97: ->group('detail.customer_id');
98:
99: return $this;
100: }
101:
102: 103: 104: 105: 106:
107: public function getSelectCountSql()
108: {
109: $countSelect = clone $this->_select;
110: $countSelect->reset(Zend_Db_Select::ORDER);
111: $countSelect->reset(Zend_Db_Select::GROUP);
112: $countSelect->reset(Zend_Db_Select::HAVING);
113: $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
114: $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
115: $countSelect->reset(Zend_Db_Select::COLUMNS);
116:
117: $countSelect->columns(new Zend_Db_Expr('COUNT(DISTINCT detail.customer_id)'));
118:
119: return $countSelect;
120: }
121: }
122: