Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » dataobjectmanager in eventcalendar

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2502 Views
  • not2dumb
    Avatar
    Community Member
    16 Posts

    dataobjectmanager in eventcalendar Link to this post

    hi guys,
    me again.

    i try to add a dataobjectmanager class to a pagetyp which extends the calenderevent class.

    the class:

    <?php

    class MorePic extends DataObject {
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text'
       );
       
       static $has_one = array (
          'Attachment' => 'Image',
          'EventSeite' => 'EventSeite'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description', 'Beschreibung'),
             new FileIFrameField('Attachment', 'Bild')
          );
       }
    }

    ?>

    now my headache:
    in the file Eventseite.php this piece of code makes the dataobjectmanger work in the cms, but they won't show up in the template:

    ...
       static $HasManyDataObjectManager = array (
          'MorePic' => 'MorePic'
       );
    ...

    if i try this,

    ...
       static $has_many = array (
          'MorePic' => 'MorePic'
       );
    ...


    the pictures are correctly displayed on the rendered page, but the access to the cms is impossible, i get the following error-message:

    Fatal error: Class name must be a valid object or a string in D:\xampp\htdocs\tads\event_calendar\code\CalendarEvent.php on line 69

    how do i apply the MorePic class correctly?

    thanx alot, p.

  • UncleCheese
    Avatar
    4085 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    Can you show us your template code? The Eventseite.php code? Looks like you've made a pretty basic error.

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    sure,
    here it is:

    <?php

    class EventSeite extends CalendarEvent {
       static $db = array(
          'Premiere' => 'Date',
          'Urauffuehrung' => 'Date',
          'Stab' => 'HTMLText'
       );
       static $has_one = array(
       );
       static $HasManyDataObjectManager = array (
          'MorePic' => 'MorePic'
       );
    /*   static $has_many = array (
          'MorePic' => 'MorePic'
       );
    */
    static $icon = "themes/tads/images/treeicons/event";
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'MorePic', // Source name
             'MorePic', // Source class
             'Attachment', // File name on DataObject
             array(
             'Name' => 'Name',
             'Description' => 'Description',
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          $manager->setAddTitle('Mehr Szenenbilder');
          $manager->setPluralTitle('Weitere Szenenbilder');
          $manager->setBrowseButtonText('Bilder hochladen (nur JPG)');
          //$manager->allowUploadFolderSelection();
          
          $fields->addFieldToTab("Root.Content.Bilder",$manager);
          $fields->addFieldToTab("Root.Content.Main", new CalendarDateField('Premiere'), 'Content');
          $fields->addFieldToTab("Root.Content.Main", new CalendarDateField('Urauffuehrung'), 'Content');
          $fields->addFieldToTab("Root.Content.Main", new HtmlEditorField('Stab'), 'Content');
          return $fields;
       }
    }

    class EventSeite_Controller extends CalendarEvent_Controller {
       
    }
    ?>

    the two date fields are for statistic reasons only

    thanx, p.

  • UncleCheese
    Avatar
    4085 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    You need to spec a datetime class in your CalendarEvent subclass

    $has_many = array ('Dates' => 'MyDateTimeClass');

    This should be improved to fall back on CalendarDateTime if none is specified.

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    hi uncle cheese,
    or anyone who can help me.

    i'm trying with little effort to extend the page "workshop" from the event_calender tutorial with a ImageDataObjectManager, to be able to associate more than ONE image to the "workshop".

    to make it clear:
    i try to put many images to one WORKSHOP, not to one DATE of the workshop.

    i hope i put my question here in the right forum, as i think my problem concerns more the dataobjectmanager than the eventcalendar module.

    hope you can help, as i'm more than confused after hours of trying...
    thanx

  • UncleCheese
    Avatar
    4085 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    It would help if you could be a little more descriptive of what isn't working. Have you been through the tutorials on filedataobjectmanager?

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    hi uncle cheese,
    seems yesterday i was a bit too tired to be really clear.

    what i try to do ist the following:
    i have a page extending the Calendar class called EventAlle.php which is the holder for all the EventSeite.php pages extending the CalendarEvent class.
    the EventSeite.php pages have a ImageDataObjectManager to be able to add them more than only one picture.
    this is defined in the MorePic.php that extends the DataObject class.

    the relationship between EventSeite.php and MorePic.php is defined via EventSeiteDateTime.php.

    as far as i got everything right studying the tuts and your posts, this should be ok.
    all this also works very well inside the cms, and the DB entrys also look ok to me.

    the problem is i can't access the pictures from within the templates. i tried nearly every way i could imagine according to the tutorials, but nothing worked out.
    though i'm quite convinced there HAS to be a way, but i'm afraid either i'm blind or my nickname is choosen badly...

    i put the sourcodes here:

    EventAlle.php:

    <?php

    class EventAlle extends Calendar {
       static $db = array(
       );
       static $has_one = array('Chronikbild' => 'Image');

       static $has_many = array ('Vorstellungen' => 'EventSeite');

       static $allowed_children = array('EventSeite');

       static $icon = "themes/tads/images/treeicons/event";

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Content.Standardbild", new ImageField('Chronikbild', 'Standardbild für Chronik'));
          return $fields;
       }

    }

    class EventAlle_Controller extends Calendar_Controller {
       
    }

    ?>

    EventSeite.php:

    <?php

    class EventSeite extends CalendarEvent {
       static $db = array(
          'Premiere' => 'Date',
          'Urauffuehrung' => 'Date',
          'Stab' => 'HTMLText'
       );
       static $has_one = array();

       static $has_many = array('Dates' => 'EventSeiteDateTime');

       static $icon = "themes/tads/images/treeicons/event";
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $manager = new ImageDataObjectManager($this, 'MorePic', 'MorePic', 'Attachment',
             array('Name' => 'Name', 'Description' => 'Description'),
             'getCMSFields_forPopup'
          );
          $manager->setAddTitle('Mehr Szenenbilder');
          $manager->setPluralTitle('Weitere Szenenbilder');
          $manager->setBrowseButtonText('Bilder hochladen (nur JPG)');
          
          $fields->addFieldToTab("Root.Content.Bilder",$manager);
          $fields->addFieldToTab("Root.Content.Main", new CalendarDateField('Premiere'), 'Content');
          $fields->addFieldToTab("Root.Content.Main", new CalendarDateField('Urauffuehrung'), 'Content');
          $fields->addFieldToTab("Root.Content.Main", new HtmlEditorField('Stab'), 'Content');
          return $fields;
       }
    }

    class EventSeite_Controller extends CalendarEvent_Controller {

    }
    ?>

    MorePic.php

    <?php

    class MorePic extends DataObject {
       static $db = array ('Name' => 'Text', 'Description' => 'Text');
       
       static $has_one = array ('Attachment' => 'Image', 'EventSeite' => 'EventSeite');
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description', 'Beschreibung'),
             new FileIFrameField('Attachment', 'Bild')
          );
       }
    }

    ?>

    EventSeiteDateTime.php

    <?php

    class EventSeiteDateTime extends CalendarDateTime
    {
    static $db = array ();

    static $has_one = array ('EventSeite' => 'EventSeite');

    static $has_many = array ('MorePic' => 'MorePic');

    }

    ?>

    by the way, i'm really new to silverstripe and hope i don't embarrass myself by a really stupid mistake i've made. i'm a beginner...

    thanx for your help!
    cheers, p.

  • UncleCheese
    Avatar
    4085 Posts

    Re: dataobjectmanager in eventcalendar Link to this post

    Sorry, it's not going to work. Right now you can't manage DataObject -> DataObject relationships with DataObjectManager. I'm working on implementing a NestedDataObjectManager field which will allow it to work in the popup of another DOM, but it's a lot of work. To be correct, your ImageDOM would have to be in the getCMSFields function of your DateTime class, not your EventClass, because the DateTime class is the one with the has_many relation. Try using a DataObjectManager in a popup window and it completely chokes. You'll have to setup the relationship of Images to an Event, not a Date.

    2502 Views
Page: 1 2
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.