Simplify project activity page.
Change-Id: Iab7bf327e1b99a65deffc587f977795439e215a9
diff --git a/classes/Review.class.inc b/classes/Review.class.inc
index 60950e3..c2ab12b 100644
--- a/classes/Review.class.inc
+++ b/classes/Review.class.inc
@@ -42,6 +42,23 @@
return self::getOne($sql, $args);
}
+ public static function get($since, $callable) {
+ $sql = "
+ select
+ project, name, date, type, status, url
+ from ProjectReviews
+ where date >= date(':date:')
+ order by date desc";
+
+ $args = array(
+ ':date:' => date('Y-m-d', $since)
+ );
+
+ query('dashboard', $sql, $args, function($row) use (&$callable) {
+ call_user_func($callable, new self($row));
+ });
+ }
+
private static function getOne($sql, $args) {
$review = null;
query('dashboard', $sql, $args, function($row) use (&$review) {
@@ -57,10 +74,22 @@
$this->data = $data;
}
+ public function getProjectId() {
+ return $this->data['project'];
+ }
+
+ public function getName() {
+ return $this->data['name'];
+ }
+
public function getDate() {
return strtotime($this->data['date']);
}
+ public function getStatus() {
+ return $this->data['status'];
+ }
+
public function getUrl() {
return $this->data['url'];
}
diff --git a/content/en_project_activity.php b/content/en_project_activity.php
index 81d217b..72c805d 100644
--- a/content/en_project_activity.php
+++ b/content/en_project_activity.php
@@ -10,7 +10,13 @@
* Christopher Guindon (Eclipse Foundation) - Initial implementation
*******************************************************************************/
?>
-
+<style>
+.project-success {
+ font-weight: bold;
+ background: url(/projects/images/ok.gif) 100% no-repeat;
+ padding-right: 20px;
+}
+</style>
<div class="container">
<div class="row">
<div class="col-sm-16 padding-bottom">
diff --git a/web-parts/activity.php b/web-parts/activity.php
index fa4f556..2babef2 100755
--- a/web-parts/activity.php
+++ b/web-parts/activity.php
@@ -14,31 +14,36 @@
* This script assumes that it is being included by another script. We
* assume that the $App variable has already been defined.
*/
-require_once ($_SERVER ['DOCUMENT_ROOT'] . "/projects/classes/Review.class.php");
-$reviews = getReviews ('complete', strtotime('-1 month'));
-usort($reviews, 'sortReviewsByDate');
+require_once ($_SERVER ['DOCUMENT_ROOT'] . "/projects/classes/Review.class.inc");
+$reviews = array();
+Review::get(strtotime('-2 month'), function($review) use (&$reviews) {
+ if ($review->getDate() > time()) return;
+ if ($review->getStatus() == 'pending') return;
+ $reviews[$review->getDate()][] = $review;
+});
print '<div class="block-box"><h3>Recent Activity</a></h3><div class="content">';
+if (! $reviews) {
+ print '<p>No activity.</p>';
+} else {
+ foreach ( $reviews as $date => $list ) {
+ $when = $App->getFormattedDate ( $date, 'long' );
+ $when = str_replace ( ' ', ' ', $when );
-$lastDate = null;
-/** @var \Review $review */
-foreach ( $reviews as $review ) {
- $date = $App->getFormattedDate ( $review->getDate(), 'long' );
- $date = str_replace ( ' ', ' ', $date );
+ print "<div class=\"\">";
+ print "<span class=\"orange date\">{$when}</span>";
+ print "<ul class=\"list-unstyled reset\">";
- if ($date != $lastDate) {
- if ($lastDate) print '</ul><hr class="reset"/>';
- print "<span class=\"orange date\">$date</span>";
- print '<ul class="list-unstyled reset">';
+ foreach ($list as $review) {
+ $project = Project::getProject($review->getProjectId());
+ print "<li><span class=\"project-{$review->getStatus()}\"><a href=\"{$review->getUrl()}\">{$project->getFormalName()} {$review->getName()}</a></span></li>";
+ }
+
+ print "</ul>";
+ print "<hr class=\"reset\"/>";
+ print "</div>";
}
-
- $lastDate = $date;
-
- print '<li>' . $review->asHtml() . '</li>';
}
-if ($lastDate) print '</ul>';
-
print '<p align="right"><a href="/projects/tools/reviews.php">Show all reviews...</a></p>';
-
print '</div></div>';
diff --git a/web-parts/reviews.php b/web-parts/reviews.php
index 32eb20b..8819f1b 100755
--- a/web-parts/reviews.php
+++ b/web-parts/reviews.php
@@ -14,34 +14,64 @@
* This script assumes that it is being included by another script. We
* assume that the $App variable has already been defined.
*/
-require_once ($_SERVER ['DOCUMENT_ROOT'] . "/projects/classes/Review.class.php");
+require_once ($_SERVER ['DOCUMENT_ROOT'] . "/projects/classes/Review.class.inc");
+require_once ($_SERVER ['DOCUMENT_ROOT'] . "/projects/classes/Project.class.php");
require_once (dirname ( __FILE__ ) . '/../classes/debug.php');
-$reviews = getReviews ( 'upcoming');
-usort($reviews, 'sortReviewsByUpcoming');
+$reviews = array();
+Review::get(strtotime('-2 weeks'), function($review) use (&$reviews) {
+ if ($review->getStatus() == 'pending') return;
+ $reviews[$review->getDate()][] = $review;
+});
+
+uksort($reviews, function($aDate, $bDate) {
+ /**
+ * Compare two Reviews for sorting. The most recently completed
+ * reviews are sorted first, followed by everything else. Within
+ * the groups, everything is sorted by date and then by project id.
+ *
+ * @internal
+ * @param Review $a
+ * @param Review $b
+ * @return -1, 0, 1 if <,==,>
+ */
+ $now = strtotime('now');
+ $lastWeek = strtotime('-1 week');
+
+ $aRecent = ($aDate < $now) && ($aDate > $lastWeek);
+ $bRecent = ($bDate < $now) && ($bDate > $lastWeek);
+
+ if ($aRecent == $bRecent) {
+ if ($aDate < $bDate) return -1;
+ if ($aDate > $bDate) return 1;
+ return 0;
+ }
+ if ($aRecent == 1) return -1;
+ return 1;
+});
print '<div class="block-box"><h3>Upcoming Reviews</a></h3><div class="content">';
if (! $reviews) {
print '<p>There are no reviews scheduled at this time.</p>';
} else {
- $lastDate = null;
- /** @var \Review $review */
- foreach ( $reviews as $review ) {
- $date = $App->getFormattedDate ( $review->getDate(), 'long' );
- $date = str_replace ( ' ', ' ', $date );
-
- if ($date != $lastDate) {
- if ($lastDate) print '</ul><hr class="reset"/>';
- print "<span class=\"orange date\">$date</span>";
- print '<ul class="list-unstyled reset">';
+ foreach ( $reviews as $date => $list ) {
+ $when = $App->getFormattedDate ( $date, 'long' );
+ $when = str_replace ( ' ', ' ', $when );
+
+ print "<div class=\"\">";
+ print "<span class=\"orange date\">{$when}</span>";
+ print "<ul class=\"list-unstyled reset\">";
+
+ foreach ($list as $review) {
+ $project = Project::getProject($review->getProjectId());
+ print "<li><span class=\"project-{$review->getStatus()}\"><a href=\"{$review->getUrl()}\">{$project->getFormalName()} {$review->getName()}</a></span></li>";
}
-
- $lastDate = $date;
-
- print '<li>' . $review->asHtml() . '</li>';
+
+ print "</ul>";
+ print "<hr class=\"reset\"/>";
+ print "</div>";
}
- if ($lastDate) print '</ul>';
}
print '<p align="right"><a href="/projects/tools/reviews.php">Show all reviews...</a></p>';
print '</div></div>';