diff --git a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php index 8871be9f..bb1d7186 100644 --- a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php +++ b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php @@ -171,7 +171,6 @@ protected function addColumnBasedOnType($index, $title, $filter = false, $sortab 'filter' => $filter, 'index' => $index, 'type' => $this->getColumnType($index), - 'users' => $this->getCollection()->users, ); $renderer = $this->getColumnRenderer($index); @@ -242,18 +241,4 @@ public function getGridJavascript() return $js; } - - /** - * Override the parent method so that $this->_prepareCollection() is called first - * - * @return $this - */ - protected function _prepareGrid() - { - $this->_prepareCollection(); - $this->_prepareColumns(); - $this->_prepareMassactionBlock(); - - return $this; - } } diff --git a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/All.php b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/All.php index 1b98dcdc..77a8ce74 100644 --- a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/All.php +++ b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/All.php @@ -52,10 +52,8 @@ protected function _prepareColumns() { $this->addColumn('requester_id', array( 'header' => Mage::helper('zendesk')->__('Email'), 'width' => '60', - 'renderer' => 'zendesk/adminhtml_dashboard_tab_tickets_grid_renderer_email', - 'index' => 'requester_id', + 'index' => 'requester_email', 'sortable' => false, - 'users' => $this->getCollection()->users, )); $this->addColumn('type', array( diff --git a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php deleted file mode 100644 index b339415e..00000000 --- a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/Email.php +++ /dev/null @@ -1,42 +0,0 @@ -getColumn()->users; - $value = (int) $row->getData($this->getColumn()->getIndex()); - - if ($users) { - $found = array_filter($users, function($user) use($value) { - return (int) $user['id'] === $value; - }); - } else { - return ''; - } - - if( count($found) ) { - $user = array_shift($found); - - return $user['email']; - } - - return ''; - } - -} diff --git a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/User.php b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/User.php index 630fdf71..382f0957 100644 --- a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/User.php +++ b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Renderer/User.php @@ -19,7 +19,7 @@ class Zendesk_Zendesk_Block_Adminhtml_Dashboard_Tab_Tickets_Grid_Renderer_User extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { public function render(Varien_Object $row) { - $users = $this->getColumn()->users; + $users = $row->users; $value = (int) $row->getData($this->getColumn()->getIndex()); $found = array_filter($users, function($user) use($value) { diff --git a/src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php b/src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php index 9dfe43ea..19c906e9 100644 --- a/src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php +++ b/src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php @@ -123,15 +123,19 @@ public function getCollection(array $params = array()) { $all = Mage::getModel('zendesk/api_tickets')->search($params); + // Set the users for this collection + $this->users = $all['users']; + + $emails = array_column($this->users, 'email', 'id'); + foreach ($all['results'] as $ticket) { + $ticket['requester_email'] = (isset($emails[$ticket['requester_id']]) ? $emails[$ticket['requester_id']] : ''); + $obj = new Varien_Object(); $obj->setData($ticket); $this->addItem($obj); } - // Set the users for this collection - $this->users = $all['users']; - $this->setPageSize($params['per_page']); $this->setCurPage($params['page']); $this->setOrder($params['sort_by'], $params['sort_order']); @@ -146,9 +150,13 @@ public function getCollection(array $params = array()) { public function getCollectionFromView($viewId, array $params = array()) { $view = Mage::getModel('zendesk/api_views')->execute($viewId, $params); + // Set the users for this collection + $this->users = (isset($view['users'])) ? $view['users'] : array(); + if (is_array($view['rows'])) { foreach ($view['rows'] as $row) { $ticket = array_merge($row, $row['ticket']); + $ticket['users'] = $this->users; $this->appendParamsWithoutIdPostfix($ticket, array('requester', 'assignee', 'group')); @@ -158,9 +166,6 @@ public function getCollectionFromView($viewId, array $params = array()) { } } - // Set the users for this collection - $this->users = (isset($view['users'])) ? $view['users'] : array(); - $this->_viewColumns = $view['columns'] ? $view['columns'] : array(); $this->setPageSize($params['per_page']); diff --git a/src/app/code/community/Zendesk/Zendesk/functions.php b/src/app/code/community/Zendesk/Zendesk/functions.php new file mode 100644 index 00000000..4da1c071 --- /dev/null +++ b/src/app/code/community/Zendesk/Zendesk/functions.php @@ -0,0 +1,116 @@ +