From cc006f124f2e525aba106de7b9cd2aa2475fd4f1 Mon Sep 17 00:00:00 2001 From: Jan Linhart Date: Mon, 2 May 2016 19:54:00 +0200 Subject: [PATCH 1/2] Sorting added to the segments table --- .../LeadBundle/Controller/ListController.php | 33 ++++++++++++++----- .../LeadBundle/Views/List/list.html.php | 23 +++++++++++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/app/bundles/LeadBundle/Controller/ListController.php b/app/bundles/LeadBundle/Controller/ListController.php index d2aa91adcc8..2cde7141ac7 100644 --- a/app/bundles/LeadBundle/Controller/ListController.php +++ b/app/bundles/LeadBundle/Controller/ListController.php @@ -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( @@ -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']) { @@ -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); @@ -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( @@ -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(); @@ -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( diff --git a/app/bundles/LeadBundle/Views/List/list.html.php b/app/bundles/LeadBundle/Views/List/list.html.php index 4bc5c2a75f1..cde2f632502 100644 --- a/app/bundles/LeadBundle/Views/List/list.html.php +++ b/app/bundles/LeadBundle/Views/List/list.html.php @@ -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' + )); ?> - trans('mautic.core.name'); ?> - trans('mautic.lead.list.thead.leadcount'); ?> - trans('mautic.core.id'); ?> From 139e91c269d59169ff18553783a11f56d5cdd9e5 Mon Sep 17 00:00:00 2001 From: Jan Linhart Date: Mon, 2 May 2016 19:54:21 +0200 Subject: [PATCH 2/2] $session var used to make the lines shorter --- app/bundles/LeadBundle/Controller/LeadController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/bundles/LeadBundle/Controller/LeadController.php b/app/bundles/LeadBundle/Controller/LeadController.php index e1de55b02fa..9cedf9d059e 100644 --- a/app/bundles/LeadBundle/Controller/LeadController.php +++ b/app/bundles/LeadBundle/Controller/LeadController.php @@ -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();