PHP to display a message when a page has been recently updated?

Permalink
Hi, folks.

I currently use a much older version of concrete5 (5.4.2.2) to manage a document library for a network operations center, and one of the features I implemented was a block of PHP code to return a message when a page had been updated within the past two weeks (to call attention to new content).

I used the following code:
$date = Loader::helper(date);
$lastupdated = $page->getCollectionDateLastModified();
$lastupdatedtime = strtotime($page->getCollectionDateLastModified());
$current = $date->getLocalDateTime($systemDateTime = now, $mask = null);
$currenttime = strtotime($date->getLocalDateTime($systemDateTime = now, $mask = null));
$difference = $currenttime-$lastupdatedtime;
if ($difference < 1209600) {
echo 'This document has been recently added or updated. Please familiarize yourself with this procedure.';
}


Now, my manager wants to use concrete5 to build a knowledge base for our entire technical operations department, and we're hoping to use version 5.7.5.2. But it's clear that the code above won't work in 5.7.

I suppose I can use the Page Attribute Display block and just show the last update, but that's not quite the same thing. I've been looking through the 5.7 API, but I'm primarily a technical writer, so I'm not sure what I need to be looking for there.

Any ideas or suggestions?

Thanks.

campbell
 
WillemAnchor replied on at Permalink Best Answer Reply
WillemAnchor
something like:
<?php
   $page = Page::getCurrentPage();
   if (is_object($page)) {
      $lastupdated = $page->getCollectionDateLastModified();
      $lastupdatedtime = strtotime($lastupdated);
      $date = Core::make('date'); // concrete\src\Localization\Service\Date.php
      $current = $date->getLocalDateTime(); // this will do, no params needed
      $currenttime = strtotime($current);
      $difference = $currenttime - $lastupdatedtime;
      echo 'dif: ' . $difference;
   }
?>


getCollectionDateLastModified() is a member of Collection (concrete\src\Page\Collection\Collection.php)
WillemAnchor replied on at Permalink Reply
WillemAnchor
Actually, this still has some deprecated date functions in it.
Maybe have a look at timeSince(), or just php's time()
campbell replied on at Permalink Reply
campbell
Thanks so much, Willem. What you provided worked beautifully, though I will look into those other suggestions you made.

I really appreciate it.
WillemAnchor replied on at Permalink Reply
WillemAnchor
your welcome :D