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: class Mage_Adminhtml_Block_Sales_Order_View_Tab_History
35: extends Mage_Adminhtml_Block_Template
36: implements Mage_Adminhtml_Block_Widget_Tab_Interface
37: {
38: protected function _construct()
39: {
40: parent::_construct();
41: $this->setTemplate('sales/order/view/tab/history.phtml');
42: }
43:
44: 45: 46: 47: 48:
49: public function getOrder()
50: {
51: return Mage::registry('current_order');
52: }
53:
54: 55: 56: 57: 58: 59:
60: public function getFullHistory()
61: {
62: $order = $this->getOrder();
63:
64: $history = array();
65: foreach ($order->getAllStatusHistory() as $orderComment){
66: $history[] = $this->_prepareHistoryItem(
67: $orderComment->getStatusLabel(),
68: $orderComment->getIsCustomerNotified(),
69: $orderComment->getCreatedAtDate(),
70: $orderComment->getComment()
71: );
72: }
73:
74: foreach ($order->getCreditmemosCollection() as $_memo){
75: $history[] = $this->_prepareHistoryItem(
76: $this->__('Credit memo #%s created', $_memo->getIncrementId()),
77: $_memo->getEmailSent(),
78: $_memo->getCreatedAtDate()
79: );
80:
81: foreach ($_memo->getCommentsCollection() as $_comment){
82: $history[] = $this->_prepareHistoryItem(
83: $this->__('Credit memo #%s comment added', $_memo->getIncrementId()),
84: $_comment->getIsCustomerNotified(),
85: $_comment->getCreatedAtDate(),
86: $_comment->getComment()
87: );
88: }
89: }
90:
91: foreach ($order->getShipmentsCollection() as $_shipment){
92: $history[] = $this->_prepareHistoryItem(
93: $this->__('Shipment #%s created', $_shipment->getIncrementId()),
94: $_shipment->getEmailSent(),
95: $_shipment->getCreatedAtDate()
96: );
97:
98: foreach ($_shipment->getCommentsCollection() as $_comment){
99: $history[] = $this->_prepareHistoryItem(
100: $this->__('Shipment #%s comment added', $_shipment->getIncrementId()),
101: $_comment->getIsCustomerNotified(),
102: $_comment->getCreatedAtDate(),
103: $_comment->getComment()
104: );
105: }
106: }
107:
108: foreach ($order->getInvoiceCollection() as $_invoice){
109: $history[] = $this->_prepareHistoryItem(
110: $this->__('Invoice #%s created', $_invoice->getIncrementId()),
111: $_invoice->getEmailSent(),
112: $_invoice->getCreatedAtDate()
113: );
114:
115: foreach ($_invoice->getCommentsCollection() as $_comment){
116: $history[] = $this->_prepareHistoryItem(
117: $this->__('Invoice #%s comment added', $_invoice->getIncrementId()),
118: $_comment->getIsCustomerNotified(),
119: $_comment->getCreatedAtDate(),
120: $_comment->getComment()
121: );
122: }
123: }
124:
125: foreach ($order->getTracksCollection() as $_track){
126: $history[] = $this->_prepareHistoryItem(
127: $this->__('Tracking number %s for %s assigned', $_track->getNumber(), $_track->getTitle()),
128: false,
129: $_track->getCreatedAtDate()
130: );
131: }
132:
133: usort($history, array(__CLASS__, "_sortHistoryByTimestamp"));
134: return $history;
135: }
136:
137: 138: 139: 140: 141: 142: 143: 144:
145: public function getItemCreatedAt(array $item, $dateType = 'date', $format = 'medium')
146: {
147: if (!isset($item['created_at'])) {
148: return '';
149: }
150: if ('date' === $dateType) {
151: return $this->helper('core')->formatDate($item['created_at'], $format);
152: }
153: return $this->helper('core')->formatTime($item['created_at'], $format);
154: }
155:
156: 157: 158: 159: 160: 161:
162: public function getItemTitle(array $item)
163: {
164: return (isset($item['title']) ? $this->escapeHtml($item['title']) : '');
165: }
166:
167: 168: 169: 170: 171: 172: 173:
174: public function isItemNotified(array $item, $isSimpleCheck = true)
175: {
176: if ($isSimpleCheck) {
177: return !empty($item['notified']);
178: }
179: return isset($item['notified']) && false !== $item['notified'];
180: }
181:
182: 183: 184: 185: 186: 187:
188: public function (array $item)
189: {
190: $allowedTags = array('b','br','strong','i','u');
191: return (isset($item['comment']) ? $this->escapeHtml($item['comment'], $allowedTags) : '');
192: }
193:
194: 195: 196: 197: 198: 199: 200: 201: 202:
203: protected function _prepareHistoryItem($label, $notified, $created, $comment = '')
204: {
205: return array(
206: 'title' => $label,
207: 'notified' => $notified,
208: 'comment' => $comment,
209: 'created_at' => $created
210: );
211: }
212:
213: 214: 215: 216: 217:
218: public function getTabLabel()
219: {
220: return Mage::helper('sales')->__('Comments History');
221: }
222:
223: 224: 225: 226: 227:
228: public function getTabTitle()
229: {
230: return Mage::helper('sales')->__('Order History');
231: }
232:
233: 234: 235: 236: 237:
238: public function getTabClass()
239: {
240: return 'ajax only';
241: }
242:
243: 244: 245: 246: 247:
248: public function getClass()
249: {
250: return $this->getTabClass();
251: }
252:
253: 254: 255: 256: 257:
258: public function getTabUrl()
259: {
260: return $this->getUrl('*/*/commentsHistory', array('_current' => true));
261: }
262:
263: 264: 265: 266: 267:
268: public function canShowTab()
269: {
270: return true;
271: }
272:
273: 274: 275: 276: 277:
278: public function isHidden()
279: {
280: return false;
281: }
282:
283: 284: 285: 286: 287: 288:
289: public function isCustomerNotificationNotApplicable($historyItem)
290: {
291: return $historyItem['notified'] == Mage_Sales_Model_Order_Status_History::CUSTOMER_NOTIFICATION_NOT_APPLICABLE;
292: }
293:
294: 295: 296: 297: 298: 299: 300:
301: private static function _sortHistoryByTimestamp($a, $b)
302: {
303: $createdAtA = $a['created_at'];
304: $createdAtB = $b['created_at'];
305:
306:
307: if ($createdAtA->getTimestamp() == $createdAtB->getTimestamp()) {
308: return 0;
309: }
310: return ($createdAtA->getTimestamp() < $createdAtB->getTimestamp()) ? -1 : 1;
311: }
312: }
313: