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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Sortable Enum Value from DataObject


Go to End


4 Posts   1501 Views

Avatar
bunheng

Community Member, 78 Posts

6 July 2011 at 12:19am

Good Evening UncleCheese,

I would like to learn the trick to make the sortable Enum value you did for ImageGallery module. I have two dataobjects

1. ActivityPage - Class
1. Project - DataObject
2. ActivityPhoto - DataObject

Through your kindness advice before, I can bring two DataObject work in one Page. I would like to have sortable Enum like the one you made within ImageGallery module, which allow user to choose ProjectTitle to upload ActivityPhoto.

Thanks in advance for your advice.

Bunheng

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 July 2011 at 9:11am

What is a sortable enum value?

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
bunheng

Community Member, 78 Posts

9 July 2011 at 10:46pm

Edited: 10/07/2011 9:48pm

Hi UncleCheese,

The thing is I have two DataObject which already bring to CMS and has many is the relationship beftween those dataobject.

- Project
- ActivityPhoto

I would like to know the trick how to create filter which allow user to select Project Code from Project DataObject before inserting new record for ActivityPhoto. http://www.cambodia-wildlife-adventures.org/filter.jpg

Once again, thanks for your advice and contribution.

Bunheng

Update
Now i can bring up the filter but it doesn't work properly.


<?php

class Activity extends Page {

    static $icon = "activities/images/activity";
    static $db = array(
    );
    static $has_many = array(
        'ActivityPhotos' => 'ActivityPhoto',
        'Projects' => 'Project'
    );

    function getCMSFields() {

        $fields = parent::getCMSFields();
        $manager = new ImageDataObjectManager(
                        $this,
                        'ActivityPhotos',
                        'ActivityPhoto',
                        'Photo',
                        array('Title' => 'Title'),
                        'getCMSFields_forPopup'
        );

        $manager->setFilter('ProjectID', 'Choose Project Code', $this->Projects()->toDropdownMap('ID', 'Code'));
        $items = new DataObjectManager(
                        $this,
                        'Projects',
                        'Project'
        );
        $fields->addFieldsToTab("Root.Content.Projects", $items);
        $fields->addFieldToTab("Root.Content.Activity", $manager);
        $fields->removeFieldFromTab("Root.Content", 'Photo');

        if ($this->Projects()->Count() > 0)
            $this->ActivityPhotos()->filter = "ProjectID_" . $this->Projects()->First()->ID;
        $manager->setAddTitle("Photos to " . $this->CurrentProjectCode());
        $manager->filter_empty_string = false;
        return $fields;
    }

    function getProjectID() {
        return str_replace("ProjectID_", "", $this->ActivityPhotos()->filter);
    }

    function CurrentProjectCode() {
        return DataObject::get_one("Project", $this->getProjectID())->Code;
    }

    

}

class Activity_Controller extends Page_Controller {
    
}

?>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 July 2011 at 6:15am

What do you mean by "it doesn't work properly"?

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com