Skip to content

Commit

Permalink
Merge pull request mautic#1674 from escopecz/segments-table-sorting
Browse files Browse the repository at this point in the history
Segments table sorting
  • Loading branch information
dongilbert committed May 2, 2016
2 parents 3b619ea + 139e91c commit 625c229
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/bundles/LeadBundle/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function indexAction($page = 1)
$session->set('mautic.lead.filter', $search);

//do some default filtering
$orderBy = $this->factory->getSession()->get('mautic.lead.orderby', 'l.last_active');
$orderByDir = $this->factory->getSession()->get('mautic.lead.orderbydir', 'DESC');
$orderBy = $session->get('mautic.lead.orderby', 'l.last_active');
$orderByDir = $session->get('mautic.lead.orderbydir', 'DESC');

$filter = array('string' => $search, 'force' => '');
$translator = $this->factory->getTranslator();
Expand Down
33 changes: 24 additions & 9 deletions app/bundles/LeadBundle/Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ListController extends FormController
public function indexAction($page = 1)
{
/** @var ListModel $model */
$model = $this->factory->getModel('lead.list');
$model = $this->factory->getModel('lead.list');
$session = $this->factory->getSession();

//set some permissions
$permissions = $this->factory->getSecurity()->isGranted(array(
Expand All @@ -45,16 +46,28 @@ public function indexAction($page = 1)
return $this->accessDenied();
}

if ($this->request->getMethod() == 'POST') {
$this->setListFilters();
}

//set limits
$limit = $this->factory->getSession()->get('mautic.leadlist.limit', $this->factory->getParameter('default_pagelimit'));
$limit = $session->get('mautic.leadlist.limit', $this->factory->getParameter('default_pagelimit'));
$start = ($page === 1) ? 0 : (($page-1) * $limit);
if ($start < 0) {
$start = 0;
}

$filter = array();
$filter['string'] = $this->request->get('search', $this->factory->getSession()->get('mautic.leadlist.filter', ''));
$this->factory->getSession()->set('mautic.leadlist.filter', $filter['string']);
$search = $this->request->get('search', $session->get('mautic.leadlist.filter', ''));
$session->set('mautic.leadlist.filter', $search);

//do some default filtering
$orderBy = $session->get('mautic.leadlist.orderby', 'l.name');
$orderByDir = $session->get('mautic.leadlist.orderbydir', 'ASC');

$filter = array(
'string' => $search
);

$tmpl = $this->request->isXmlHttpRequest() ? $this->request->get('tmpl', 'index') : 'index';

if (!$permissions['lead:lists:viewother']) {
Expand All @@ -68,7 +81,9 @@ public function indexAction($page = 1)
array(
'start' => $start,
'limit' => $limit,
'filter' => $filter
'filter' => $filter,
'orderBy' => $orderBy,
'orderByDir' => $orderByDir,
));

$count = count($items);
Expand All @@ -80,7 +95,7 @@ public function indexAction($page = 1)
} else {
$lastPage = (ceil($count / $limit)) ?: 1;
}
$this->factory->getSession()->set('mautic.leadlist.page', $lastPage);
$session->set('mautic.leadlist.page', $lastPage);
$returnUrl = $this->generateUrl('mautic_leadlist_index', array('page' => $lastPage));

return $this->postActionRedirect(array(
Expand All @@ -98,7 +113,7 @@ public function indexAction($page = 1)
}

//set what page currently on so that we can return here after form submission/cancellation
$this->factory->getSession()->set('mautic.leadlist.page', $page);
$session->set('mautic.leadlist.page', $page);

$listIds = array_keys($items->getIterator()->getArrayCopy());
$leadCounts = (!empty($listIds)) ? $model->getRepository()->getLeadCount($listIds) : array();
Expand All @@ -112,7 +127,7 @@ public function indexAction($page = 1)
'security' => $this->factory->getSecurity(),
'tmpl' => $tmpl,
'currentUser' => $this->factory->getUser(),
'searchValue' => $filter['string']
'searchValue' => $search
);

return $this->delegateView(array(
Expand Down
23 changes: 20 additions & 3 deletions app/bundles/LeadBundle/Views/List/list.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,27 @@
'checkall' => 'true',
'target' => '#leadListTable'
));

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', array(
'sessionVar' => 'leadlist',
'orderBy' => 'l.name',
'text' => 'mautic.core.name',
'class' => 'col-leadlist-name'
));

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', array(
'sessionVar' => 'leadlist',
'text' => 'mautic.lead.list.thead.leadcount',
'class' => 'visible-md visible-lg col-leadlist-leadcount'
));

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', array(
'sessionVar' => 'leadlist',
'orderBy' => 'l.id',
'text' => 'mautic.core.id',
'class' => 'visible-md visible-lg col-leadlist-id'
));
?>
<th class="col-leadlist-name"><?php echo $view['translator']->trans('mautic.core.name'); ?></th>
<th class="visible-md visible-lg col-leadlist-leadcount"><?php echo $view['translator']->trans('mautic.lead.list.thead.leadcount'); ?></th>
<th class="visible-md visible-lg col-leadlist-id"><?php echo $view['translator']->trans('mautic.core.id'); ?></th>
</tr>
</thead>
<tbody>
Expand Down

0 comments on commit 625c229

Please sign in to comment.