From c1b0b499cc99cdc9affc21f8602c30a017f7d009 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 22 Mar 2014 10:57:30 -0500 Subject: [PATCH] Initial support for sort by applied status (Ref #21) --- .../com_patchtester/models/pulls.php | 39 +++++++++++++++++-- .../com_patchtester/patchtester.xml | 2 +- .../views/pulls/tmpl/default.php | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_patchtester/models/pulls.php b/administrator/components/com_patchtester/models/pulls.php index a611f1a..978b04c 100644 --- a/administrator/components/com_patchtester/models/pulls.php +++ b/administrator/components/com_patchtester/models/pulls.php @@ -45,10 +45,7 @@ class PatchtesterModelPulls extends JModelList if (empty($config['filter_fields'])) { $config['filter_fields'] = array( - 'id', 'id', - 'title', 'title', - 'updated_at', 'updated_at', - 'user', 'user' + 'id', 'title', 'updated_at', 'user', 'applied' ); } @@ -232,6 +229,7 @@ class PatchtesterModelPulls extends JModelList else { $pulls = $this->github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'), 'open', $page); + $pulls = $this->mergeAppliedData($pulls); usort($pulls, array($this, 'sortItems')); } @@ -304,6 +302,9 @@ class PatchtesterModelPulls extends JModelList case 'title' : return ($this->orderDir == 'asc') ? strcasecmp($a->title, $b->title) : strcasecmp($b->title, $a->title); + case 'applied' : + return ($this->orderDir == 'asc') ? $b->applied > $a->applied : $b->applied < $a->applied; + case 'number' : default : return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number; @@ -328,4 +329,34 @@ class PatchtesterModelPulls extends JModelList return 0; } } + + /** + * Flags pull requests as having been applied in the current environment + * + * @param array $pulls Array of pull data + * + * @return array + * + * @since 2.0 + */ + protected function mergeAppliedData($pulls) + { + // Fetch the applied patches + $appliedData = $this->getAppliedPatches(); + + // Loop through the pulls and add an applied flag + foreach ($pulls as $pull) + { + if (array_key_exists($pull->number, $appliedData)) + { + $pull->applied = 1; + } + else + { + $pull->applied = 0; + } + } + + return $pulls; + } } diff --git a/administrator/components/com_patchtester/patchtester.xml b/administrator/components/com_patchtester/patchtester.xml index 4f21710..22c47c1 100644 --- a/administrator/components/com_patchtester/patchtester.xml +++ b/administrator/components/com_patchtester/patchtester.xml @@ -7,7 +7,7 @@ GNU General Public License version 2 or later admin@joomla.org http://www.joomla.org - 2.0.0.beta + 2.0.0.beta2.dev COM_PATCHTESTER_XML_DESCRIPTION script.php diff --git a/administrator/components/com_patchtester/views/pulls/tmpl/default.php b/administrator/components/com_patchtester/views/pulls/tmpl/default.php index 4074026..d48d7a7 100644 --- a/administrator/components/com_patchtester/views/pulls/tmpl/default.php +++ b/administrator/components/com_patchtester/views/pulls/tmpl/default.php @@ -56,7 +56,7 @@ $listDirn = $this->escape($this->state->get('list.direction')); - +