phpci/PHPCI/View/SummaryTable.phtml

119 lines
3.8 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 = 'green';
} elseif ($successes == 0) {
$health = 'Bad';
$subcls = 'red';
} else {
$health = 'Warning';
$subcls = 'yellow';
}
?>
<div class="small-box bg-<?php print $subcls; ?>">
<div class="inner">
<h3>
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $project->getId(); ?>">
<?php print $project->getTitle(); ?>
</a>
</h3>
<p>
<?php if ($failures > 0): ?>
<?php print $failures; ?> out of the last
<?php print count($builds[$project->getId()]); ?> builds have failed.
<?php if (!is_null($successful[$project->getId()])): ?>
The last successful build was
<?php print $successful[$project->getId()]->getFinished()->format('M j Y'); ?>
<?php else: ?>
This project has never built successfully.
<?php endif; ?>
<?php else: ?>
All of the last <?php print count($builds[$project->getId()]); ?> builds passed.
<?php if (!is_null($failed[$project->getId()])): ?>
The last failed build was
<?php print $failed[$project->getId()]->getFinished()->format('M j Y'); ?>
<?php else: ?>
This project has never failed to build.
<?php endif; ?>
<?php endif; ?>
</p>
</div>
<div class="icon">
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
</div>
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer">
View Project <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
<?php endforeach; ?>