Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Uploadify - multiple file upload

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1540 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Uploadify - multiple file upload Link to this post

    Hello,

    this is primary a question for UncleCheese, but any1 who know the answer would be welcome to give it.

    I have seen the code examples for DOM/Uploadify posted in this thread:
    http://www.silverstripe.org/dataobjectmanager-module-forum/show/7009?start=0
    and it works (I've tried it with a bit of different names for sth, but mainly the same thing). now I would like to be able to attach 2 files to same Dataobject. I've tried doing sth like:

    <?php
    class Resource extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text',
          'Category' => "Enum('Industry, Finance, Education')"
       );
       
       static $has_one = array (
          'Attachment' => 'File',
    'MYFILE' => 'File,
          'ResourcePage' => 'ResourcePage'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description'),
             new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
             new FileIFrameField('Attachment'),
    new FileIFrameField('MYFILE'),
          );
       }
    }
    ?>

    and it doesn't work. I added sth like:

    <?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
    'MYFILE', // Second file name on DataObject
             array(
                'Name' => 'Name',
                'Description' => 'Description',
                'Category' => 'Category'
             ), // Headings
    .....
    and it just gives out errors. Any ideas how to do this? I need 2 separate file uploaded in 2 different categorys in same Dataobject

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify - multiple file upload Link to this post

    Just use a regular DOM.

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Uploadify - multiple file upload Link to this post

    Hey mate, I have tried that, didn't help much - for some reason just changing FileDataObjectManager to DataObjectManager doesn't do much help, if you had sth else in mind plz do tell.

    Then I wanted to use the code you supplied on your website with frontend form for Jop aplication (kinda simmilar to what I want - it has a file and multifile upload thingie and it rly is all i need in the end.
    The files can be found at this location:
    http://www.leftandmain.com/silverstripe-tutorials/2010/08/30/using-uploadify-in-frontend-forms/

    Anyways, long story short, I have placed them in /ss/mycode and .../templates/layout folders as neaded, rebuilt a side (/dev/build) and I can go to admin interface and create a new JobAplicationPage, but then the following error pops up:

    ERROR [Notice]: Undefined index: ManyS3File
    IN POST /ss/admin/getitem?ID=430&ajax=1
    Line 154 in /var/www/ss/sapphire/core/ClassInfo.php

    Source
    ======
    145:    /**
    146:     * @todo Improve documentation
    147:     */
    148:    static function ancestry($class, $onlyWithTables = false) {
    149:       global $_ALL_CLASSES;
    150:
    151:       if(is_object($class)) $class = $class->class;
    152:       else if(!is_string($class)) user_error("Bad class value " . var_export($class, true) . " passed to
    ClassInfo::ancestry()", E_USER_WARNING);
    153:
    * 154:       $items = $_ALL_CLASSES['parents'][$class];
    155:       $items[$class] = $class;
    156:       if($onlyWithTables) foreach($items as $item) {
    157:          if(!DataObject::has_own_table($item)) unset($items[$item]);
    158:       }
    159:       return $items;
    160:    }

    Trace
    =====
    <ul>ClassInfo::ancestry(ManyS3File)
    line 426 of Object.php

    Object::combined_static(ManyS3File,has_one,DataObject)
    line 1334 of DataObject.php

    DataObject->getRemoteJoinField(ManyS3Files,has_many)
    line 1264 of DataObject.php

    DataObject->getComponents(ManyS3Files)

    call_user_func_array(Array,Array)
    line 711 of Object.php

    Object->__call(ManyS3Files,Array)
    line 38 of MultipleFileUploadField.php

    JobApplicationPage->ManyS3Files()
    line 38 of MultipleFileUploadField.php

    MultipleFileUploadField->setValue(,JobApplicationPage)
    line 992 of Form.php

    Form->loadDataFrom(JobApplicationPage)
    line 490 of CMSMain.php

    CMSMain->getEditForm(430)
    line 1039 of LeftAndMain.php

    LeftAndMain->EditForm()
    line 389 of LeftAndMain.php

    LeftAndMain->getitem(SS_HTTPRequest)
    line 193 of Controller.php

    Controller->handleAction(SS_HTTPRequest)
    line 143 of RequestHandler.php

    RequestHandler->handleRequest(SS_HTTPRequest)
    line 147 of Controller.php

    Controller->handleRequest(SS_HTTPRequest)
    line 282 of Director.php

    Director::handleRequest(SS_HTTPRequest,Session)
    line 125 of Director.php

    Director::direct(/admin/getitem)
    line 127 of main.php

    </ul>

    Plz help

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify - multiple file upload Link to this post

    Don't forget that DOM and FDOM have different constructors, so you'll need to remove one argument when going from FDOM to DOM.

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

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Uploadify - multiple file upload Link to this post

    Mate I am probably boring my now, but I don't see the problem, can you fix this for me?
    This is my actual code

    <?php
    class Challenge extends DataObject{

       static $db=array(
          'Naziv' => 'Text',
          'Datum' => 'Date',
          'Opis'=>'Text',
          'Aktivan'=>'Boolean'
       );
       
       static $has_one=array(
          'Izazov'=>'File',
          'Razultati'=>'File',
          'Izazovi' => 'Izazovi',
          'IzazoviArhiva' => 'IzazoviArhiva'
       );
       
       public function getCMSFields_forPopup(){
       
          return new FieldSet(
             new TextField('Naziv','Naziv izazova'),
             new DatePickerField('Datum'),
             new TextField('Opis','Krataki opis'),
             new FileIFrameField('Izazov'),
             new FileIFrameField('Rezultati'),
             new CheckboxField('Aktivan')
          );
       }
    }
    ?>

    <?php
    /**
    * Izazovi page type - sadrzi aktivne izazove
    */

    class Izazovi extends Page {

       static $has_one = array(
          'Photo' => 'Image'
       );
       
       static $allowed_children = array(
          'IzazoviArhiva',
          'Challenge'
       );
       
       static $has_many=array(
          'Challenges'=>'Challenge'
       );

       
       static $db = array(
    'Content' => 'Text'
       );

       public function getCMSFields(){
    $fields = parent::getCMSFields();
        $manager = new DataObjectManager(
             $this, // Controller
             'Challenges', // Source name
             'Challenge', // Source class
             'Izazov', // File name on DataObject
             'Rezultati', // File name on DataObject
             array(
                'Naziv' => 'Naziv',
                'Datum' => 'Datum',
                'Opis' => 'Opis',
                'Aktivan'=> 'Aktivan'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          
    $fields->removeFieldFromTab('Root.Content.Main', 'Content');
        $fields->addFieldToTab("Root.Content.Image", new ImageField('Photo','Slika'));
    $fields->addFieldToTab('Root.Content.Main', new TextareaField('Content', 'Content', 20));
        $fields->addFieldToTab("Root.Content.Izazovi",$manager);
    return $fields;
    }
    }

    class Izazovi_Controller extends Page_Controller {
    ...

    and the error it gives me in /admin/ :

    ERROR [Warning]: Invalid argument supplied for foreach()
    IN POST /ss/admin/getitem?ID=19&ajax=1
    Line 284 in /var/www/ss/dataobject_manager/code/DataObjectManager.php

    Source
    ======
    275:       if(!$this->controller->ID && $this->isNested)
    276:          return $this->renderWith('DataObjectManager_holder');
    277:       return parent::FieldHolder();
    278:    }
    279:
    280:    
    281:    public function Headings()
    282:    {
    283:       $headings = array();
    * 284:       foreach($this->fieldList as $fieldName => $fieldTitle) {
    285:          if(isset($_REQUEST['ctf'][$this->Name()]['sort_dir']))
    286:             $dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'] == "ASC" ? "DESC" : "ASC";
    287:          else
    288:             $dir = "ASC";
    289:          $headings[] = new ArrayData(array(
    290:             "Name" => $fieldName,

    Trace
    =====
    <ul>DataObjectManager->Headings()
    line 369 of ViewableData.php

    ViewableData->obj(Headings,,1)
    line 245 of .cache.dataobject_manager.templates.DataObjectManager.ss

    include(/tmp/silverstripe-cache-var-www-ss/.cache.dataobject_manager.templates.DataObjectManager.ss)
    line 420 of SSViewer.php

    SSViewer->process(DataObjectManager)
    line 342 of ViewableData.php

    ViewableData->renderWith(DataObjectManager)
    line 275 of ComplexTableField.php

    ComplexTableField->FieldHolder()
    line 277 of DataObjectManager.php

    DataObjectManager->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 73 of .cache.sapphire.templates.TabSetFieldHolder.ss

    include(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.TabSetFieldHolder.ss)
    line 420 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 58 of .cache.sapphire.templates.TabSetFieldHolder.ss

    include(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.TabSetFieldHolder.ss)
    line 420 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 77 of .cache.sapphire.templates.Includes.Form.ss

    include(/tmp/silverstripe-cache-var-www-ss/.cache.sapphire.templates.Includes.Form.ss)
    line 420 of SSViewer.php

    SSViewer->process(Form)
    line 342 of ViewableData.php

    ViewableData->renderWith(Array)
    line 1108 of Form.php

    Form->forTemplate()
    line 1135 of Form.php

    Form->formHtmlContent()
    line 391 of LeftAndMain.php

    LeftAndMain->getitem(SS_HTTPRequest)
    line 193 of Controller.php

    Controller->handleAction(SS_HTTPRequest)
    line 143 of RequestHandler.php

    RequestHandler->handleRequest(SS_HTTPRequest)
    line 147 of Controller.php

    Controller->handleRequest(SS_HTTPRequest)
    line 282 of Director.php

    Director::handleRequest(SS_HTTPRequest,Session)
    line 125 of Director.php

    Director::direct(/admin/getitem)
    line 127 of main.php

    </ul>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify - multiple file upload Link to this post

    Look at the API for FDOM versus DOM. This argument does not exist in DOM:

    'Izazov', // File name on DataObject

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Uploadify - multiple file upload Link to this post

    Hey mate, thank you, i figured it out, you helped a lot.
    Btw, how to formulate a <% if $Rezultati %> in .ss file so that if there is a filed uploaded it would show it, if not then nothing?

    I have tried this:

             <% control getChallenges(2) %>
                         
                   <h3>$Naziv</h3>
                   <p class="document_text"><b>Datum:</b> $Datum</p>                      
                   <p class="document_text"><b>Kratki opis:</b> $Opis</p>
                   <p>&nbsp;<a href="$Izazov.URL">Preuzmi izazov</a></p>
                   <% if $Rezultati %>
                      <p>Rezultati izazova:</p>
                      <p>&nbsp;<a href="$Razultati.URL">Rezultati</a></p>
                   <% end_if %>
                   </br>      
             <% end_control %>

    but it doesn't work... I need $Rezultati file to only be shown once it is uploaded, since the Iizazov file is some kind of a challenge, and once the certain amount of time has passes we will announce the ppl who managed to finish it and show resaults in $Rezultati (pdf file) so once that is uploaded for that particular challenge it is supposed to be shown.

    EDIT:

    Been trying with return file_exists($this->Rezultati); in some function but it doesn't work also, always returns bool(false) so I rly don't know how to check if there is a file uploaded or not.

    EDIT2:

    works, had a typo in filename

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify - multiple file upload Link to this post

    Also you don't want the $ in the if statement. Prepending a $ before the variable name will render its output to the template, and that's not what you want.

    <% if MyFile %> not <% if $MyFile %>

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

    1540 Views
Page: 1
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.