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_Sales
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: * Flat sales abstract collection
30: *
31: * @category Mage
32: * @package Mage_Sales
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: abstract class Mage_Sales_Model_Resource_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Check if $attribute is Mage_Eav_Model_Entity_Attribute and convert to string field name
39: *
40: * @param string|Mage_Eav_Model_Entity_Attribute $attribute
41: * @return string
42: */
43: protected function _attributeToField($attribute)
44: {
45: $field = false;
46: if (is_string($attribute)) {
47: $field = $attribute;
48: } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute) {
49: $field = $attribute->getAttributeCode();
50: }
51: if (!$field) {
52: Mage::throwException(Mage::helper('sales')->__('Cannot determine the field name.'));
53: }
54: return $field;
55: }
56:
57: /**
58: * Add attribute to select result set.
59: * Backward compatibility with EAV collection
60: *
61: * @param string $attribute
62: * @return Mage_Sales_Model_Resource_Collection_Abstract
63: */
64: public function addAttributeToSelect($attribute)
65: {
66: $this->addFieldToSelect($this->_attributeToField($attribute));
67: return $this;
68: }
69:
70: /**
71: * Specify collection select filter by attribute value
72: * Backward compatibility with EAV collection
73: *
74: * @param string|Mage_Eav_Model_Entity_Attribute $attribute
75: * @param array|integer|string|null $condition
76: * @return Mage_Sales_Model_Resource_Collection_Abstract
77: */
78: public function addAttributeToFilter($attribute, $condition = null)
79: {
80: $this->addFieldToFilter($this->_attributeToField($attribute), $condition);
81: return $this;
82: }
83:
84: /**
85: * Specify collection select order by attribute value
86: * Backward compatibility with EAV collection
87: *
88: * @param string $attribute
89: * @param string $dir
90: * @return Mage_Sales_Model_Resource_Collection_Abstract
91: */
92: public function addAttributeToSort($attribute, $dir = 'asc')
93: {
94: $this->addOrder($this->_attributeToField($attribute), $dir);
95: return $this;
96: }
97:
98: /**
99: * Set collection page start and records to show
100: * Backward compatibility with EAV collection
101: *
102: * @param integer $pageNum
103: * @param integer $pageSize
104: * @return Mage_Sales_Model_Resource_Collection_Abstract
105: */
106: public function setPage($pageNum, $pageSize)
107: {
108: $this->setCurPage($pageNum)
109: ->setPageSize($pageSize);
110: return $this;
111: }
112:
113: /**
114: * Create all ids retrieving select with limitation
115: * Backward compatibility with EAV collection
116: *
117: * @param int $limit
118: * @param int $offset
119: * @return Mage_Eav_Model_Entity_Collection_Abstract
120: */
121: protected function _getAllIdsSelect($limit = null, $offset = null)
122: {
123: $idsSelect = clone $this->getSelect();
124: $idsSelect->reset(Zend_Db_Select::ORDER);
125: $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
126: $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
127: $idsSelect->reset(Zend_Db_Select::COLUMNS);
128: $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
129: $idsSelect->limit($limit, $offset);
130: return $idsSelect;
131: }
132:
133: /**
134: * Retrive all ids for collection
135: * Backward compatibility with EAV collection
136: *
137: * @param int $limit
138: * @param int $offset
139: * @return array
140: */
141: public function getAllIds($limit = null, $offset = null)
142: {
143: return $this->getConnection()->fetchCol(
144: $this->_getAllIdsSelect($limit, $offset),
145: $this->_bindParams
146: );
147: }
148:
149: /**
150: * Backward compatibility with EAV collection
151: *
152: * @todo implement join functionality if necessary
153: *
154: * @param string $alias
155: * @param string $attribute
156: * @param string $bind
157: * @param string $filter
158: * @param string $joinType
159: * @param int $storeId
160: * @return Mage_Sales_Model_Resource_Collection_Abstract
161: */
162: public function joinAttribute($alias, $attribute, $bind, $filter = null, $joinType = 'inner', $storeId = null)
163: {
164: return $this;
165: }
166: }
167: