1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36: 37: 38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setId('authorizedTokensGrid');
43: $this->setUseAjax(true);
44: $this->setSaveParametersInSession(true);
45: $this->setDefaultSort('entity_id')
46: ->setDefaultDir(Varien_Db_Select::SQL_DESC);
47: }
48:
49: 50: 51: 52: 53:
54: protected function _prepareCollection()
55: {
56:
57: $collection = Mage::getModel('oauth/token')->getCollection();
58: $collection->joinConsumerAsApplication()
59: ->addFilterByType(Mage_Oauth_Model_Token::TYPE_ACCESS);
60: $this->setCollection($collection);
61:
62: parent::_prepareCollection();
63: return $this;
64: }
65:
66: 67: 68: 69: 70:
71: protected function _prepareColumns()
72: {
73: $this->addColumn('entity_id', array(
74: 'header' => Mage::helper('oauth')->__('ID'),
75: 'index' => 'entity_id',
76: 'align' => 'right',
77: 'width' => '50px',
78:
79: ));
80:
81: $this->addColumn('name', array(
82: 'header' => $this->__('Application Name'),
83: 'index' => 'name',
84: 'escape' => true,
85: ));
86:
87: $this->addColumn('type', array(
88: 'header' => $this->__('User Type'),
89:
90: 'options' => array(0 => $this->__('Admin'), 1 => $this->__('Customer')),
91: 'frame_callback' => array($this, 'decorateUserType')
92: ));
93:
94: $this->addColumn('user_id', array(
95: 'header' => $this->__('User ID'),
96:
97: 'frame_callback' => array($this, 'decorateUserId')
98: ));
99:
100:
101: $sourceYesNo = Mage::getSingleton('adminhtml/system_config_source_yesno');
102: $this->addColumn('revoked', array(
103: 'header' => $this->__('Revoked'),
104: 'index' => 'revoked',
105: 'width' => '100px',
106: 'type' => 'options',
107: 'options' => $sourceYesNo->toArray(),
108: 'sortable' => true,
109: ));
110:
111: parent::_prepareColumns();
112: return $this;
113: }
114:
115: 116: 117: 118: 119:
120: public function getGridUrl()
121: {
122: return $this->getUrl('*/*/grid', array('_current' => true));
123: }
124:
125: 126: 127: 128: 129: 130:
131: public function getRevokeUrl($row)
132: {
133: return $this->getUrl('*/*/revoke', array('id' => $row->getId()));
134: }
135:
136: 137: 138: 139: 140: 141:
142: public function getDeleteUrl($row)
143: {
144: return $this->getUrl('*/*/delete', array('id' => $row->getId()));
145: }
146:
147: 148: 149: 150: 151:
152: protected function _prepareMassaction()
153: {
154: if(!$this->_isAllowed()) {
155: return $this;
156: }
157:
158: $this->setMassactionIdField('id');
159: $block = $this->getMassactionBlock();
160:
161: $block->setFormFieldName('items');
162: $block->addItem('enable', array(
163: 'label' => Mage::helper('index')->__('Enable'),
164: 'url' => $this->getUrl('*/*/revoke', array('status' => 0)),
165: ));
166: $block->addItem('revoke', array(
167: 'label' => Mage::helper('index')->__('Revoke'),
168: 'url' => $this->getUrl('*/*/revoke', array('status' => 1)),
169: ));
170: $block->addItem('delete', array(
171: 'label' => Mage::helper('index')->__('Delete'),
172: 'url' => $this->getUrl('*/*/delete'),
173: ));
174:
175: return $this;
176: }
177:
178: 179: 180: 181: 182: 183: 184: 185: 186:
187: public function decorateUserType($value, $row, $column, $isExport)
188: {
189: $options = $column->getOptions();
190:
191: $value = ($row->getCustomerId()) ?$options[1] :$options[0];
192: $cell = $value;
193:
194: return $cell;
195: }
196:
197: 198: 199: 200: 201: 202: 203: 204: 205:
206: public function decorateUserId($value, $row, $column, $isExport)
207: {
208: $value = ($row->getCustomerId()) ?$row->getCustomerId() :$row->getAdminId();
209: $cell = $value;
210:
211: return $cell;
212: }
213:
214: 215: 216: 217: 218:
219: protected function _isAllowed()
220: {
221:
222: $session = Mage::getSingleton('admin/session');
223: return $session->isAllowed('system/oauth/authorizedTokens');
224: }
225: }
226: