Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Delete entry when date is expired

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 376 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Delete entry when date is expired Link to this post

    Hi,

    I´ve searched everywhere in web, but can´t find an solution.
    I´m using DOM to save dates. Is it possible to delete the entries when the date is expired?
    In php I can simply say: $query_delete_date = "DELETE FROM datetable WHERE date < DATE_SUB(NOW(), INTERVAL 1 DAY)";
    But is there an nice way of writing a function into the DataObject-file?

    Here´s my code from the DataObject:
    <?php
       $fields = singleton('Termin')->summaryFields();
       
       class Termin extends DataObject
       {
    //db fields
    static $db = array (
    'Datum' => 'Date',
          'Text' => 'Text'
    );

    //Relations
    static $has_one = array (
    'Aktuelles' => 'Aktuelles',
          'Author' => 'Member'
    );

    //Fields to show in the DOM table
    static $summary_fields = array(
    'Datum',
    'Text',
    'Author.FirstName',
       //'Datum',
    );

    static $default_sort = "Datum ASC";

    //Fields for the DOM Popup
    public function getCMSFields()
    {
    return new FieldSet(
    new DateField('Datum'),
    new TextareaField('Text')
    );

    }

    function onBeforeWrite(){
             if(!$this->ID){
                $currentMember = Member::currentMember();
                if($currentMember){
                   $this->AuthorID = $currentMember->ID;
                }
             }
             parent::onBeforeWrite();
       }
    }
    ?>

    I hope someone can help me.

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Delete entry when date is expired Link to this post

    I figered out, that I can better use the filter clause in the DOM. So I wanna filter the dates that were older than today's date.

    //Termine
    $terminmanager = new DataObjectManager(
    $this,
    'Termine',
    'Termin',
    $this->Datum < date('Y-m-d')
    );

    But this doesn´t work either. Does someone see the mistake?

    376 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.