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: /**
29: * Customer My Applications list block
30: *
31: * @category Mage
32: * @package Mage_Oauth
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Oauth_Block_Customer_Token_List extends Mage_Customer_Block_Account_Dashboard
36: {
37: /**
38: * Collection model
39: *
40: * @var Mage_Oauth_Model_Resource_Token_Collection
41: */
42: protected $_collection;
43:
44: /**
45: * Prepare collection
46: */
47: protected function _construct()
48: {
49: /** @var $session Mage_Customer_Model_Session */
50: $session = Mage::getSingleton('customer/session');
51:
52: /** @var $collection Mage_Oauth_Model_Resource_Token_Collection */
53: $collection = Mage::getModel('oauth/token')->getCollection();
54: $collection->joinConsumerAsApplication()
55: ->addFilterByType(Mage_Oauth_Model_Token::TYPE_ACCESS)
56: ->addFilterByCustomerId($session->getCustomerId());
57: $this->_collection = $collection;
58: }
59:
60: /**
61: * Get count of total records
62: *
63: * @return int
64: */
65: public function count()
66: {
67: return $this->_collection->getSize();
68: }
69:
70: /**
71: * Get toolbar html
72: *
73: * @return string
74: */
75: public function getToolbarHtml()
76: {
77: return $this->getChildHtml('toolbar');
78: }
79:
80: /**
81: * Prepare layout
82: *
83: * @return Mage_Oauth_Block_Customer_Token_List
84: */
85: protected function _prepareLayout()
86: {
87: /** @var $toolbar Mage_Page_Block_Html_Pager */
88: $toolbar = $this->getLayout()->createBlock('page/html_pager', 'customer_token.toolbar');
89: $toolbar->setCollection($this->_collection);
90: $this->setChild('toolbar', $toolbar);
91: parent::_prepareLayout();
92: return $this;
93: }
94:
95: /**
96: * Get collection
97: *
98: * @return Mage_Oauth_Model_Resource_Token_Collection
99: */
100: public function getCollection()
101: {
102: return $this->_collection;
103: }
104:
105: /**
106: * Get link for update revoke status
107: *
108: * @param Mage_Oauth_Model_Token $model
109: * @return string
110: */
111: public function getUpdateRevokeLink(Mage_Oauth_Model_Token $model)
112: {
113: return Mage::getUrl('oauth/customer_token/revoke/',
114: array('id' => $model->getId(), 'status' => (int) !$model->getRevoked()));
115: }
116:
117: /**
118: * Get delete link
119: *
120: * @param Mage_Oauth_Model_Token $model
121: * @return string
122: */
123: public function getDeleteLink(Mage_Oauth_Model_Token $model)
124: {
125: return Mage::getUrl('oauth/customer_token/delete/', array('id' => $model->getId()));
126: }
127:
128: /**
129: * Retrieve a token status label
130: *
131: * @param int $revokedStatus Token status of revoking
132: * @return string
133: */
134: public function getStatusLabel($revokedStatus)
135: {
136: $labels = array(
137: $this->__('Enabled'),
138: $this->__('Disabled')
139: );
140: return $labels[$revokedStatus];
141: }
142:
143: /**
144: * Retrieve a label of link to change a token status
145: *
146: * @param int $revokedStatus Token status of revoking
147: * @return string
148: */
149: public function getChangeStatusLabel($revokedStatus)
150: {
151: $labels = array(
152: $this->__('Disable'),
153: $this->__('Enable')
154: );
155: return $labels[$revokedStatus];
156: }
157:
158: /**
159: * Retrieve a message to confirm an action to change a token status
160: *
161: * @param int $revokedStatus Token status of revoking
162: * @return string
163: */
164: public function getChangeStatusConfirmMessage($revokedStatus)
165: {
166: $messages = array(
167: $this->__('Are you sure you want to disable this application?'),
168: $this->__('Are you sure you want to enable this application?')
169: );
170: return $messages[$revokedStatus];
171: }
172: }
173: