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_Newsletter_Model_Resource_Problem_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: 38: 39: 40: 41:
42: protected $_subscribersInfoJoinedFlag = false;
43:
44: 45: 46: 47: 48:
49: protected $_problemGrouped = false;
50:
51: 52: 53: 54:
55: protected function _construct()
56: {
57: $this->_init('newsletter/problem');
58: }
59:
60: 61: 62: 63: 64:
65: public function addSubscriberInfo()
66: {
67: $this->getSelect()->joinLeft(array('subscriber'=>$this->getTable('newsletter/subscriber')),
68: 'main_table.subscriber_id = subscriber.subscriber_id',
69: array('subscriber_email','customer_id','subscriber_status')
70: );
71: $this->addFilterToMap('subscriber_id', 'main_table.subscriber_id');
72: $this->_subscribersInfoJoinedFlag = true;
73:
74: return $this;
75: }
76:
77: 78: 79: 80: 81:
82: public function addQueueInfo()
83: {
84: $this->getSelect()->joinLeft(array('queue'=>$this->getTable('newsletter/queue')),
85: 'main_table.queue_id = queue.queue_id',
86: array('queue_start_at', 'queue_finish_at')
87: )
88: ->joinLeft(array('template'=>$this->getTable('newsletter/template')), 'queue.template_id = template.template_id',
89: array('template_subject','template_code','template_sender_name','template_sender_email')
90: );
91: return $this;
92: }
93:
94: 95: 96: 97:
98: protected function _addCustomersData()
99: {
100: $customersIds = array();
101:
102: foreach ($this->getItems() as $item) {
103: if ($item->getCustomerId()) {
104: $customersIds[] = $item->getCustomerId();
105: }
106: }
107:
108: if (count($customersIds) == 0) {
109: return;
110: }
111:
112: $customers = Mage::getResourceModel('customer/customer_collection')
113: ->addNameToSelect()
114: ->addAttributeToFilter('entity_id', array("in"=>$customersIds));
115:
116: $customers->load();
117:
118: foreach ($customers->getItems() as $customer) {
119: $problems = $this->getItemsByColumnValue('customer_id', $customer->getId());
120: foreach ($problems as $problem) {
121: $problem->setCustomerName($customer->getName())
122: ->setCustomerFirstName($customer->getFirstName())
123: ->setCustomerLastName($customer->getLastName());
124: }
125: }
126: }
127:
128: 129: 130: 131: 132: 133: 134:
135: public function load($printQuery = false, $logQuery = false)
136: {
137: parent::load($printQuery, $logQuery);
138: if ($this->_subscribersInfoJoinedFlag && !$this->isLoaded()) {
139: $this->_addCustomersData();
140: }
141: return $this;
142: }
143: }
144: