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_Api2
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: * API2 filter ACL attribute resource model
29: *
30: * @category Mage
31: * @package Mage_Api2
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Api2_Model_Resource_Acl_Filter_Attribute extends Mage_Core_Model_Resource_Db_Abstract
35: {
36: /**
37: * Attribute Filter resource ID "all"
38: */
39: const FILTER_RESOURCE_ALL = 'all';
40:
41: /**
42: * Initialize resource model
43: *
44: * @return void
45: */
46: protected function _construct()
47: {
48: $this->_init('api2/acl_attribute', 'entity_id');
49: }
50:
51: /**
52: * Get allowed attributes
53: *
54: * @param string $userType
55: * @param string $resourceId
56: * @param string $operation One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
57: * @return string|bool|null
58: */
59: public function getAllowedAttributes($userType, $resourceId, $operation)
60: {
61: $select = $this->_getReadAdapter()->select()
62: ->from($this->getMainTable(), 'allowed_attributes')
63: ->where('user_type = ?', $userType)
64: ->where('resource_id = ?', $resourceId)
65: ->where('operation = ?', $operation);
66:
67: return $this->getReadConnection()->fetchOne($select);
68: }
69:
70: /**
71: * Check if ALL attributes allowed
72: *
73: * @param string $userType
74: * @return bool
75: */
76: public function isAllAttributesAllowed($userType)
77: {
78: $resourceId = self::FILTER_RESOURCE_ALL;
79:
80: $select = $this->getReadConnection()->select()
81: ->from($this->getMainTable(), new Zend_Db_Expr('COUNT(*)'))
82: ->where('user_type = ?', $userType)
83: ->where('resource_id = ?', $resourceId);
84:
85: return ($this->getReadConnection()->fetchOne($select) == 1);
86: }
87: }
88: