Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Automatically moving object from one to another folder after meet the condition

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

Page: 1
Go to End
Author Topic: 407 Views
  • fraxter
    Avatar
    Community Member
    8 Posts

    Automatically moving object from one to another folder after meet the condition Link to this post

    HI Folks,

    Could some one of You help me how to create something like that… I’d like to create a Page Type which would contain tenders (so TenderPage and TenderHolder ). Each tender is valid for some specific period for example 3 weeks after creating… I’d like to create two options.
    1)   Tender would be automatically moved from topical tenders folder to archives folder after exceed of valid time(this time would be set by creating of each tender).
    2)   There should be a possibility to move manually each tender to archives folder by marking of check box in admin panel by editing a tender ( I’d like to add a check box for example under title line which after marking it would move specific tender to archives folder).
    I hope I describe good enough what I’d like to achieve if no don’t hesitate to ask me for details. My mail: pfraszka@gmail.com

    Many thanks for help in advance
    Peter

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Automatically moving object from one to another folder after meet the condition Link to this post

    Have you done the tutorials? That will cover how to add a field to the CMS. You would then have a piece of code that detected to see if that page had selected the checkbox and move it. Your auto moving would need to be setup as a CRON job.

    So first create a function on your TenderPage class - moveToArchive() you'll use this for both

    // this assumes you have a Page Type for your archive,
    class TenderPage extends Page {
    ..
    function moveToArchive() {
    $archive = DataObject::get_one('TenderHolderArchive');

    $this->ParentID = $archive->ID;
    }

    Next, in that same class we can get the tick box working but adding a checkbox to the CMS and detecting the change / calling moveToArchive on onBeforeWrite();

    function getCMSFields() {
    $fields->addFieldToTab('Root.Main.Content', new CheckboxField('Archive'));
    }

    function onBeforeWrite() {
    parent::onBeforeWrite();

    if($this->Archive) $this->moveToArchive();
    }

  • fraxter
    Avatar
    Community Member
    8 Posts

    Re: Automatically moving object from one to another folder after meet the condition Link to this post

    Hi Willr,

    Many thanks for Your response. I’ve done as You said and everything is working fine. Thanks again. I have done the tutorials (btw. The tutorials are really good made – well done) only thing which is not totally clear for me according to adding a field to the CMS is how to create a FileTab with FileFields, where could I add attachments (documentation to trender) e.g. some doc. or pdf files and then they would be shown on tender page?
    Partially I made it adding a new tab ‘attachments’ and put over there FileField using uploadify module so that I can browse for files and add it but I don’t know how can I refer to these files to show their on a particular tender page?

    Do u have some idea, how could I do it maybe?

    Many thanks for help in advance
    Peter

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Automatically moving object from one to another folder after meet the condition Link to this post

    What you're creating is a relationship between 2 objects. 'File' which is the name of your assets and your 'TenderPage'. If you've done the tutorial 5 you would have been introduced to has_many, has_one etc. The uploadify module has an example of has_many images being added to a page (http://ss2doc-v2.ernie.silverstripe.com/old/uploadify#usage).

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