예제 #1
0
파일: Rank.php 프로젝트: rmaiwald/MUBoard
 /**
  * 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 MUBoard_Entity_Rank::postRemoveCallback()
  * @return boolean true if completed successfully else false.
  */
 protected function performPostRemoveCallback()
 {
     // echo 'deleted a record ...';
     // initialise the upload handler
     $uploadManager = new MUBoard_UploadHandler();
     $uploadFields = array('uploadImage');
     foreach ($uploadFields as $uploadField) {
         if (empty($this->{$uploadField})) {
             continue;
         }
         // remove upload file (and image thumbnails)
         $uploadManager->deleteUploadFile('rank', $this, $uploadField);
     }
     return true;
 }
예제 #2
0
파일: Edit.php 프로젝트: rmaiwald/MUBoard
 /**
  * Helper method to process upload fields
  */
 protected function handleUploads($formData, $existingObject)
 {
     if (!count($this->uploadFields)) {
         return $formData;
     }
     // initialise the upload handler
     $uploadManager = new MUBoard_UploadHandler();
     $existingObjectData = $existingObject->toArray();
     // 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);
                     if (empty($existingObjectData[$uploadField])) {
                         $existingObject[$uploadField] = '';
                     }
                 }
                 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);
             if (empty($existingObjectData[$uploadField])) {
                 $existingObject[$uploadField] = '';
             }
         }
         // 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 && $formData[$uploadField] === false) {
             // mandatory upload has not been completed successfully
             return false;
         }
         // upload succeeded
     }
     return $formData;
 }