Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions src/app/code/community/Zendesk/Zendesk/Model/Api/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,7 @@ public function get($id, $sideload = false)
$ticket = $response['ticket'];

if($sideload) {
// Sideload user information
if(isset($response['users'])) {
// Generate the list of user IDs from the users provided
$users = array();
foreach($response['users'] as $user) {
$users[$user['id']] = $user;
}

// Use the list of generated users to attach additional details to the ticket
if(isset($ticket['requester_id'])) {
if(isset($users[$ticket['requester_id']])) {
$ticket['requester'] = $users[$ticket['requester_id']];
}
}

if(isset($ticket['submitter_id'])) {
if(isset($users[$ticket['submitter_id']])) {
$ticket['submitter'] = $users[$ticket['submitter_id']];
}
}

if(isset($ticket['assignee_id'])) {
if(isset($users[$ticket['assignee_id']])) {
$ticket['assignee'] = $users[$ticket['assignee_id']];
}
}
}

// Sideload group information
if(isset($response['groups'])) {
// Generate the list of group IDs from the users provided
$groups = array();
foreach($response['groups'] as $group) {
$groups[$group['id']] = $group;
}

// Use the list of generated groups to attach additional details to the ticket
if(isset($ticket['group_id'])) {
if(isset($groups[$ticket['group_id']])) {
$ticket['group'] = $groups[$ticket['group_id']];
}
}
}
$this->formatSideloaded($response, $ticket);
}

return $ticket;
Expand Down Expand Up @@ -146,8 +104,19 @@ public function forRequester($customerEmail)
{
$user = Mage::getModel('zendesk/api_users')->find($customerEmail);
if(isset($user['id'])) {
$response = $this->_call('users/' . $user['id'] . '/requests.json', null, 'GET', null, false);
return $response['requests'];
$response = $this->_call(
'users/' . $user['id'] . '/tickets/requested.json',
array('include' => 'users,groups', 'sort_by' => 'updated_at', 'sort_order' => 'desc'),
'GET',
null,
false
);

foreach ($response['tickets'] as &$request) {
$request = $this->formatSideloaded($response, $request);
}

return $response['tickets'];
} else {
return array();
}
Expand Down Expand Up @@ -192,4 +161,52 @@ public function create($data)
return (isset($response['ticket']) ? $response['ticket'] : null);
}

private function formatSideloaded($response, $ticket)
{
// Sideload user information
if(isset($response['users'])) {
// Generate the list of user IDs from the users provided
$users = array();
foreach($response['users'] as $user) {
$users[$user['id']] = $user;
}

// Use the list of generated users to attach additional details to the ticket
if(isset($ticket['requester_id'])) {
if(isset($users[$ticket['requester_id']])) {
$ticket['requester'] = $users[$ticket['requester_id']];
}
}

if(isset($ticket['submitter_id'])) {
if(isset($users[$ticket['submitter_id']])) {
$ticket['submitter'] = $users[$ticket['submitter_id']];
}
}

if(isset($ticket['assignee_id'])) {
if(isset($users[$ticket['assignee_id']])) {
$ticket['assignee'] = $users[$ticket['assignee_id']];
}
}
}

// Sideload group information
if(isset($response['groups'])) {
// Generate the list of group IDs from the users provided
$groups = array();
foreach($response['groups'] as $group) {
$groups[$group['id']] = $group;
}

// Use the list of generated groups to attach additional details to the ticket
if(isset($ticket['group_id'])) {
if(isset($groups[$ticket['group_id']])) {
$ticket['group'] = $groups[$ticket['group_id']];
}
}
}

return $ticket;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ if($customer = Mage::registry('current_customer')) {
</tr>
</thead>
<tbody class="odd">
<?php foreach($tickets as $ticket): ?>
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
<?php foreach($tickets as $ticket):?>
<tr class="border">
<td><?php echo ucwords($ticket['priority']); ?></td>
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
<td><?php echo Mage::helper('core')->formatDate($ticket['updated_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
<td><?php echo ucwords($ticket['status']); ?></td>
<td><?php echo (isset($ticket['group_id'])) ? $t['group']['name'] : ''; ?></td>
<td><?php echo ($ticket['assignee_id']) ? $t['assignee']['name'] : ''; ?></td>
<td><?php echo (isset($ticket['group_id'])) ? $ticket['group']['name'] : ''; ?></td>
<td><?php echo ($ticket['assignee_id']) ? $ticket['assignee']['name'] : ''; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
</thead>
<tbody class="odd">
<?php foreach($tickets as $ticket): ?>
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
<tr class="border">
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
Expand Down