ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Only allow delete if the date is in the future

stikkimorey 19 Dec, 2018
Hi

I have a form based on the demo articles form, which has an article_delete_link which opens a popup containing {view:article_delete_confirm}

I need the form to show items with a date both future and past, but I need to make sure that only items with dates in the future can be deleted.

Is there a way to do this?

Many thanks
healyhatman 19 Dec, 2018
Instead of using {view:article_delete_link} in your table, use
{fn:delete_switch_php$date=(var:tablename.row.datefield)}{fn:delete_switch}

instead.

Create a delete_switch_php PHP block. Return true or false depending on whether or not $this->get("date") is in the future or not.
Create a delete_switch Switch element. Data source {var:delete_switch_php}.
true:{view:article_delete_link}
false:Whatever you want

This will mean that the delete button only shows up for future articles.

DO NOT COPY+PASTE FROM THE FORUMS.
stikkimorey 29 Dec, 2018
Thanks Healyhatman but I can't get this to work - it removes the delete button from future as well as past items.

The date is called start_date and has model ID of Article so I have created delete_switch_php like this:
$today = date("Y-m-d");
if ($this->get("Article.start_date")>$today){
return true;
} else {
return false;
}
Then I created a delete_switch element with a data provider of {var:delete_switch_php} and these values:
true:{view:article_delete_link}
false:No-delete
In the view I have replaced {view:article_delete_link} with
delete:{fn:delete_switch_php$start_date=(var:read_articles.row.start_date)}{fn:delete_switch}
Even when I have an item where the start_date is in the future.

Can you see from this what I am doing wrong?

Thanks again

Mikki
healyhatman 29 Dec, 2018
read_articles.row.model.start_date
healyhatman 29 Dec, 2018
Also that PHP code is.... Not right. I'm on holidays right now so can't do it for you but you're comparing a date object to a string
stikkimorey 29 Dec, 2018
Thanks again - i should be able to fix it now.
healyhatman 29 Dec, 2018
Answer
$this->get("Article.startdate") is probably wrong as well it should be tableviewname.row.model.field
stikkimorey 10 Jan, 2019
Many thanks healyhatman that worked really well
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com