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_Newsletter_Model_Mysql4_Problem_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00036 {
00037
00038 protected $_subscribersInfoJoinedFlag = false;
00039 protected $_problemGrouped = false;
00040
00041 protected function _construct()
00042 {
00043 $this->_init('newsletter/problem');
00044 }
00045
00046 public function addSubscriberInfo()
00047 {
00048 $this->getSelect()
00049 ->joinLeft(array('subscriber'=>$this->getTable('subscriber')),'main_table.subscriber_id = subscriber.subscriber_id',
00050 array('subscriber_email','customer_id','subscriber_status'));
00051 $this->_subscribersInfoJoinedFlag = true;
00052
00053 return $this;
00054 }
00055
00056 public function addQueueInfo()
00057 {
00058 $this->getSelect()
00059 ->joinLeft(array('queue'=>$this->getTable('queue')),'main_table.queue_id = queue.queue_id',
00060 array('queue_start_at', 'queue_finish_at'))
00061 ->joinLeft(array('template'=>$this->getTable('template')),'main_table.queue_id = queue.queue_id',
00062 array('template_subject','template_code','template_sender_name','template_sender_email'));
00063 return $this;
00064 }
00065
00066
00067
00068
00069
00070
00071 protected function _addCustomersData( )
00072 {
00073 $customersIds = array();
00074
00075 foreach ($this->getItems() as $item) {
00076 if($item->getCustomerId()) {
00077 $customersIds[] = $item->getCustomerId();
00078 }
00079 }
00080
00081 if(count($customersIds) == 0) {
00082 return;
00083 }
00084
00085 $customers = Mage::getResourceModel('customer/customer_collection')
00086 ->addNameToSelect()
00087 ->addAttributeToFilter('entity_id', array("in"=>$customersIds));
00088
00089 $customers->load();
00090
00091 foreach($customers->getItems() as $customer) {
00092 $problems = $this->getItemsByColumnValue('customer_id', $customer->getId());
00093 foreach ($problems as $problem) {
00094 $problem->setCustomerName($customer->getName())
00095 ->setCustomerFirstName($customer->getFirstName())
00096 ->setCustomerLastName($customer->getLastName());
00097 }
00098 }
00099
00100 }
00101
00102 public function load($printQuery=false, $logQuery=false)
00103 {
00104 parent::load($printQuery, $logQuery);
00105 if($this->_subscribersInfoJoinedFlag && !$this->isLoaded()) {
00106 $this->_addCustomersData();
00107 }
00108 return $this;
00109 }
00110
00111 }