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_Oauth
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: * OAuth token resource collection model
29: *
30: * @category Mage
31: * @package Mage_Oauth
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Oauth_Model_Resource_Token_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35: {
36: /**
37: * Initialize collection model
38: *
39: * @return void
40: */
41: protected function _construct()
42: {
43: $this->_init('oauth/token');
44: }
45:
46: /**
47: * Load collection with consumer data
48: *
49: * Method use for show applications list (token-consumer)
50: *
51: * @return Mage_Oauth_Model_Resource_Token_Collection
52: */
53: public function joinConsumerAsApplication()
54: {
55: $select = $this->getSelect();
56: $select->joinLeft(
57: array('c' => $this->getTable('oauth/consumer')),
58: 'c.entity_id = main_table.consumer_id',
59: 'name'
60: );
61:
62: return $this;
63: }
64:
65: /**
66: * Add filter by admin ID
67: *
68: * @param int $adminId
69: * @return Mage_Oauth_Model_Resource_Token_Collection
70: */
71: public function addFilterByAdminId($adminId)
72: {
73: $this->addFilter('main_table.admin_id', $adminId);
74: return $this;
75: }
76:
77: /**
78: * Add filter by customer ID
79: *
80: * @param int $customerId
81: * @return Mage_Oauth_Model_Resource_Token_Collection
82: */
83: public function addFilterByCustomerId($customerId)
84: {
85: $this->addFilter('main_table.customer_id', $customerId);
86: return $this;
87: }
88:
89: /**
90: * Add filter by consumer ID
91: *
92: * @param int $consumerId
93: * @return Mage_Oauth_Model_Resource_Token_Collection
94: */
95: public function addFilterByConsumerId($consumerId)
96: {
97: $this->addFilter('main_table.consumer_id', $consumerId);
98: return $this;
99: }
100:
101: /**
102: * Add filter by type
103: *
104: * @param string $type
105: * @return Mage_Oauth_Model_Resource_Token_Collection
106: */
107: public function addFilterByType($type)
108: {
109: $this->addFilter('main_table.type', $type);
110: return $this;
111: }
112:
113: /**
114: * Add filter by ID
115: *
116: * @param array|int $id
117: * @return Mage_Oauth_Model_Resource_Token_Collection
118: */
119: public function addFilterById($id)
120: {
121: $this->addFilter('main_table.entity_id', array('in' => $id), 'public');
122: return $this;
123: }
124:
125: /**
126: * Add filter by "Is Revoked" status
127: *
128: * @param bool|int $flag
129: * @return Mage_Oauth_Model_Resource_Token_Collection
130: */
131: public function addFilterByRevoked($flag)
132: {
133: $this->addFilter('main_table.revoked', (int) $flag, 'public');
134: return $this;
135: }
136: }
137: