1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Rss
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Order Rss Resource Model
30: *
31: * @category Mage
32: * @package Mage_Rss
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Rss_Model_Resource_Order
36: {
37: /**
38: * Enter description here ...
39: *
40: * @deprecated after 1.4.1.0
41: *
42: * @var array
43: */
44: protected $_entityTypeIdsToTypes = array();
45:
46: /**
47: * Enter description here ...
48: *
49: * @deprecated after 1.4.1.0
50: *
51: * @var array
52: */
53: protected $_entityIdsToIncrementIds = array();
54:
55: /**
56: * Enter description here ...
57: *
58: * @deprecated after 1.4.1.0
59: *
60: * @return array
61: */
62: public function getEntityTypeIdsToTypes()
63: {
64: return $this->_entityTypeIdsToTypes;
65: }
66:
67: /**
68: * Enter description here ...
69: *
70: * @deprecated after 1.4.1.0
71: *
72: * @return array
73: */
74: public function getEntityIdsToIncrementIds()
75: {
76: return $this->_entityIdsToIncrementIds;
77: }
78:
79: /**
80: * Enter description here ...
81: *
82: * @deprecated after 1.4.1.0
83: *
84: * @return array
85: */
86: public function getAllOrderEntityTypeIds()
87: {
88: return array();
89: }
90:
91: /**
92: * Enter description here ...
93: *
94: * @deprecated after 1.4.1.0
95: *
96: * @param unknown_type $orderId
97: * @param unknown_type $orderEntityTypes
98: * @return array
99: */
100: public function getAllOrderEntityIds($orderId, $orderEntityTypes)
101: {
102: return array();
103: }
104:
105: /**
106: * Enter description here ...
107: *
108: * @deprecated after 1.4.1.0
109: *
110: * @param unknown_type $entityIds
111: * @return array
112: */
113: public function getAllEntityIds($entityIds = array())
114: {
115: return array();
116: }
117:
118: /**
119: * Enter description here ...
120: *
121: * @deprecated after 1.4.1.0
122: *
123: * @return array
124: */
125: public function getAllEntityTypeCommentIds()
126: {
127: return array();
128: }
129:
130: /**
131: * Retrieve core resource model
132: *
133: * @return Mage_Core_Model_Resource
134: */
135: public function getCoreResource()
136: {
137: return Mage::getSingleton('core/resource');
138: }
139:
140: /**
141: * Retrieve order comments
142: *
143: * @param int $orderId
144: * @return array
145: */
146: public function getAllCommentCollection($orderId)
147: {
148: $res = $this->getCoreResource();
149: $read = $res->getConnection('core_read');
150:
151: $fields = array(
152: 'notified' => 'is_customer_notified',
153: 'comment',
154: 'created_at',
155: );
156: $commentSelects = array();
157: foreach (array('invoice', 'shipment', 'creditmemo') as $entityTypeCode) {
158: $mainTable = $res->getTableName('sales/' . $entityTypeCode);
159: $slaveTable = $res->getTableName('sales/' . $entityTypeCode . '_comment');
160: $select = $read->select()
161: ->from(array('main' => $mainTable), array(
162: 'entity_id' => 'order_id',
163: 'entity_type_code' => new Zend_Db_Expr("'$entityTypeCode'")
164: ))
165: ->join(array('slave' => $slaveTable), 'main.entity_id = slave.parent_id', $fields)
166: ->where('main.order_id = ?', $orderId);
167: $commentSelects[] = '(' . $select . ')';
168: }
169: $select = $read->select()
170: ->from($res->getTableName('sales/order_status_history'), array(
171: 'entity_id' => 'parent_id',
172: 'entity_type_code' => new Zend_Db_Expr("'order'")
173: ) + $fields)
174: ->where('parent_id = ?', $orderId)
175: ->where('is_visible_on_front > 0');
176: $commentSelects[] = '(' . $select . ')';
177:
178: $commentSelect = $read->select()
179: ->union($commentSelects, Zend_Db_Select::SQL_UNION_ALL);
180:
181: $select = $read->select()
182: ->from(array('orders' => $res->getTableName('sales/order')), array('increment_id'))
183: ->join(array('t' => $commentSelect),'t.entity_id = orders.entity_id')
184: ->order('orders.created_at desc');
185:
186: return $read->fetchAll($select);
187: }
188: }
189: