Skip to content

Commit 3a2fa2a

Browse files
committed
fix sorting issue
1 parent 2b4c6f9 commit 3a2fa2a

File tree

6 files changed

+131
-55
lines changed

6 files changed

+131
-55
lines changed

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

Lines changed: 2 additions & 3 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);
@@ -248,12 +247,12 @@ public function getGridJavascript()
248247
*
249248
* @return $this
250249
*/
251-
protected function _prepareGrid()
250+
/* protected function _prepareGrid()
252251
{
253252
$this->_prepareCollection();
254253
$this->_prepareColumns();
255254
$this->_prepareMassactionBlock();
256255
257256
return $this;
258-
}
257+
}*/
259258
}

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']);
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
if (!function_exists('array_column')) {
4+
/**
5+
* This file is part of the array_column library
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
11+
* @license http://opensource.org/licenses/MIT MIT
12+
*/
13+
14+
/**
15+
* Returns the values from a single column of the input array, identified by
16+
* the $columnKey.
17+
*
18+
* Optionally, you may provide an $indexKey to index the values in the returned
19+
* array by the values from the $indexKey column in the input array.
20+
*
21+
* @param array $input A multi-dimensional array (record set) from which to pull
22+
* a column of values.
23+
* @param mixed $columnKey The column of values to return. This value may be the
24+
* integer key of the column you wish to retrieve, or it
25+
* may be the string key name for an associative array.
26+
* @param mixed $indexKey (Optional.) The column to use as the index/keys for
27+
* the returned array. This value may be the integer key
28+
* of the column, or it may be the string key name.
29+
* @return array
30+
*/
31+
function array_column($input = null, $columnKey = null, $indexKey = null)
32+
{
33+
// Using func_get_args() in order to check for proper number of
34+
// parameters and trigger errors exactly as the built-in array_column()
35+
// does in PHP 5.5.
36+
$argc = func_num_args();
37+
$params = func_get_args();
38+
39+
if ($argc < 2) {
40+
trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
41+
return null;
42+
}
43+
44+
if (!is_array($params[0])) {
45+
trigger_error(
46+
'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
47+
E_USER_WARNING
48+
);
49+
return null;
50+
}
51+
52+
if (!is_int($params[1])
53+
&& !is_float($params[1])
54+
&& !is_string($params[1])
55+
&& $params[1] !== null
56+
&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
57+
) {
58+
trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
59+
return false;
60+
}
61+
62+
if (isset($params[2])
63+
&& !is_int($params[2])
64+
&& !is_float($params[2])
65+
&& !is_string($params[2])
66+
&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
67+
) {
68+
trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
69+
return false;
70+
}
71+
72+
$paramsInput = $params[0];
73+
$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
74+
75+
$paramsIndexKey = null;
76+
if (isset($params[2])) {
77+
if (is_float($params[2]) || is_int($params[2])) {
78+
$paramsIndexKey = (int) $params[2];
79+
} else {
80+
$paramsIndexKey = (string) $params[2];
81+
}
82+
}
83+
84+
$resultArray = array();
85+
86+
foreach ($paramsInput as $row) {
87+
$key = $value = null;
88+
$keySet = $valueSet = false;
89+
90+
if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
91+
$keySet = true;
92+
$key = (string) $row[$paramsIndexKey];
93+
}
94+
95+
if ($paramsColumnKey === null) {
96+
$valueSet = true;
97+
$value = $row;
98+
} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
99+
$valueSet = true;
100+
$value = $row[$paramsColumnKey];
101+
}
102+
103+
if ($valueSet) {
104+
if ($keySet) {
105+
$resultArray[$key] = $value;
106+
} else {
107+
$resultArray[] = $value;
108+
}
109+
}
110+
111+
}
112+
113+
return $resultArray;
114+
}
115+
116+
}

0 commit comments

Comments
 (0)