Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Expiring a date-based object?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 877 Views
  • Bauer-CTU
    Avatar
    Community Member
    10 Posts

    Expiring a date-based object? Link to this post

    Hi,
    I can't get my head round the following ... I hope someone can help

    I have an Event DataObject as below and want any events that have taken place not to display when I call the events stored in the database. Ideally, I want to automatically delete the event from the database at the end of the day on which it takes place.

    I see the CMS Workflow module has an Expiry method but from what I can gather this only applies to Pages not objects.

    mysite/code/Event.php

    class Event extends DataObject
    {
       static $db = array (
          'EventName' => 'Text',
          'Description' => 'Text',
          'Date' => 'Date',
          'Time' => 'Text',
          'Venue' => 'Text',
          'ContactNumber' => 'Text'
       );
    ...
    ...

    mysite/code/EventPage.php

    class EventPage_Controller extends Page_Controller
    {
       function Event()
       {
          return DataObject::get(
             'Event',
             null,
             'Date ASC',
             null
          );
       }

    Many thanks in advance!

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: Expiring a date-based object? Link to this post

    Hi,

    i guess you can do this by just checking if date has passed in the query which will be generated by silverstripe through the DataObject get method.

    something like:

    return DataObject::get('Event', "Date > NOW()", 'Date DESC');

  • Bauer-CTU
    Avatar
    Community Member
    10 Posts

    Re: Expiring a date-based object? Link to this post

    Thanks bart. It works a treat!
    I think I was over-thinking it and expecting it to be more complicated!

    877 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.