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 grid view filename


Reply

5 Posts   1351 Views

Avatar
richard-ward

12 August 2010 at 4:57am (Last edited: 12 August 2010 4:58am), Community Member, 31 Posts

Hi,

I have got the file data object manager working roughly as I would like it, with the exception of the grid view of my files showing "#5" for example rather than the title of the file? Any ideas why?

Publication

class Publication extends DataObject {
   static $db = array(
      'IssueNumber' => 'Varchar(25)',
      'Date' => 'Date'
   );
   
   static $has_one = array(
      'Document' => 'File',
      'PublicationPage' => 'PublicationPage'
   );

   function getCMSFields_forPopup() {
      $datefield = new DateField('Date');
      $datefield->setConfig('showcalendar', true);
      $datefield->setConfig('showdropdown', true);
      $datefield->setConfig('dateformat', 'dd/MM/YYYY');
   
      return new FieldSet(
         new TextField('IssueNumber'),
         $datefield,
         new FileIFrameField('Document')
      );
   }
}

PublicationPage

class PublicationPage extends Page {
   
   static $has_many = array(
      'Publications' => 'Publication'
   );
   
   static $has_one = array (
      'RootFolder' => 'Folder'
   );
   
   function onBeforeWrite() {
      parent::onBeforeWrite();
      if($this->ID) {
         $this->RootFolder()->Title = $this->Title;
      }
   }   
   
   function onAfterWrite() {
      if($this->ID) {
         $this->checkFolder();
      }
      parent::onAfterWrite();
   }
   
   function onBeforeDelete() {
      parent::onBeforeDelete();
      $this->RootFolder()->delete();
   }
   
   function checkFolder() {
      if(!$this->RootFolderID) {
         $folder = Folder::findOrMake("PublicationPage-" . $this->ID);
         $folder->Title = $this->Title;
         $folder->write();
         
         $this->RootFolderID = $folder->ID;
         $this->write();
      } else {
         $this->RootFolder()->Title = $this->Title;
         $this->RootFolder()->write();
      }
   }
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $manager = new FileDataObjectManager(
         $this,
         'Publications',
         'Publication',
         'Document',
         array(
            'IssueNumber' => 'IssueNumber',
            'Date' => 'Date'),
         'getCMSFields_forPopup'
      );
      $manager->setUploadFolder("PublicationPage-" . $this->ID);
      $manager->setAllowedFileTypes(array ('pdf','doc'));
      
      $fields->addFieldToTab("Root.Content.Publications", $manager);
      return $fields;
   }
}

class PublicationPage_Controller extends Page_Controller {
   public function init() {
      parent::init();
   }
}

Avatar
UncleCheese

12 August 2010 at 5:11am 4085 Posts

$manager->setGridLabelField('IssueNumber');

Avatar
richard-ward

12 August 2010 at 7:03am Community Member, 31 Posts

Thanks for the quick reply!

That worked perfectly for getting the IssueNumber. Now I have decided to use the filename, how would I go about that?

I have tried:

'Document.Title'
'Document()->Title'

And I had tried creating a method in Publication and calling that, but all to no avail!!

Avatar
UncleCheese

12 August 2010 at 8:36am 4085 Posts

It should fall back on the Title field of your File object if there's not grid label defined. Are the numbers you're getting representative of the DataObject ID, or the File ID? Is the Title field of the File stored in the database?

Avatar
richard-ward

12 August 2010 at 9:08am (Last edited: 12 August 2010 9:25am), Community Member, 31 Posts

It is the DataObjectID...

EDIT: Don't worry! I was using some old versions of SS and DOM. Thanks very much!