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_Core
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: * Store group collection
30: *
31: * @category Mage
32: * @package Mage_Core
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Core_Model_Resource_Store_Group_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Load default flag
39: *
40: * @deprecated since 1.5.0.0
41: * @var boolean
42: */
43: protected $_loadDefault = false;
44:
45: /**
46: * Define resource model
47: *
48: */
49: protected function _construct()
50: {
51: $this->setFlag('load_default_store_group', false);
52: $this->_init('core/store_group');
53: }
54:
55: /**
56: * Set flag for load default (admin) store
57: *
58: * @param boolean $loadDefault
59: *
60: * @return Mage_Core_Model_Resource_Store_Group_Collection
61: */
62: public function setLoadDefault($loadDefault)
63: {
64: return $this->setFlag('load_default_store_group', (bool)$loadDefault);
65: }
66:
67: /**
68: * Is load default (admin) store
69: *
70: * @return boolean
71: */
72: public function getLoadDefault()
73: {
74: return $this->getFlag('load_default_store_group');
75: }
76:
77: /**
78: * Add disable default store group filter to collection
79: *
80: * @return Mage_Core_Model_Resource_Store_Group_Collection
81: */
82: public function setWithoutDefaultFilter()
83: {
84: return $this->addFieldToFilter('main_table.group_id', array('gt' => 0));
85: }
86:
87: /**
88: * Filter to discard stores without views
89: *
90: * @return Mage_Core_Model_Resource_Store_Group_Collection
91: */
92: public function setWithoutStoreViewFilter()
93: {
94: return $this->addFieldToFilter('main_table.default_store_id', array('gt' => 0));
95: }
96:
97: /**
98: * Load collection data
99: *
100: * @return Mage_Core_Model_Resource_Store_Group_Collection
101: */
102: public function _beforeLoad()
103: {
104: if (!$this->getLoadDefault()) {
105: $this->setWithoutDefaultFilter();
106: }
107: $this->addOrder('main_table.name', self::SORT_ORDER_ASC);
108: return parent::_beforeLoad();
109: }
110:
111: /**
112: * Convert collection items to array for select options
113: *
114: * @return array
115: */
116: public function toOptionArray()
117: {
118: return $this->_toOptionArray('group_id', 'name');
119: }
120:
121: /**
122: * Add filter by website to collection
123: *
124: * @param int|array $website
125: *
126: * @return Mage_Core_Model_Resource_Store_Group_Collection
127: */
128: public function addWebsiteFilter($website)
129: {
130: return $this->addFieldToFilter('main_table.website_id', array('in' => $website));
131: }
132: }
133: