Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

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


Reply

4 Posts   482 Views

Avatar
fraxter

6 September 2012 at 8:30pm Community Member, 8 Posts

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

Avatar
Willr

7 September 2012 at 9:45pm Forum Moderator, 5511 Posts

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();
}

Avatar
fraxter

10 September 2012 at 8:30am Community Member, 8 Posts

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

Avatar
Willr

10 September 2012 at 6:15pm Forum Moderator, 5511 Posts

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