News:

Support for jDownloads 3 has been ended
Since 17 August 2023 Joomla.org has discontinued support for Joomla 3.x. Therefore, we will no longer offer official support for our Joomla 3 jDownloads version 3.9.x from January 2024.
Please update your website to the latest Joomla version (Joomla 4 or Joomla 5) as soon as possible. Afterwards, please update jDownloads to the latest published version. The longer you delay, the more difficult the upgrade process for your website is likely to be.

Main Menu
Support-Forum

Show enddate in frontend

Started by andreasb, 30.07.2015 15:02:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

andreasb

Hi,

I'm working on a few adjustmens for a Website and i've got a problem:

I want to show the enddate of publication in the frontend and I want to change the title color of the file to red if there is less than one week until the date of expiration is reached.
My problem is that i havn't got access to the enddate. Is it possible to get these data?

Thanks!
  •  

ColinM

Hi
Sounds useful idea.
The end date info is stored in the 'publish_to' field of the <prefix>_jdownloads_files table in the database. But there is no easy way to show it with the layouts!

Perhaps a way would be to add a custom field so that the end date is placed in that manually when the download is created, ideally of course it would be added automatically but the core code to do that is not present at this time.  The custom placeholder would then be put into the relevant Files or Details layout.

To become effective you would need to add to the core code to get the resultant date text automatically and to suitably style.  That would mean being careful with updates. But if working code was available I suspect it would not be a challenge to get it agreed to be included in the core.

Please let us know any further thoughts

Colin

Colin M
  •  

andreasb

Thank you for the idea to create a custom field.

I created a custom field for the enddate and a MySQL trigger to copy the value from this custom field to the publish_to field. Now I can show the Enddate in the Frontend.
To change the color to red is more difficult...
  •  

ColinM

Hi
Sounds good.  As a thought I believe you could add JavaScript in a <script>  </script> sequence to your layout.  The script could compare the target date less so many days with the current date and if appropriate switch the class in the relevant html statement, which would need an id.  Maybe

Colin
Colin M
  •  

andreasb

It works. Thanks for your help!
  •  

ColinM

Hi
Would it be possible to post the info & code of what you did so as to help others, and with a view to adding to the core jD code.,  You could either post here or send to me by Private Message.  In the first instance I would think to turn into a user doc, with of course credit to yourself on the technique.

Thanks

Colin
Colin M
  •  

andreasb

#6
First I created two MySQL triggers to update the "publish_to" field when the "custom_field_11" is changed:

INSERT trigger:

SET NEW.publish_to = NEW.custom_field_11


UPDATE trigger:
same code

For both triggers you have to use "BEFORE" as time setting.



To show the enddate and update the color I added a JavaScript code to the layout:


<script type="text/javascript">
                var date= Date.now()/86400000;
                var dt = Date.parse('{custom_value_11}');
                var enddate = dt.getTime() / 86400000;
                var rest= Math.floor(enddate - date);
                var addObj = document.createElement("font");
                if(rest<7){
                       document.getElementById("enddate_{file_id}").style.color = "red";
                } else {
                       document.getElementById("enddate_{file_id}").style.color = "green";
                }
              var recObj = document.getElementById("enddate_{file_id}");
              recObj.appendChild(addObj);
</script>




If you want to add a download you have to use the custom_field_11 to change the enddate.

This is certainly not the nicest way, but it works.
(Sorry, my English is not the best..)
  •