Skip to content

Commit b6ad85a

Browse files
committed
sideload users and groups for customer tickets list
1 parent d714255 commit b6ad85a

File tree

3 files changed

+65
-50
lines changed
  • src/app
    • code/community/Zendesk/Zendesk/Model/Api
    • design
      • adminhtml/default/default/template/zendesk/customer
      • frontend/base/default/template/zendesk/customer/tickets

3 files changed

+65
-50
lines changed

src/app/code/community/Zendesk/Zendesk/Model/Api/Tickets.php

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,7 @@ public function get($id, $sideload = false)
3232
$ticket = $response['ticket'];
3333

3434
if($sideload) {
35-
// Sideload user information
36-
if(isset($response['users'])) {
37-
// Generate the list of user IDs from the users provided
38-
$users = array();
39-
foreach($response['users'] as $user) {
40-
$users[$user['id']] = $user;
41-
}
42-
43-
// Use the list of generated users to attach additional details to the ticket
44-
if(isset($ticket['requester_id'])) {
45-
if(isset($users[$ticket['requester_id']])) {
46-
$ticket['requester'] = $users[$ticket['requester_id']];
47-
}
48-
}
49-
50-
if(isset($ticket['submitter_id'])) {
51-
if(isset($users[$ticket['submitter_id']])) {
52-
$ticket['submitter'] = $users[$ticket['submitter_id']];
53-
}
54-
}
55-
56-
if(isset($ticket['assignee_id'])) {
57-
if(isset($users[$ticket['assignee_id']])) {
58-
$ticket['assignee'] = $users[$ticket['assignee_id']];
59-
}
60-
}
61-
}
62-
63-
// Sideload group information
64-
if(isset($response['groups'])) {
65-
// Generate the list of group IDs from the users provided
66-
$groups = array();
67-
foreach($response['groups'] as $group) {
68-
$groups[$group['id']] = $group;
69-
}
70-
71-
// Use the list of generated groups to attach additional details to the ticket
72-
if(isset($ticket['group_id'])) {
73-
if(isset($groups[$ticket['group_id']])) {
74-
$ticket['group'] = $groups[$ticket['group_id']];
75-
}
76-
}
77-
}
35+
$this->formatSideloaded($response, $ticket);
7836
}
7937

8038
return $ticket;
@@ -146,8 +104,19 @@ public function forRequester($customerEmail)
146104
{
147105
$user = Mage::getModel('zendesk/api_users')->find($customerEmail);
148106
if(isset($user['id'])) {
149-
$response = $this->_call('users/' . $user['id'] . '/requests.json', null, 'GET', null, false);
150-
return $response['requests'];
107+
$response = $this->_call(
108+
'users/' . $user['id'] . '/tickets/requested.json',
109+
array('include' => 'users,groups', 'sort_by' => 'updated_at', 'sort_order' => 'desc'),
110+
'GET',
111+
null,
112+
false
113+
);
114+
115+
foreach ($response['tickets'] as &$request) {
116+
$request = $this->formatSideloaded($response, $request);
117+
}
118+
119+
return $response['tickets'];
151120
} else {
152121
return array();
153122
}
@@ -192,4 +161,52 @@ public function create($data)
192161
return (isset($response['ticket']) ? $response['ticket'] : null);
193162
}
194163

164+
private function formatSideloaded($response, $ticket)
165+
{
166+
// Sideload user information
167+
if(isset($response['users'])) {
168+
// Generate the list of user IDs from the users provided
169+
$users = array();
170+
foreach($response['users'] as $user) {
171+
$users[$user['id']] = $user;
172+
}
173+
174+
// Use the list of generated users to attach additional details to the ticket
175+
if(isset($ticket['requester_id'])) {
176+
if(isset($users[$ticket['requester_id']])) {
177+
$ticket['requester'] = $users[$ticket['requester_id']];
178+
}
179+
}
180+
181+
if(isset($ticket['submitter_id'])) {
182+
if(isset($users[$ticket['submitter_id']])) {
183+
$ticket['submitter'] = $users[$ticket['submitter_id']];
184+
}
185+
}
186+
187+
if(isset($ticket['assignee_id'])) {
188+
if(isset($users[$ticket['assignee_id']])) {
189+
$ticket['assignee'] = $users[$ticket['assignee_id']];
190+
}
191+
}
192+
}
193+
194+
// Sideload group information
195+
if(isset($response['groups'])) {
196+
// Generate the list of group IDs from the users provided
197+
$groups = array();
198+
foreach($response['groups'] as $group) {
199+
$groups[$group['id']] = $group;
200+
}
201+
202+
// Use the list of generated groups to attach additional details to the ticket
203+
if(isset($ticket['group_id'])) {
204+
if(isset($groups[$ticket['group_id']])) {
205+
$ticket['group'] = $groups[$ticket['group_id']];
206+
}
207+
}
208+
}
209+
210+
return $ticket;
211+
}
195212
}

src/app/design/adminhtml/default/default/template/zendesk/customer/tickets.phtml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ if($customer = Mage::registry('current_customer')) {
5353
</tr>
5454
</thead>
5555
<tbody class="odd">
56-
<?php foreach($tickets as $ticket): ?>
57-
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
56+
<?php foreach($tickets as $ticket):?>
5857
<tr class="border">
5958
<td><?php echo ucwords($ticket['priority']); ?></td>
6059
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
6160
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
6261
<td><?php echo Mage::helper('core')->formatDate($ticket['updated_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
6362
<td><?php echo ucwords($ticket['status']); ?></td>
64-
<td><?php echo (isset($ticket['group_id'])) ? $t['group']['name'] : ''; ?></td>
65-
<td><?php echo ($ticket['assignee_id']) ? $t['assignee']['name'] : ''; ?></td>
63+
<td><?php echo (isset($ticket['group_id'])) ? $ticket['group']['name'] : ''; ?></td>
64+
<td><?php echo ($ticket['assignee_id']) ? $ticket['assignee']['name'] : ''; ?></td>
6665
</tr>
6766
<?php endforeach; ?>
6867
</tbody>

src/app/design/frontend/base/default/template/zendesk/customer/tickets/list.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
</thead>
3737
<tbody class="odd">
3838
<?php foreach($tickets as $ticket): ?>
39-
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
4039
<tr class="border">
4140
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
4241
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>

0 commit comments

Comments
 (0)