Skip to content
Merged
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
35 changes: 31 additions & 4 deletions src/app/code/community/Zendesk/Zendesk/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public function getUrl($object = '', $id = null, $format = 'old')
{
$protocol = 'https://';
$domain = Mage::getStoreConfig('zendesk/general/domain');
$root = ($format === 'old') ? '' : '/agent/#';
$root = ($format === 'old') ? '' : '/agent';

$base = $protocol . $domain . $root;
$hc = $protocol . $domain . '/hc';

switch($object) {
case '':
Expand All @@ -42,6 +43,10 @@ public function getUrl($object = '', $id = null, $format = 'old')
case 'raw':
return $protocol . $domain . '/' . $id;
break;

case 'request':
return $hc . '/requests/' . $id;
break;
}
}

Expand Down Expand Up @@ -280,9 +285,17 @@ public function isExternalIdEnabled()
}

public function getTicketUrl($row, $link = false)
{
{
if ($this->isAdmin()) {
$path = 'adminhtml/zendesk/login';
$object = 'ticket';
} else {
$path = '*/sso/login';
$object = 'request';
}
$path = Mage::getSingleton('admin/session')->getUser() ? 'adminhtml/zendesk/login' : '*/sso/login';
$url = Mage::helper('adminhtml')->getUrl($path, array("return_url" => Mage::helper('core')->urlEncode(Mage::helper('zendesk')->getUrl('ticket', $row['id']))));

$url = Mage::helper('adminhtml')->getUrl($path, array("return_url" => Mage::helper('core')->urlEncode(Mage::helper('zendesk')->getUrl($object, $row['id']))));

if ($link)
return $url;
Expand All @@ -291,7 +304,7 @@ public function getTicketUrl($row, $link = false)

return '<a href="' . $url . '" target="_blank">' . Mage::helper('core')->escapeHtml($subject) . '</a>';
}

public function getStatusMap()
{
return array(
Expand All @@ -303,6 +316,7 @@ public function getStatusMap()
'hold' => 'Hold'
);
}


public function getPriorityMap()
{
Expand Down Expand Up @@ -401,4 +415,17 @@ public function storeDependenciesInCachedRegistry() {
Mage::register('zendesk_groups', $groups);
}
}

/**
* Checks whether the user is in an admin page.
*
* @return boolean
*/
public function isAdmin()
{
return (
Mage::getSingleton('admin/session')->getUser() &&
(Mage::app()->getStore()->isAdmin() || Mage::getDesign()->getArea() == 'adminhtml')
);
}
}