Getting the date of the last updated element of the complete site

Hi,

with my old modx installation 0.9.6.3 I had an extra called lastUpdate, which gave me a date stamp of the last changed element of my site, regardless from where in the doc tree I called it.

As lastUpdate is not available in modx 3, I tried to get this working via getResources and getDate, but I can’t get it working.

Maybe it’s possible with this snippets, maybe there is another way to achive this - any help would be greatly appreciated.

I post the code of lastUpdate here, maybe it’s easy to adopt?

Kind regards
Andre

// snippet: [[lastUpdate]]
// simply displays the last edited document
// use for site-wide update info like "This website was last updated: ..."
// change echo() to return() if needed
// modify date-format to suit your language/region, see http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format
// http://modxcms.com/forums/index.php/topic,16751.0.html
// tested with MODx v. 0.9.6

// $dbQuery = "SELECT id, pagetitle, FROM_UNIXTIME(editedon, '%d.%m.%Y [%H%:%i:%s]') AS humanDate FROM modx_site_content ORDER BY editedon DESC LIMIT 0,1";
$dbQuery = "SELECT id, pagetitle, FROM_UNIXTIME(editedon, '%d.%m.%Y') AS humanDate FROM modx_site_content ORDER BY editedon DESC LIMIT 0,1";
$result = mysql_query($dbQuery) or die( mysql_error() );

if(mysql_num_rows($result) > 0) {
	while ($row = mysql_fetch_array($result)) {
		extract($row);
		$url = $modx->makeUrl($id, '', '', 'full');
		// echo "Last update: <a href=\"$url\">$pagetitle</a> - $humanDate";
               echo "$humanDate";
	}
}

Try this for your two query lines:

$this->modx->prepare($searchQuery);
$result = $this->modx->query($searchQuery);

This code should work:

$dbQuery = "SELECT id, pagetitle, FROM_UNIXTIME(editedon, '%d.%m.%Y') AS humanDate FROM modx_site_content ORDER BY editedon DESC LIMIT 0,1";
$stmt = $modx->prepare($dbQuery);
if ($stmt && $stmt->execute()) {
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    if ($row) {
        //$url = $modx->makeUrl($row['id'], '', '', 'full');
        return $row['humanDate'];
    }
}
return '';

The second one worked, thans alot guys!

Maybe this could be put as a package in the extras for other users to download and install?

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.