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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

FileDataObjectManager - question?


Go to End
Reply

30 Posts   4251 Views

Avatar
FireMe!

31 March 2009 at 6:13am Community Member, 74 Posts

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!

Avatar
UncleCheese

31 March 2009 at 7:38am 4085 Posts

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.

Avatar
FireMe!

31 March 2009 at 8:11am Community Member, 74 Posts

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

Thanks in advance

FireMe!

Avatar
UncleCheese

31 March 2009 at 8:26am 4085 Posts

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.

Avatar
FireMe!

31 March 2009 at 9:26am Community Member, 74 Posts

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!

Avatar
UncleCheese

31 March 2009 at 9:34am 4085 Posts

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.

Avatar
FireMe!

31 March 2009 at 9:48am Community Member, 74 Posts

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

Avatar
UncleCheese

31 March 2009 at 9:53am 4085 Posts

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 %>

Go to Top