Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » trying to adapt ressource example to modeladmin

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: 1099 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    trying to adapt ressource example to modeladmin Link to this post

    Hello

    I'm trying to do the following using model admin :

    I have categories who have sub categorie (works) and each works has several file (images) attached to them so it looks like this.

    CATEGORY 1
    Work 1 > multiple file attachment
    Work 2 > multiple file attachment

    To do so I used the example given in the modeladmin wich gives me :

    WorkManager.php

    <?php
    class WorkManager extends ModelAdmin {

    public static $managed_models = array(
    'Work',
    'Category'
    );

    static $url_segment = 'works';
    static $menu_title = 'WorksManager';

    }

    Work.php

    <?php
    class Work extends DataObject {

    static $db = array(
    'Name' => 'Varchar'
    );

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

    static $searchable_fields = array(
    'Name'
    );

    }

    Category.php

    <?php
    class Category extends DataObject {
    static $db = array(
    'Title' => 'Text'
    );
    }
    ?>

    this part works fine and I understand how it works.

    Then I get lost, I had set up in previous project a Ressource page based on some other example :

    Ressource.php

    <?php
    class Resource extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
       );
       
       static $has_one = array (
          'Attachment' => 'File',
          'ResourcePage' => 'ResourcePage'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new FileIFrameField('Attachment')
          );
       }
    }
    ?>

    RessourcePage.php

    <?php
    class ResourcePage extends Page
    {
       static $has_many = array (
          'Resources' => 'Resource'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, /
             'Resources',
             'Resource',
             'Attachment',
             array(
                'Name' => 'Name',
                'Description' => 'Description'
             ),
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
       
          );
          
          
                
          $f->addFieldToTab("Root.Content.Resources", $manager);

          return $f;
       }

    }
    class ResourcePage_Controller extends Page_Controller {

    }

    }

    That also was working fine

    Could anybody show me how to combine those 2 approach.

    Right now I only want to load datas, my next step will be to create a CategoryPage but I'm trying to do this step by step with a simple example.

    Thanks for any help

    T

  • UncleCheese
    Avatar
    4085 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    I'm really confused about what you're trying to do. How to the categories and ResourcePages relate?

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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    Thank for your answer !

    The ressource example was something I used in previous exersise .

    Now I trying to use model admin to deal with datas .

    So I would like to have my Work dataobject to behave like a ressource that hold several uploaded files.

    Is it clearer ?

    I'm very new to this maybe I'm doing it the wrong way

    T

  • UncleCheese
    Avatar
    4085 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    class Work extends DataObject {

    static $db = array(
    'Name' => 'Varchar'
    );

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

    static $has_many = array (
    'UploadedFiles' => 'WorkFile'
    );

    static $searchable_fields = array(
    'Name'
    );

    public function getCMSFields() {
    return new FieldSet (
    new TextField('Name'),
    new MultipleFileUploadField('UploadedFiles','Files')
    );
    }

    WorkFile.php

    class WorkFile extends File {
    static $has_one = array (
    'Work' => 'Work'
    );
    }

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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    Thank you Uncle Fromage

    If you have a bit of time can you tell me if this is the right approach for that type of project.
    I'm getting lost because the more I read things on the forum the more I don't know if it is best to use DOM or modeladmin or both

    In the exemple I'm trying to set up with the modeladmin will the next step (not asking you to do it for me of course;) be :

    Creating a CategoryPage and the template that goes allong ;
    It will display all the categories, their attached works and the images attached to those works

    Is it the right way of doing it ?

    Thank you

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    Hello Uncle Cheese

    I tried to set up your solution but I have now 2 problems and 2 question :

    First the questions :

    1) The work file you created is it there to create the relationship between the work and the attached files ?

    2) Is it possible to add this uploadfilds in an tab like the tab I get for ressource in my ressource page example ?
    I guess it would have something to do with addFieldToTab function

    Now my 2 errors :
    I have lost the dropdown to select a categorie in the work tab :
    Do I have to add a specific fieldd in the fieldset ?

    public function getCMSFields() {
    return new FieldSet (
    new TextField('Name'),
    new MultipleFileUploadField('UploadedFiles','Files')
    );

    The other problem is that once I save the work I have added all the images the little thumbnails turns white this problem is related to my questio about gettin a specific tab for the images attached to the work.
    In fact I noticed taht once uploaded ans saved the image seems to disppear even tough they exist in the upload folder i get :
    No files attached under the upload field

    Hope I'm not to demanding

    Thank you

  • UncleCheese
    Avatar
    4085 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    The code I gave you was just an example. You can set up your FieldSet any way you want, with whatever tabs and fields you need.

    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Files", new MultipleFileUploadField(....

    etc..

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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: trying to adapt ressource example to modeladmin Link to this post

    Hello Uncle cheese

    I tried to add this : new DropdownField('Category'),

    in

    public function getCMSFields() {
    return new FieldSet (
    new TextField('Name'),
    new DropdownField('Category'),
    new MultipleFileUploadField('UploadedFiles','Files')
    );
    }

    But I cant get the caterogry dropdown to show me the categories.

    The weird thing is that if I remove the public function getCMSFields() {} block
    I can see them again in a drop down menu

    I'm a bit lost I don't understand why this block makes them disapear.

    Thanks

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