Show date of last edit?

Permalink 1 user found helpful
Hello all

My existing site shows the date of the last edit at the bottom of some pages (e.g. 'Page last updated on 11/1/2010'). Is it possible to show this automagically in c5? Is it also possible to show the most up-to-date date on the homepage (ie. whenever the last update was made, regardless of which page it was made to)?

Many thanks :)

melat0nin
 
melat0nin replied on at Permalink Reply
melat0nin
I found this function on c5mix.com:

<?php echo $c->getCollectionDatePublic("F j, Y") ?>


and I thought it might reflect the date of the last edit, my reasoning being that once the page is already set as public any edit which are made are therefore immediately public, but that wasn't the case when I experimented (which is fair enough.. just thought I would try it anyway!).

c5 must keep a record of the dates of edits for its versioning system, so is there an easy way to get that info out of the database for display?
melat0nin replied on at Permalink Reply
melat0nin
I've found these on the API reference:

getVersionDateCreated ()


and

getSiteLastEdit ()


but how do I show these? I'd like the first one on every page, and the second one on the homepage.

This doesn't work:

<?php echo $c->getVersionDateCreated(); ?>


Any thoughts would be much appreciated :)
Mnkras replied on at Permalink Reply
Mnkras
here ya go!

Loader::model('page_statistics'); 
echo strftime('%x ' . t('at') . ' %l:%M %p', strtotime(PageStatistics::getSiteLastEdit()));
melat0nin replied on at Permalink Reply
melat0nin
Thanks for the reply, it works great!

Is it possible to format the date string to something more attractive (and British!)? i.e. 14 Jan 2010

Also, can this be applied to show the edit dates of specific pages as well as the whole site?

Thanks :)
melat0nin replied on at Permalink Reply
melat0nin
I've achieved the formatting of the date like this:

<?php                  Loader::model('page_statistics');
echo date("j M Y", strtotime(PageStatistics::getSiteLastEdit()))
?>


which works great.

Any thoughts on how to do this for individual pages?

EDIT: i tried to apply the logic to individual pages using getVersionDateCreated like this:

<?php
                  Loader::model('collection_version');
echo strftime('%x ' . t('at') . ' %l:%M %p', strtotime(CollectionVersion::getVersionDateCreated()));
?>


but that didn't work (it just shows 1 Jan 1970 1200AM.

Any thoughts would be much appreciated :)
melat0nin replied on at Permalink Reply
melat0nin
Any thoughts from those in the know?
ScottC replied on at Permalink Reply
ScottC
This is pretty straightforward.

$cv = $c->getVersionObject(); 
echo date('F jS, Y h:i:s  a',strtotime($cv->getVersionDateCreated()));


check out the date formatting, the key is that you cast a time represented as a string back to a unix timestamp which is the seconds since 1970 or something like that, then the first parameter on date lets you specify the format you want. I am partial to the one I posted above. Hope that helps.
melat0nin replied on at Permalink Reply
melat0nin
Thanks! That works perfectly! :)

Now if there was a decent wiki where little snippets like this could live, this could help other people instead of filling up the forum...
melat0nin replied on at Permalink Reply
melat0nin
Durr the code for the sitewide edit doesn't actually work :(

For the homepage (showing the last edit to the entire site) i have this:

<?php
Loader::model('page_statistics');
echo date("jS F Y", strtotime(PageStatistics::getSiteLastEdit()));
?>


but it's not updating. I just changed a page today (the 19th) but the homepage still shows the 16th :(
ScottC replied on at Permalink Reply
ScottC
hm kinda sucks but you could do this:

$db = Loader::db();

$lastEdit = $db->getOne("SELECT MAX( cDateModified )
FROM Collections");

then use that as your strtotime($lastEdit) in the same way you are looking to use the api.

It is another query but it should cache? Issue is if you edit a page you might get the older cached value though but it might not, haven't tested but the easy query does work.
melat0nin replied on at Permalink Reply
melat0nin
Thanks for the response. That seems kinda messy, tho!

Why doesn't the other code work? It seems that it's there in the API so it should be possible to use it :/
melat0nin replied on at Permalink Reply
melat0nin
Anybody got any thoughts? Will this solution cache, and is it therefore viable?

EDIT: i just added a new page, and the date updated. I wonder if it only updates when new pages are added, rather than when small edits to existing pages are made?
melat0nin replied on at Permalink Reply
melat0nin
Can anyone comment on this? I've just launched the site, but when I edit an existing page the 'Site last edited' date on the homepage doesn't update.

Any help would be much appreciated :)
agedman replied on at Permalink Reply
agedman
What happens if you clear your cache (i.e. Dashboard > Sitewide Settings > Debug > Clear Cache)?
melat0nin replied on at Permalink Reply
melat0nin
Hi there

I actually didn't have the cache enabled, but once I enabled it and cleared it the wrong date was still displaying. Any other thoughts?
melat0nin replied on at Permalink Reply
melat0nin
Can anyone help on this?

I'm using this code:

<?php
            Loader::model('page_statistics');
echo date("jS F Y", strtotime(PageStatistics::getSiteLastEdit()));
?>


but it only updates when a new page is added, not when a new edit is made to any existing pages. Obviously the latter is most common so it makes sense for it to be included in the idea of 'getSiteLastEdit'.

Any help would be much appreciated :)
Steevb replied on at Permalink Reply
Steevb
Old post?

I use this:
Last Update - <?php global $c; $vo=$c->getVersionObject(); print $vo->getVersionDateCreated(); ?>
diorist replied on at Permalink Reply
diorist
Works for me. Tx 55wd!
dexterweb replied on at Permalink Reply
dexterweb
This will do!
<?php
// Load Date Helper
$date = Loader::helper("date");
// You may need to define $c
global $c;
// Get Blocks in Main area
foreach($c->getBlocks('Main') as $b) {
   $bDate[$i] = $b->getBlockDateLastModified();
   $i ++;
}
// Reverse Sort Date Array
rsort( $bDate );
//Echo Date and Time Page last Edited
echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s');
<?
JohntheFish replied on at Permalink Reply
JohntheFish