Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FileDataObjectManager - question?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4
Go to End
Author Topic: 4160 Views
  • FireMe!
    Avatar
    Community Member
    74 Posts

    FileDataObjectManager - question? Link to this post

    Hi

    The filedataobjectmanager works really well, But I was just wondering if there was a way that I could have a page with all files pagination and a side navigation. To pages that can filter the files by category.

    eg. a main download page with all files pagination any category.

    and sub pages that filters to specific category pagination.

    I was just wondering if any one could help me, with the best way of doing this>?

    thanks in advance

    FireMe!

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager - question? Link to this post

    Are you talking about something in the CMS or on your website? The FileDataObjectManager is just a CMS interface. You can handle your templates any way you want.

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    Yes on the website, any ideas how i could do a template for that?

    Thanks in advance

    FireMe!

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager - question? Link to this post

    There's a lot of information in the docs about how to paginate a result set. I won't get into all that here. Filtering one is equally easy.

    static $has_many = array ('SomeFileObjects' => 'SomeFileObject');

    function MyFileObjects()
    {
    $filter = Director::urlParam('Action');
    return $filter ? $this->SomeFileObjects("Category = '$filter'") : $this->SomeFileObjects();
    }

    Then you just need to set up links to my-url-segment/myFilePage/some_category.

    Works a little better if you're using IDs, though. Cause otherwise you get into weirdness trying to pass rich text strings into the URL. ugh.

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    I'm sorry but I do not understand what i am meant to do, do i put this code in to ResourcePage.php, and do i have to change SomeFileObject and MyFileObjects i'm really sorry about this i am more a visual designer than coder, have no idea lol.

    Thanks in advance

    FireMe!

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager - question? Link to this post

    Add it to ResourcePage_Controller. You don't need to change the variable names. I was just using an example. If you're using the example code that comes with DataObjectManager, you can replace SomeFileObjects() with Resources(). If you're still having trouble, post your code for ResourcePage.php and I can show you where to add it.

    FYI, you should avoid building sites on the code examples that come with DataObjectManager. I'm going to be taking them out of the module soon, since people have been complaining about injecting new page types into their site tree. If you really need those example files, you can move them to the mysite/code folder.

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    This is my code

    <?php
    class ResourcePage extends Page
    {
       static $has_many = array (
          'Resources' => 'Resource'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'Resources', // Source name
             'Resource', // Source class
             'Attachment', // File name on DataObject
             array(
                'Name' => 'Name',
                'Description' => 'Description',
                'Category' => 'Category'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          
          $manager->setFilter(
             'Category', // Name of field to filter
             'Filter by Category', // Label for filter
             singleton('Resource')->dbObject('Category')->enumValues() // Map for filter (could be $dataObject->toDropdownMap(), e.g.)
          );
          
          // If undefined, all types are allowed. Pass with or without a leading "."      
          $manager->setAllowedFileTypes(array('pdf','doc'));
          
          // Label for the upload button in the popup
          $manager->setBrowseButtonText("Upload (PDF or DOC only)");
          
          // In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
          $manager->setGridLabelField('Name');
          
          // Plural form of the objects being managed. Used on the "Add" button.
          // If left out, this defaults to [MyObjectName]s
          $manager->setPluralTitle('Resources');
                
          $f->addFieldToTab("Root.Content.Resources", $manager);

          return $f;
       }
       
       function MyFileObjects()
       {
          $filter = Director::urlParam('Action');
          return $filter ? $this->Resources("Category = '$filter'") : $this->Resources();
       }

    }

    class ResourcePage_Controller extends Page_Controller
    {

    }
    ?>

    thanks alot fot you help with this

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager - question? Link to this post

    class ResourcePage_Controller extends Page_Controller
    {
    function FilteredResources()
    {
    $filter = Director::urlParam('Action');
    return $filter ? $this->Resources("Category = '$filter'") : $this->Resources();
    }
    }

    Then on your template use <% control FilteredResources %>

    4160 Views
Page: 1 2 3 4
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.