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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

New Feature: Audio and Video


Go to End


150 Posts   38453 Views

Avatar
Roelfsche

25 Posts

15 May 2009 at 12:21am

Edited: 15/05/2009 12:45am

Hi Uncle Cheese,

this looks really great. thank you for your work.

while using i get the following error:

"[User Error] Object::__call() Method 'forTemplate' not found in class 'File'"

this happens, if i use the variable $Attachment in my template, which is the object property for my file.

i also miss the .js and .swf-includes in my html-file. i followed your description on http://doc.silverstripe.com/doku.php?id=modules:dataobjectmanager and on youtube.

thank you,
roelfsche

Avatar
UncleCheese

Forum Moderator, 4102 Posts

15 May 2009 at 4:44am

Did you upload an mp3 or FLV?

Avatar
Roelfsche

25 Posts

16 May 2009 at 11:41pm

Edited: 17/05/2009 12:04am

i tried an mp3 file.

my code looks as follows:

class AudioFile extends DataObject  {

  public static $db = array(
    'Name' => 'Text',
    'Beschreibung' => 'Text'
  );
  static $has_one = array(
    'Attachment' => 'File',
    'AudioSeite' => 'AudioPage'
  );
  
function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'Name', 'Titelname' ) );
      $fields->push( new TextField( 'Beschreibung', 'Beschreibung' ) );
      $fields->push( new FileIFrameField( 'Track', 'MP3-File') );
      return $fields;
   }
  
}


class AudioPage extends Page
{
  public static $db = array();
  
  public static $has_one = array();
  static $has_many = array('AudioFiles' => 'AudioFile');
  
  function getCMSFields()
  {
    $fields = parent::getCMSFields();
    
    $manager = new FileDataObjectManager($this, 'AudioFiles', 'AudioFile', 'Attachment', array('Name' => 'Name', 'Beschreibung' => 'Beschreibung'), 'getCMSFields_forPopup'/* new FieldSet(new TextField('Beschreibung', 'Beschreibung'), new FileIFrameField('Track'))*/
        );
    
    $manager->setAllowedFileTypes(array('mp3'));
    $manager->setBrowseButtonText('MP3 Datei hochladen');
    $manager->allowUploadFolderSelection();
     
    $fields->addFieldToTab('Root.Content.Tracks', $manager);
     
    return $fields;
  }

}

the AudioPage.ss (exactly the Layout-snippet) only has the following lines:

<% control AudioFiles %>
<h3>$Name</h3>
<p>$Beschreibung</p>
$Attachment
<% end_control %>

thank you,
roelfsche

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 May 2009 at 12:57pm

Edited: 17/05/2009 12:57pm

Can you check your DB and verify that the file was stored with ClassName "MP3?"

You're on the latest SVN, I assume. I haven't deployed this to the ZIP file download yet.

Avatar
Roelfsche

25 Posts

18 May 2009 at 12:08am

Edited: 18/05/2009 12:26am

hi uncle cheese,

you are right. the reason is the 'ClassName' field in the file table.
if i upload with silverstripe's 'files and folder' functionality the files get as ClassName 'file'. if i upload from your swf-uploader by directly choosing files from my pc the ClassName-field has 'MP3' as value and it works fine.
may be the possibility of choosing existing files in the swf-uploader should filter possible uploaded files by ClassName == 'MP3' to choose for displaying (eg. listening ;-))?
anyway, it's a great functionality.
roelfsche

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 May 2009 at 3:41am

Yeah, I should have mentioned that. That's one reason it's just in SVN right now and not in the official release. I plan to clean all that up. That said, if you do have a page of strictly audio files, just use

$has_many = array ('AudioFiles' => 'MP3');
instead of
$has_many = array ('AudioFiles' => 'File');

That way you're not relying on DOM to sniff out the upgrade. You're doing it manually.

Avatar
Roelfsche

25 Posts

19 May 2009 at 5:15am

that's a good idea.
thank you.
roelfsche

Avatar
micahsheets

Community Member, 165 Posts

20 May 2009 at 12:30pm

Very nice implementation Uncle Cheese. I have it working pretty well. The only issue I have is that the VideoThumnail is not actually generated. I am not sure why. The permissions seem to be right on the assets/uploads folder and SS can put other files in there. Also I wanted to know what developer too /code editor you were using on the video. I am looking for a good one that isn't Dreamweaver.