Version: current

     1 <?php
     2
     3 /*
     4  * To change this template, choose Tools | Templates
     5  * and open the template in the editor.
     6  */
     7
     8 /**
     9  * Description of VideoManager
    10  *
    11  * @author inxo
    12  */
    13 class VideoManager extends FileDataObjectManager {
    14     public $template = "VideoManager";
    15     protected $limitFileTypes = array('flv', 'avi', 'mov', 'mpeg', 'mpg', 'm4a');
    16
    17     public function __construct($controller, $name, $sourceClass, $fileFieldName, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
    18         parent::__construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
    19         if(!class_exists("FileDataObjectManager")) {
    20             die("<strong>Error</strong>: requires the DataObjectManager module.");
    21         }
    22
    23         $this->setGridLabelField('Title');
    24         $this->setAddTitle(_t('VideoManager.Video', 'Video'));
    25         $this->setPopupSize(800, 600);
    26         $this->setBrowseButtonText('');
    27         $this->setParentClass('VideoBankPage');
    28     }
    29
    30     public function EditUploadedForm() {
    31         if(!$this->hasDataObject)
    32             return $this->closePopup();
    33
    34         $childData = $this->getChildDataObj();
    35         $validator = $this->getValidatorFor($childData);
    36         $fields = $this->getFieldsFor($childData);
    37         $fields->removeByName($this->fileFieldName);
    38         $total = 0;
    39         if(isset($_POST['totalsize'])){
    40             $total = $_POST['totalsize'];
    41         }else{
    42             if(isset($_POST['uploaded_files'])){
    43                 $total = sizeof($_POST['uploaded_files']);
    44             }
    45         }
    46         $index = isset($_POST['index']) ? $_POST['index'] + 1 : 1;
    47         $fields->push(new HiddenField('totalsize','',$total));
    48         $fields->push(new HiddenField('index','',$index));
    49         if(isset($_POST['uploaded_files']) && is_array($_POST['uploaded_files'])) {
    50             $remaining_files = $_POST['uploaded_files'];
    51             $current = $remaining_files[0];
    52             $dataObject = DataObject::get_by_id($this->sourceClass(), $current);
    53             $fileObject = $dataObject->obj($this->fileFieldName);
    54             $fields->push(new HiddenField('current','',$current));
    55             unset($remaining_files[0]);
    56             if(!$fields->loaded) {
    57                 foreach($remaining_files as $id)
    58                     $fields->push(new LiteralField("u-$id","<input type='hidden' name='uploaded_files[]' value='$id' />"));
    59                 $first = $fields->First()->Name();
    60                 $fields->insertBefore(new HeaderField("Header",_t('DataObjectManager.EDITINGFILE','Editing file')." $index "._t('DataObjectManager.OF','of')." $total",2), $first);
    61                 $fields->insertBefore($this->getPreviewFieldFor($fileObject), $first);
    62                 $fields->replaceField('PreviewImage', new FileField('PreviewImage', _t('VideoEntry.has_one_PreviewImage')));
    63             }
    64         }
    65
    66         $form = Object::create(
    67                 $this->popupClass,
    68                 $this,
    69                 'EditUploadedForm',
    70                 $fields,
    71                 $validator,
    72                 false,
    73                 $childData
    74         );
    75         $form->setActions(new FieldSet(new FormAction("saveEditUploadedForm", $index == $total ? _t('DataObjectManager.BUTTONFINISH', 'Finish') : _t('DataObjectManager.BUTTONNEXT', 'Next'))));
    76         if(isset($dataObject) && $dataObject)
    77             $form->loadDataFrom($dataObject);
    78         $fields->loaded = true;
    79         return $form;
    80     }
    81 }
    82
    83 ?>
    84

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -