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 class Mage_Customer_Model_Entity_Customer_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
00035 {
00036 protected function _construct()
00037 {
00038 $this->_init('customer/customer');
00039 }
00040
00041 public function groupByEmail()
00042 {
00043 $this->getSelect()
00044 ->from(array('email'=>$this->getEntity()->getEntityTable()),
00045 array('email_count'=>new Zend_Db_Expr('COUNT(email.entity_id)'))
00046 )
00047 ->where('email.entity_id=e.entity_id')
00048 ->group('email.email');
00049 return $this;
00050 }
00051
00052 public function addNameToSelect()
00053 {
00054 $fields = array();
00055 foreach (Mage::getConfig()->getFieldset('customer_account') as $code=>$node) {
00056 if ($node->is('name')) {
00057
00058 $fields[$code] = $code;
00059 }
00060 }
00061
00062 $expr = 'CONCAT('
00063 .(isset($fields['prefix']) ? 'IF({{prefix}} IS NOT NULL AND {{prefix}} != "", CONCAT({{prefix}}," "), ""),' : '')
00064 .'{{firstname}}'.(isset($fields['middlename']) ? ',IF({{middlename}} IS NOT NULL AND {{middlename}} != "", CONCAT(" ",{{middlename}}), "")' : '').'," ",{{lastname}}'
00065 .(isset($fields['suffix']) ? ',IF({{suffix}} IS NOT NULL AND {{suffix}} != "", CONCAT(" ",{{suffix}}), "")' : '')
00066 .')';
00067
00068 $this->addExpressionAttributeToSelect('name', $expr, $fields);
00069 return $this;
00070 }
00071
00072
00073
00074
00075
00076
00077 public function getSelectCountSql()
00078 {
00079 $this->_renderFilters();
00080
00081 $countSelect = clone $this->getSelect();
00082 $countSelect->reset(Zend_Db_Select::ORDER);
00083 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00084 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00085 $countSelect->reset(Zend_Db_Select::COLUMNS);
00086
00087 $countSelect->from('', 'COUNT(*)');
00088 $countSelect->resetJoinLeft();
00089
00090 return $countSelect;
00091 }
00092
00093
00094
00095
00096
00097
00098 public function getAllIds($limit=null, $offset=null)
00099 {
00100 $idsSelect = clone $this->getSelect();
00101 $idsSelect->reset(Zend_Db_Select::ORDER);
00102 $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00103 $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00104 $idsSelect->reset(Zend_Db_Select::COLUMNS);
00105 $idsSelect->from(null, 'e.'.$this->getEntity()->getIdFieldName());
00106 $idsSelect->limit($limit, $offset);
00107 $idsSelect->resetJoinLeft();
00108
00109 return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams);
00110 }
00111 }