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

Extending Blog entry with ImageDataObjectManager


Go to End
Reply


12 Posts   1918 Views

Avatar
wainui

Community Member, 56 Posts

14 September 2010 at 10:46am

Hi I am trying to extend the blog entry and add an image manager... so far I have got this

// in _config
DataObject::add_extension('BlogEntry', 'CustomBlogEntry');

// in CustomBlogEntry.php
<?php

class CustomBlogEntry extends DataObjectDecorator {

function extraStatics() {
   static $has_many = array (
'GalleryResources' => 'GalleryResource'
);
}

public function updateCMSFields(FieldSet &$fields) {

$manager = new ImageDataObjectManager(
         $this->owner, // Controller   
         'GalleryResources', // Source name
         'GalleryResource', // Source class
         'Attachment', // File name on DataObject
         array(
            'Name' => 'Name',
            'Caption' => 'Caption'
            //'Category' => 'Category'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
   
      $manager -> setAddTitle("Gallery Image");
      $manager->setPluralTitle('Gallery Images');
      $manager ->setAllowedFileTypes(array('jpg'));
$manager->setBrowseButtonText("Upload (JPG only)");
   $folder = 'BlogEntryGalleries/';
      $manager->setUploadFolder($folder);
      $fields->addFieldToTab("Root.Content.Gallery Images", $manager);
      
}
}

// and my GalleryResource class
<?php
class GalleryResource extends DataObject
{
   
   static $db = array (
      'Name' => 'Text',
      'Caption' => 'Text'
   );

   static $has_one = array (
      'Attachment' => 'File',
      'BlogEntry' => 'BlogEntry'
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Caption'),
         new FileIFrameField('Attachment')
      );
   }
   
   
   public function Thumbnail()
   {
      return $this->Attachment()->CroppedImage(125,93);
   }
   
   
   public function Large()
   {   
      if($this->Attachment()->getWidth() > $this->Attachment()->getHeight())
      return $this->Attachment()->SetWidth(700);
      else
      return $this->Attachment()->SetHeight(500);
   }
   
}

This work in that I get the datamanger showing and popup works..
problem is I get an error returned from the swfupload... saying server didnt accept file..

the file is getting uploaded...

My debug from swfupload looks like this

SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number: SWFUPLOAD 2.2.0 Alpha 2008-10-17
SWF DEBUG: movieName: SWFUpload_0
SWF DEBUG: Upload URL: http://localhost/hallertau/www/FileDataObjectManager_Controller/handleswfupload
SWF DEBUG: File Types String: *.jpg;*.JPG;
SWF DEBUG: Parsed File Types: jpg,jpg,
SWF DEBUG: File Types Description: (*.jpg;*.JPG;)
SWF DEBUG: File Size Limit: 52428800 bytes
SWF DEBUG: File Upload Limit: 20
SWF DEBUG: File Queue Limit: 20
SWF DEBUG: Post Params:
SWF DEBUG: dataObjectFieldName=GalleryResources
SWF DEBUG: dataObjectClassName=GalleryResource
SWF DEBUG: parentIDName=BlogEntryID
SWF DEBUG: fileClassName=File
SWF DEBUG: hasDataObject=1
SWF DEBUG: fileFieldName=Attachment
SWF DEBUG: OverrideUploadFolder=BlogEntryGalleries/
SWF DEBUG: controllerID=12
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.jpg;*.JPG;
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: Global Post Item: dataObjectFieldName=GalleryResources
SWF DEBUG: Global Post Item: dataObjectClassName=GalleryResource
SWF DEBUG: Global Post Item: parentIDName=BlogEntryID
SWF DEBUG: Global Post Item: fileClassName=File
SWF DEBUG: Global Post Item: hasDataObject=1
SWF DEBUG: Global Post Item: fileFieldName=Attachment
SWF DEBUG: Global Post Item: OverrideUploadFolder=BlogEntryGalleries/
SWF DEBUG: Global Post Item: controllerID=12
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to http://localhost/hallertau/www/FileDataObjectManager_Controller/handleswfupload for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 32768. Total: 46958
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 46958. Total: 46958
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 500.
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
Error Code: -200, File name: home_art1.jpg, File size: 46958, Message: 500

Any ideas why it is not accepting even though it is upladed?

Avatar
UncleCheese

Forum Moderator, 4092 Posts

14 September 2010 at 11:19am

SWFUpload has been sunsetted in favor of Uploadify. I would start there..

http://www.leftandmain.com/silverstripe-modules/2010/08/26/uploadify/

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

Avatar
wainui

Community Member, 56 Posts

14 September 2010 at 11:31am

Thanks. nice site too :)
will check it out.

Avatar
wainui

Community Member, 56 Posts

14 September 2010 at 11:37am

wow.. that was easy... simply downloaded did a dev/build and perfect :)

Avatar
UncleCheese

Forum Moderator, 4092 Posts

14 September 2010 at 12:00pm

Ha! Music to my ears.

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

Avatar
wainui

Community Member, 56 Posts

14 September 2010 at 12:09pm

:)

I havent done much extending before but images showing up in backend.. but cant seem to access in template..

<% if GalleryResources %>
   FOUND IMAGE HERE...
<% else %>

Any ideas... is it related to adding $this-> owner in datamanager?

$manager = new ImageDataObjectManager(
$this->owner,

Mike

Avatar
UncleCheese

Forum Moderator, 4092 Posts

14 September 2010 at 12:43pm

What is "FOUND IMAGE HERE"?

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

Avatar
wainui

Community Member, 56 Posts

14 September 2010 at 12:50pm

just some text to check if it can find a galleryresource! should be $Attachment :)
bu definitely doesnt fire.. not sure why as is attched to page in backend. Dont know where to look kinda stumped.

Go to Top