예제 #1
0
파일: Edit.php 프로젝트: rmaiwald/Reviews
 /**
  * Helper method to process upload fields.
  *
  * @param array  $formData       The form input data.
  * @param object $existingObject Data of existing entity object.
  *
  * @return array form data after processing.
  */
 protected function handleUploads($formData, $existingObject)
 {
     if (!count($this->uploadFields)) {
         return $formData;
     }
     // initialise the upload handler
     $uploadManager = new Reviews_UploadHandler();
     $existingObjectData = $existingObject->toArray();
     $objectId = $this->mode != 'create' ? $this->idValues[0] : 0;
     // process all fields
     foreach ($this->uploadFields as $uploadField => $isMandatory) {
         // check if an existing file must be deleted
         $hasOldFile = !empty($existingObjectData[$uploadField]);
         $hasBeenDeleted = !$hasOldFile;
         if ($this->mode != 'create') {
             if (isset($formData[$uploadField . 'DeleteFile'])) {
                 if ($hasOldFile && $formData[$uploadField . 'DeleteFile'] === true) {
                     // remove upload file (and image thumbnails)
                     $existingObjectData = $uploadManager->deleteUploadFile($this->objectType, $existingObjectData, $uploadField, $objectId);
                     if (empty($existingObjectData[$uploadField])) {
                         $existingObject[$uploadField] = '';
                         $existingObject[$uploadField . 'Meta'] = array();
                     }
                 }
                 unset($formData[$uploadField . 'DeleteFile']);
                 $hasBeenDeleted = true;
             }
         }
         // look whether a file has been provided
         if (!$formData[$uploadField] || $formData[$uploadField]['size'] == 0) {
             // no file has been uploaded
             unset($formData[$uploadField]);
             // skip to next one
             continue;
         }
         if ($hasOldFile && $hasBeenDeleted !== true && $this->mode != 'create') {
             // remove old upload file (and image thumbnails)
             $existingObjectData = $uploadManager->deleteUploadFile($this->objectType, $existingObjectData, $uploadField, $objectId);
             if (empty($existingObjectData[$uploadField])) {
                 $existingObject[$uploadField] = '';
                 $existingObject[$uploadField . 'Meta'] = array();
             }
         }
         // do the actual upload (includes validation, physical file processing and reading meta data)
         $uploadResult = $uploadManager->performFileUpload($this->objectType, $formData, $uploadField);
         // assign the upload file name
         $formData[$uploadField] = $uploadResult['fileName'];
         // assign the meta data
         $formData[$uploadField . 'Meta'] = $uploadResult['metaData'];
         // if current field is mandatory check if everything has been done
         if ($isMandatory && empty($formData[$uploadField])) {
             // mandatory upload has not been completed successfully
             return false;
         }
         // upload succeeded
     }
     return $formData;
 }
예제 #2
0
파일: Review.php 프로젝트: rmaiwald/Reviews
 /**
  * Post-Process the data after a delete.
  * The event happens after the entity has been deleted.
  * Will be called after the database delete operations.
  *
  * Restrictions:
  *     - no access to entity manager or unit of work apis
  *     - will not be called for a DQL DELETE statement
  *
  * @see Reviews_Entity_Review::postRemoveCallback()
  * @return boolean true if completed successfully else false.
  */
 protected function performPostRemoveCallback()
 {
     // echo 'deleted a record ...';
     $objectId = $this['id'];
     // initialise the upload handler
     $uploadManager = new Reviews_UploadHandler();
     $uploadFields = array('coverUpload');
     foreach ($uploadFields as $uploadField) {
         if (empty($this->{$uploadField})) {
             continue;
         }
         // remove upload file (and image thumbnails)
         $uploadManager->deleteUploadFile('review', $this, $uploadField, $objectId);
     }
     return true;
 }