Example #1
0
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Controller action for uploading files.
  * The method allows for only one file to be processed. It will send back
  * either an error obejct to the view or a File_Dto upon successfull
  * processing.
  *
  */
 public function uploadFileAction()
 {
     // first of, extract the file key
     $fileKey = array_pop(array_keys($_FILES));
     /**
      * @see Conjoon_Modules_Groupware_Files_Facade
      */
     require_once 'Conjoon/Modules/Groupware/Files/Facade.php';
     $facade = Conjoon_Modules_Groupware_Files_Facade::getInstance();
     $upload = $facade->generateUploadObject();
     if (!$upload->isValid()) {
         // generate the error message
         $message = $upload->getMessages();
         $messages = array();
         foreach ($message as $m) {
             $messages[] = $m;
         }
         /**
          * @see Conjoon_Error_Factory
          */
         require_once 'Conjoon/Error/Factory.php';
         $error = Conjoon_Error_Factory::createError(implode("\n", $messages), Conjoon_Error::LEVEL_WARNING, Conjoon_Error::INPUT)->getDto();
         $this->view->success = false;
         $this->view->error = $error;
         return;
     }
     $fileDto = $facade->uploadFileToTempFolderForUser($upload, $this->_helper->registryAccess->getUserId());
     if (!$fileDto) {
         /**
          * @see Conjoon_Error_Factory
          */
         require_once 'Conjoon/Error/Factory.php';
         $error = Conjoon_Error_Factory::createError("Sorry, I could not upload this file. Something went wrong", Conjoon_Error::LEVEL_WARNING, Conjoon_Error::INPUT)->getDto();
         $this->view->success = false;
         $this->view->error = $error;
         return;
     }
     // we will silently add the old id to Dto so the client can identify the
     // uploaded record properly
     $fileDto->oldId = $fileKey;
     $fileDto->folderId = $fileDto->groupwareFilesFoldersId;
     unset($fileDto->groupwareFilesFoldersId);
     $this->view->success = true;
     $this->view->files = array($fileDto);
 }