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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

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


Go to End


4 Posts   1377 Views

Avatar
fraxter

Community Member, 8 Posts

6 September 2012 at 8:30pm

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

Forum Moderator, 5523 Posts

7 September 2012 at 9:45pm

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

Community Member, 8 Posts

10 September 2012 at 8:30am

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

Forum Moderator, 5523 Posts

10 September 2012 at 6:15pm

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