Buy Now
Sign in

Only allow delete if the date is in the future

stikkimorey , December 19 2018, 17:23
S
stikkimorey 72
December 19 2018, 17:23 #382313
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 7
December 19 2018, 21:28 #382324
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.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
S
stikkimorey 72
December 29 2018, 15:48 #382456
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
Attachments
cap1.JPG
cap1.JPG
(26.89 KiB)
164 Downloads/Views
healyhatman 7
December 29 2018, 20:22 #382464
read_articles.row.model.start_date
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
healyhatman 7
December 29 2018, 20:26 #382466
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
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
S
stikkimorey 72
December 29 2018, 21:39 #382467
Thanks again - i should be able to fix it now.
healyhatman 7
December 29 2018, 22:27 #382470
 Answer
$this->get("Article.startdate") is probably wrong as well it should be tableviewname.row.model.field
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
S
stikkimorey 72
January 10 2019, 21:02 #382743
Many thanks healyhatman that worked really well