0

I'm trying to display a time stamp of when a module is published. I can display the current time stamp with PHP without problem, but that's not what I want to do. I'm sure this is simple to do I just can't figure it out.

0

Modules, unlike articles, do not have a creation time saved in their database table.

You can see their table structure here: https://docs.joomla.org/Tables/modules

I believe that to achieve what you want would require a bespoke plug-in that saves this additional data. From this question, it appears that the hook for saving modules is onExtensionAfterSave, though the documentation for onExtension events is abysmal.

edit: If you are talking about a bespoke module, rather than core or third party ones, you could possibly use the calendar field type with the default set to NOW and disabled set to true https://docs.joomla.org/Calendar_form_field_type - this would give a creation date, if that is enough.

0

Can be done with a few lines of php, but requires two steps:

  1. Modify your module adding two fields to store timestamp and last status, add this to fieldset section of your module xml

    <field name="laststatus" type="text" readonly="readonly" default="" label="Last Status" description="Last status"/>
    <field name="lastpublishup" type="text" readonly="readonly" default="" label="Last publish up timestamp" description="Last publish Up timestamp"/>
    
  2. Create and install a extension plugin

I've tried to write directly the plugin and use discover feature on extensions but not worked for me. You must write this on your computer, pack and the install the plugin.

First, make a folder and call it publishmodule.

Inside create two files:

publishmodule.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="extension" method="upgrade">
    <name>plg_publishmodule</name>
    <author>your name</author>
    <creationDate>April 2016</creationDate>
    <copyright>your copyright</copyright>
    <license>your license</license>
    <authorEmail>your mail</authorEmail>
    <authorUrl>your url</authorUrl>
    <version>1.0.0</version>
    <description>Record last published timestamp in module params</description>
    <files>
        <filename plugin="publishmodule">publishmodule.php</filename>
    </files>
</extension>

publishmodule.php

<?php
defined('_JEXEC') or die;

class PlgExtensionPublishModule extends JPlugin {

    public function onExtensionBeforeSave($context, $table, $isNew) {
        $tmpparameters = json_decode($table->params);
        if(((int) $tmpparameters->laststatus == 0) && ($table->published == 1)) {
            $tmpparameters->lastpublishup = time();
        }
        $tmpparameters->laststatus = $table->published;
        $table->params = json_encode($tmpparameters);
        return true;
    }

}
?>

Pack the publishmodule folder in a zip file. Upload and install it in your Joomla.

Now, when your module changes published status from 0 to 1, the timestamp is recorded in lastpublishup param, you can use in your module this way:

$lastpublishup = $params->get('lastpublishup',0);

Tested on a Joomla 3.5.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.