Skip to content

Commit da0e418

Browse files
committed
Merge pull request #94 from zendesk/jose/fix-grid-sorting
Fix grid sorting
2 parents 0c1de28 + 2201c9e commit da0e418

File tree

5 files changed

+13
-67
lines changed

5 files changed

+13
-67
lines changed

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ protected function addColumnBasedOnType($index, $title, $filter = false, $sortab
171171
'filter' => $filter,
172172
'index' => $index,
173173
'type' => $this->getColumnType($index),
174-
'users' => $this->getCollection()->users,
175174
);
176175

177176
$renderer = $this->getColumnRenderer($index);
@@ -242,18 +241,4 @@ public function getGridJavascript()
242241

243242
return $js;
244243
}
245-
246-
/**
247-
* Override the parent method so that $this->_prepareCollection() is called first
248-
*
249-
* @return $this
250-
*/
251-
protected function _prepareGrid()
252-
{
253-
$this->_prepareCollection();
254-
$this->_prepareColumns();
255-
$this->_prepareMassactionBlock();
256-
257-
return $this;
258-
}
259244
}

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/All.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ protected function _prepareColumns() {
5252
$this->addColumn('requester_id', array(
5353
'header' => Mage::helper('zendesk')->__('Email'),
5454
'width' => '60',
55-
'renderer' => 'zendesk/adminhtml_dashboard_tab_tickets_grid_renderer_email',
56-
'index' => 'requester_id',
55+
'index' => 'requester_email',
5756
'sortable' => false,
58-
'users' => $this->getCollection()->users,
5957
));
6058

6159
$this->addColumn('type', array(

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class Zendesk_Zendesk_Block_Adminhtml_Dashboard_Tab_Tickets_Grid_Renderer_User extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
2020

2121
public function render(Varien_Object $row) {
22-
$users = $this->getColumn()->users;
22+
$users = $row->users;
2323
$value = (int) $row->getData($this->getColumn()->getIndex());
2424

2525
$found = array_filter($users, function($user) use($value) {

src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,19 @@ public function getCollection(array $params = array()) {
123123

124124
$all = Mage::getModel('zendesk/api_tickets')->search($params);
125125

126+
// Set the users for this collection
127+
$this->users = $all['users'];
128+
129+
$emails = array_column($this->users, 'email', 'id');
130+
126131
foreach ($all['results'] as $ticket) {
132+
$ticket['requester_email'] = (isset($emails[$ticket['requester_id']]) ? $emails[$ticket['requester_id']] : '');
133+
127134
$obj = new Varien_Object();
128135
$obj->setData($ticket);
129136
$this->addItem($obj);
130137
}
131138

132-
// Set the users for this collection
133-
$this->users = $all['users'];
134-
135139
$this->setPageSize($params['per_page']);
136140
$this->setCurPage($params['page']);
137141
$this->setOrder($params['sort_by'], $params['sort_order']);
@@ -146,9 +150,13 @@ public function getCollection(array $params = array()) {
146150
public function getCollectionFromView($viewId, array $params = array()) {
147151
$view = Mage::getModel('zendesk/api_views')->execute($viewId, $params);
148152

153+
// Set the users for this collection
154+
$this->users = (isset($view['users'])) ? $view['users'] : array();
155+
149156
if (is_array($view['rows'])) {
150157
foreach ($view['rows'] as $row) {
151158
$ticket = array_merge($row, $row['ticket']);
159+
$ticket['users'] = $this->users;
152160

153161
$this->appendParamsWithoutIdPostfix($ticket, array('requester', 'assignee', 'group'));
154162

@@ -158,9 +166,6 @@ public function getCollectionFromView($viewId, array $params = array()) {
158166
}
159167
}
160168

161-
// Set the users for this collection
162-
$this->users = (isset($view['users'])) ? $view['users'] : array();
163-
164169
$this->_viewColumns = $view['columns'] ? $view['columns'] : array();
165170

166171
$this->setPageSize($params['per_page']);

0 commit comments

Comments
 (0)