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_XmlConnect
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: * Configuration data collection
29: *
30: * @category Mage
31: * @package Mage_Xmlconnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Model_Resource_ConfigData_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
35: {
36: /**
37: * Is application filter applied
38: *
39: * @var bool
40: */
41: protected $_applicationFilter = false;
42:
43: /**
44: * Internal constructor
45: */
46: protected function _construct()
47: {
48: $this->_init('xmlconnect/configData');
49: }
50:
51: /**
52: * Add application filter
53: *
54: * @param $applicationId
55: * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
56: */
57: public function addApplicationIdFilter($applicationId)
58: {
59: $this->_applicationFilter = true;
60: $this->getSelect()->where('application_id=?', $applicationId);
61: return $this;
62: }
63:
64: /**
65: * Add path filter
66: *
67: * @param $path
68: * @param bool $like
69: * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
70: */
71: public function addPathFilter($path, $like = true)
72: {
73: if ($like) {
74: $this->getSelect()->where('path like ?', $path . '/%');
75: } else {
76: $this->getSelect()->where('path=?', $path);
77: }
78: return $this;
79: }
80:
81: /**
82: * Add category filter
83: *
84: * @param $category
85: * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
86: */
87: public function addCategoryFilter($category)
88: {
89: $this->getSelect()->where('category=?', $category);
90: return $this;
91: }
92:
93: /**
94: * Add value filter
95: *
96: * @param $value
97: * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
98: */
99: public function addValueFilter($value)
100: {
101: $this->getSelect()->where('value=?', $value);
102: return $this;
103: }
104:
105: /**
106: * Add filter by array
107: *
108: * @param array $array
109: * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
110: */
111: public function addArrayFilter(array $array)
112: {
113: foreach ($array as $key => $val) {
114: $method = 'add' . uc_words($key, '') . 'Filter';
115: if (is_callable($this->$method($val))) {
116: return $this->$method($val);
117: }
118: }
119: return $this;
120: }
121:
122: /**
123: * Convert items array to array for select options
124: *
125: * return items array
126: * array(
127: * application_id => array(
128: * category => array(
129: * path
130: * )
131: * )
132: * )
133: *
134: * @return array
135: */
136: public function toOptionArray()
137: {
138: $result = array();
139: foreach ($this as $item) {
140: $appId = $item->getData('application_id');
141: $category = $item->getData('category');
142: $path = $item->getData('path');
143: $value = $item->getData('value');
144:
145: if ($this->_applicationFilter) {
146: $result[$category][$path] = $value;
147: } else {
148: $result[$appId][$category][$path] = $value;
149: }
150: }
151: return $result;
152: }
153:
154: /**
155: * Get Application filter status
156: *
157: * @return boolean
158: */
159: public function getApplicationFilter()
160: {
161: return $this->_applicationFilter;
162: }
163:
164: /**
165: * Set Application filter status
166: *
167: * @param boolean $applicationFilter
168: */
169: public function setApplicationFilter($applicationFilter)
170: {
171: $this->_applicationFilter = $applicationFilter;
172: }
173: }
174: