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
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ protected function addColumnBasedOnType($index, $title, $filter = false, $sortab
'filter' => $filter,
'index' => $index,
'type' => $this->getColumnType($index),
'users' => $this->getCollection()->users,
);

$renderer = $this->getColumnRenderer($index);

if($renderer !== null) {
$column['renderer'] = $renderer;
}
Expand Down Expand Up @@ -241,5 +242,18 @@ 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected function _prepareColumns() {
'renderer' => 'zendesk/adminhtml_dashboard_tab_tickets_grid_renderer_email',
'index' => 'requester_id',
'sortable' => false,
'users' => $this->getCollection()->users,
));

$this->addColumn('type', array(
Expand All @@ -75,15 +76,6 @@ protected function _prepareColumns() {
'options' => Mage::helper('zendesk')->getStatusMap(),
));

$this->addColumn('priority', array(
'header' => Mage::helper('zendesk')->__('Priority'),
'sortable' => true,
'width' => '100px',
'index' => 'priority',
'type' => 'options',
'options' => Mage::helper('zendesk')->getPriorityMap(),
));

$this->addColumn('created_at', array(
'header' => Mage::helper('zendesk')->__('Requested'),
'sortable' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Zendesk_Zendesk_Block_Adminhtml_Dashboard_Tab_Tickets_Grid_Renderer_Email extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

public function render(Varien_Object $row) {
$users = Mage::registry('zendesk_users');
$users = $this->getColumn()->users;
$value = (int) $row->getData($this->getColumn()->getIndex());

if ($users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
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 = Mage::registry('zendesk_users') ? Mage::registry('zendesk_users') : array();
$users = $this->getColumn()->users;
$value = (int) $row->getData($this->getColumn()->getIndex());

$found = array_filter($users, function($user) use($value) {
return (int) $user['id'] === $value;
});

if( count($found) ) {
$user = array_shift($found);

return $user['name'];
}

return '';
}

Expand Down
10 changes: 0 additions & 10 deletions src/app/code/community/Zendesk/Zendesk/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,6 @@ public function getConnectionStatus() {
public function storeDependenciesInCachedRegistry() {
$cache = Mage::app()->getCache();

if (null == Mage::registry('zendesk_users')) {
if( $cache->load('zendesk_users') === false) {
$users = serialize( Mage::getModel('zendesk/api_users')->all() );
$cache->save($users, 'zendesk_users', array('zendesk', 'zendesk_users'), 300);
}

$users = unserialize( $cache->load('zendesk_users') );
Mage::register('zendesk_users', $users);
}

if (null == Mage::registry('zendesk_groups')) {
if( $cache->load('zendesk_groups') === false) {
$groups = serialize( Mage::getModel('zendesk/api_groups')->all() );
Expand Down
7 changes: 4 additions & 3 deletions src/app/code/community/Zendesk/Zendesk/Model/Api/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ public function get($id, $sideload = false)

public function recent()
{
$response = $this->_call('tickets/recent.json');
$response = $this->_call('tickets/recent.json', array('include' => 'users,groups'));

return $response['tickets'];
}

public function all()
{
$response = $this->_call('tickets.json');
$response = $this->_call('tickets.json', array('include' => 'users,groups'));
return $response['tickets'];
}

public function search($data)
{
return $this->_call('search.json', $data);
$data['include'] = 'users,groups';
return $this->_call('search/incremental', $data);
}

public function forOrder($orderIncrementId)
Expand Down
1 change: 1 addition & 0 deletions src/app/code/community/Zendesk/Zendesk/Model/Api/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function execute($id, array $params = array())
throw new InvalidArgumentException('View ID not provided');
}

$params['include'] = 'users,groups';
$paramsString = count($params) ? '?' . http_build_query($params) : '';

$response = $this->_call('views/' . $id . '/execute.json' . $paramsString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ class Zendesk_Zendesk_Model_Resource_Tickets_Collection extends Varien_Data_Coll
protected $_viewColumns = array();
protected static $_excludedColumns = array('score');

public $users = array();

public function __construct() {
$this->_search = new Zendesk_Zendesk_Model_Search( Zendesk_Zendesk_Model_Search::TYPE_TICKET );
}

public function addFieldToFilter($fieldName, $condition = null) {
if(is_string($condition) OR is_array($condition)) {

$searchFields = array();

switch($fieldName) {
case 'subject':
$searchFields[] = array(
Expand Down Expand Up @@ -82,7 +84,7 @@ public function addFieldToFilter($fieldName, $condition = null) {
case 'created_at':
case 'updated_at':
$fieldName = substr($fieldName, 0, -3);

if( isset($condition['from']) AND Mage::helper('zendesk')->isValidDate($condition['from']) ) {
$value = Mage::helper('zendesk')->getFormatedDataForAPI( $condition['from'] );
$searchFields[] = array(
Expand All @@ -91,7 +93,7 @@ public function addFieldToFilter($fieldName, $condition = null) {
'operator' => '>'
);
}

if( isset($condition['to']) AND Mage::helper('zendesk')->isValidDate($condition['to']) ) {
$value = Mage::helper('zendesk')->getFormatedDataForAPI( $condition['to'] );
$searchFields[] = array(
Expand All @@ -111,14 +113,14 @@ public function addFieldToFilter($fieldName, $condition = null) {

return $this;
}

public function getCollection(array $params = array()) {
$searchQuery = array(
'query' => $this->_search->getString(),
);

$params = array_merge($searchQuery, $params);

$all = Mage::getModel('zendesk/api_tickets')->search($params);

foreach ($all['results'] as $ticket) {
Expand All @@ -127,54 +129,61 @@ public function getCollection(array $params = array()) {
$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']);
$this->_count = $all['count'];

Mage::unregister('zendesk_tickets_all');
Mage::register('zendesk_tickets_all', $all['count']);

return $this;
}

public function getCollectionFromView($viewId, array $params = array()) {
$view = Mage::getModel('zendesk/api_views')->execute($viewId, $params);

if (is_array($view['rows'])) {
foreach ($view['rows'] as $row) {
$ticket = array_merge($row, $row['ticket']);

$this->appendParamsWithoutIdPostfix($ticket, array('requester', 'assignee', 'group'));

$obj = new Varien_Object();
$obj->setData($ticket);
$this->addItem($obj);
}
}


// 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']);
$this->setCurPage($params['page']);
$this->setOrder($params['sort_by'], $params['sort_order']);
$this->_count = $view['count'];

Mage::unregister('zendesk_tickets_view_'.$viewId);
Mage::register('zendesk_tickets_view_'.$viewId, $view['count']);

return $this;
}

protected function appendParamsWithoutIdPostfix(& $item, array $params = array()) {
foreach($params as $param) {
$name = $param . '_id';

if(isset($item[$name])) {
$item[$param] = $item[$name];
}
}
}

public function getColumnsForView() {
$excludedColumns = static::$_excludedColumns;

Expand Down