33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2025-01-23 07:08:33 +00:00

Initial support for sort by applied status (Ref #21)

This commit is contained in:
Michael Babker 2014-03-22 10:57:30 -05:00
parent b9f440e0fc
commit c1b0b499cc
3 changed files with 37 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -7,7 +7,7 @@
<license>GNU General Public License version 2 or later</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>http://www.joomla.org</authorUrl>
<version>2.0.0.beta</version>
<version>2.0.0.beta2.dev</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<scriptfile>script.php</scriptfile>
<install>

View File

@ -56,7 +56,7 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
</th>
<th width="20%" class="nowrap center">
<?php echo JText::_('JSTATUS'); ?>
<?php echo JHtml::_('grid.sort', 'JSTATUS', 'applied', $listDirn, $listOrder); ?>
</th>
<th width="20%" class="nowrap center">
<?php echo JText::_('COM_PATCHTESTER_TEST_THIS_PATCH'); ?>