/**
  * For UF and work with local editors we have special scenario:
  * If user don't have permission for update file,
  * we have to attach new file to entity by posting comment with
  * alternative version.
  */
 protected function processActionCommit()
 {
     $userId = $this->getUser()->getId();
     if ($this->attachedModel->canUpdate($userId)) {
         parent::processActionCommit();
         return;
     }
     $this->checkRequiredFilesParams(array('file'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $userStorage = Driver::getInstance()->getStorageByUserId($userId);
     if (!$userStorage) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
         $this->sendJsonErrorResponse();
     }
     $folder = $userStorage->getFolderForCreatedFiles();
     if (!$folder) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES)));
         $this->sendJsonErrorResponse();
     }
     if (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     //todo fix Cherezov. Ban encoding 1251
     $fileArray = $this->request->getFile('file');
     $fileArray['name'] = $this->file->getName();
     $newFile = $folder->uploadFile($fileArray, array('NAME' => $this->file->getName(), 'CREATED_BY' => $userId), array(), true);
     if (!$newFile) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $valueFileUf = FileUserType::NEW_FILE_PREFIX . $newFile->getId();
     /** @var User $createUser */
     $createUser = User::loadById($userId);
     if (!$createUser) {
         $this->sendJsonErrorResponse();
     }
     $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_M');
     if ($createUser->getPersonalGender() == 'F') {
         $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_F');
     }
     if ($this->attachedModel->getAllowAutoComment()) {
         $this->attachedModel->getConnector()->addComment($userId, array('text' => $text, 'fileId' => $valueFileUf));
     }
     $this->sendJsonSuccessResponse();
 }
Exemplo n.º 2
0
 /**
  * @param AttachedObject $attachedModel
  * @return string
  */
 private function getContextForImage(AttachedObject $attachedModel)
 {
     $context = 'unknown';
     if ($this->request->getQuery('width') == 1024 && $this->request->getQuery('height') == 1024) {
         $context = 'viewer resize';
     } elseif ($this->request->getQuery('width') == 69 && $this->request->getQuery('height') == 69) {
         $context = 'list resize';
     } elseif ($this->request->getQuery('x')) {
         $context = 'inline resize';
     }
     $connector = $attachedModel->getConnector();
     if ($connector instanceof BlogPostConnector) {
         $context .= " (blog {$attachedModel->getEntityId()})";
         return $context;
     } elseif ($connector instanceof CalendarEventConnector) {
         $context .= " (calendar {$attachedModel->getEntityId()})";
         return $context;
     } elseif ($connector instanceof ForumMessageConnector) {
         $context .= " (forum {$attachedModel->getEntityId()})";
         return $context;
     } elseif ($connector instanceof SonetCommentConnector) {
         $context .= " (sonetcomm {$attachedModel->getEntityId()})";
         return $context;
     } elseif ($connector instanceof SonetLogConnector) {
         $context .= " (sonetlog {$attachedModel->getEntityId()})";
         return $context;
     } elseif ($connector instanceof TaskConnector) {
         $context .= " (task {$attachedModel->getEntityId()})";
         return $context;
     } else {
         $context .= " (stub {$attachedModel->getEntityId()})";
         return $context;
     }
 }