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_Customer_Model_Resource_Customer_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
36: {
37: 38: 39:
40: protected function _construct()
41: {
42: $this->_init('customer/customer');
43: }
44:
45: 46: 47: 48: 49:
50: public function groupByEmail()
51: {
52: $this->getSelect()
53: ->from(
54: array('email' => $this->getEntity()->getEntityTable()),
55: array('email_count' => new Zend_Db_Expr('COUNT(email.entity_id)'))
56: )
57: ->where('email.entity_id = e.entity_id')
58: ->group('email.email');
59:
60: return $this;
61: }
62:
63: 64: 65: 66: 67:
68: public function addNameToSelect()
69: {
70: $fields = array();
71: $customerAccount = Mage::getConfig()->getFieldset('customer_account');
72: foreach ($customerAccount as $code => $node) {
73: if ($node->is('name')) {
74: $fields[$code] = $code;
75: }
76: }
77:
78: $adapter = $this->getConnection();
79: $concatenate = array();
80: if (isset($fields['prefix'])) {
81: $concatenate[] = $adapter->getCheckSql(
82: '{{prefix}} IS NOT NULL AND {{prefix}} != \'\'',
83: $adapter->getConcatSql(array('LTRIM(RTRIM({{prefix}}))', '\' \'')),
84: '\'\'');
85: }
86: $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
87: $concatenate[] = '\' \'';
88: if (isset($fields['middlename'])) {
89: $concatenate[] = $adapter->getCheckSql(
90: '{{middlename}} IS NOT NULL AND {{middlename}} != \'\'',
91: $adapter->getConcatSql(array('LTRIM(RTRIM({{middlename}}))', '\' \'')),
92: '\'\'');
93: }
94: $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
95: if (isset($fields['suffix'])) {
96: $concatenate[] = $adapter
97: ->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'',
98: $adapter->getConcatSql(array('\' \'', 'LTRIM(RTRIM({{suffix}}))')),
99: '\'\'');
100: }
101:
102: $nameExpr = $adapter->getConcatSql($concatenate);
103:
104: $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);
105:
106: return $this;
107: }
108:
109: 110: 111: 112: 113:
114: public function getSelectCountSql()
115: {
116: $select = parent::getSelectCountSql();
117: $select->resetJoinLeft();
118:
119: return $select;
120: }
121:
122: 123: 124: 125: 126: 127: 128:
129: protected function _getAllIdsSelect($limit = null, $offset = null)
130: {
131: $idsSelect = parent::_getAllIdsSelect($limit, $offset);
132: $idsSelect->resetJoinLeft();
133: return $idsSelect;
134: }
135: }
136: