Add WrReportIntermapsValidDays configuration variable.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 59443f94622f838473891a759c1dc5f03a55c6e8..e3d3e77cebb1af064c0bb475f785e6f2540cde33 100644 (file)
@@ -9,6 +9,7 @@
 //     $wgWrReportDeleteMode = 'loggedin'; // 'allow', 'loggedin', 'deny'
 //     $wgWrReportFeedRoot = 'https://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
 //     $wgWrReportEnableIntermaps = true; // show Intermaps sledrun information column
+//     $wgWrReportIntermapsValidDays = 1; // number of days the last check of the Intermaps data may be in the past
 //
 //
 // The following tags are supported:
@@ -775,6 +776,7 @@ class WrReport {
                global $wgWrReportBlackListAll;
                global $wgWrReportBlackListStrangers;
                global $wgWrReportEnableIntermaps;
+               global $wgWrReportIntermapsValidDays;
 
                // Determine, whether the user is allowed to make a new report
                $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
@@ -799,6 +801,7 @@ class WrReport {
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-length')->text());
 
                // Rows
+               $now = new DateTime();
                while ($row = $dbr->fetchObject($res)) {
                        $title = Title::newFromRow($row);
                        $tr = $table->appendElement('tr');
@@ -825,14 +828,17 @@ class WrReport {
                        if ($wgWrReportMode != 'summer' && $wgWrReportEnableIntermaps) {
                                $td = $tr->appendElement('td');
                                if ($row->show_status) {
-                                       if ($row->status == 'open') {
-                                               $msg = wfMessage('wrreport-icon-intermaps-open', $row->last_update)->text();
-                                               $td->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => $msg, 'title' => $msg));
-                                       } elseif ($row->status == 'closed') {
-                                               $msg = wfMessage('wrreport-icon-intermaps-closed', $row->last_update)->text();
-                                               $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => $msg, 'title' => $msg));
-                                       } else {
-                                               $td->appendText($row->status);
+                                       $date_last_check = new DateTime($row->last_check);
+                                       if ($date_last_check->diff($now)->days <= $wgWrReportIntermapsValidDays) {
+                                               if ($row->status == 'open') {
+                                                       $msg = wfMessage('wrreport-icon-intermaps-open', $row->last_update)->text();
+                                                       $td->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => $msg, 'title' => $msg));
+                                               } elseif ($row->status == 'closed') {
+                                                       $msg = wfMessage('wrreport-icon-intermaps-closed', $row->last_update)->text();
+                                                       $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => $msg, 'title' => $msg));
+                                               } else {
+                                                       $td->appendText($row->status);
+                                               }
                                        }
                                }
                        }