phpci/PHPCI/View/SummaryTable.phtml
2014-12-02 16:26:55 +00:00

103 lines
2.9 KiB
PHTML

<?php
foreach($projects as $project):
$statuses = array();
$successes = 0;
$failures = 0;
$health = '';
$subcls = '';
$cls = '';
$success = null;
$failure = null;
if (count($builds[$project->getId()])) {
// Use the latest build information to determine current status:
$latestBuild = $builds[$project->getId()][0];
switch ($latestBuild->getStatus()) {
case 0:
$cls = 'active';
$status = 'Pending';
break;
case 1:
$cls = 'warning';
$status = 'Running';
break;
case 2:
$cls = 'success';
$status = 'Success';
break;
case 3:
$cls = 'danger';
$status = 'Failed';
break;
}
// Use the last 5 builds to determine project health:
$successes = 0;
$failures = 0;
foreach ($builds[$project->getId()] as $build) {
switch ($build->getStatus()) {
case 0:
$statuses[] = 'pending';
break;
case 1:
$statuses[] = 'running';
break;
case 2:
$successes++;
$statuses[] = 'ok';
$success = is_null($success) && !is_null($build->getFinished()) ? $build->getFinished()->format('M j Y g:ia') : $success;
break;
case 3:
$failures++;
$statuses[] = 'failed';
$failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('M j Y g:ia') : $failure;
break;
}
}
}
if ($failures == 0) {
$health = 'Good';
$subcls = 'success';
} elseif ($failures > $successes) {
$health = 'Bad';
$subcls = 'danger';
} else {
$health = 'Warning';
$subcls = 'warning';
}
?>
<tr class="<?php print $cls; ?>">
<td>
<a href='<?php echo PHPCI_URL ?>project/view/<?php echo $project->getId() ?>'><strong><?php echo htmlspecialchars($project->getTitle()) ?></strong></a>
<br>
Last Success: <?php print is_null($success) ? 'Never' : $success; ?>
<br>
Last Failure: <?php print is_null($failure) ? 'Never' : $failure; ?>
</td>
<td>
<span class='label label-<?php echo $subcls ?>'>
<?php echo $health ?>
</span>
<br>
<?php
foreach ($statuses as $status) {
print '<img alt="'.$status.'" src="' . PHPCI_URL . 'assets/img/icon-build-' . $status . '.png">';
}
?>
</td>
<td><a class="btn btn-default btn-sm" href='<?php echo PHPCI_URL ?>project/build/<?php echo $project->getId(); ?>'>build now &raquo;</a></td>
</tr>
<?php endforeach; ?>