예제 #1
0
파일: Documents.php 프로젝트: arbi/MyCode
 /**
  *
  * @param int $documentId
  * @return boolean
  */
 public function deleteDocument($documentId)
 {
     try {
         $auth = $this->getServiceLocator()->get('library_backoffice_auth');
         if (!$auth->hasRole(Roles::ROLE_PEOPLE_MANAGEMENT) && !$auth->hasRole(Roles::ROLE_PEOPLE_MANAGEMENT_HR)) {
             return false;
         }
         $this->getUserDocumentsDao();
         $documentData = $this->getDocumentsData($documentId);
         if ($documentData === false) {
             $this->gr2err('Cannot find document data for ' . $documentId, ['service' => 'User/Documents']);
             return false;
         }
         if (!empty($documentData->getAttachment())) {
             $filepath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_USER_DOCUMENTS . $documentData->getUserId() . '/' . $documentData->getAttachment();
             if (is_writable($filepath)) {
                 unlink($filepath);
             } else {
                 $this->gr2err("Cannot delete file", ['file' => $filepath]);
             }
         }
         return $this->_userDocumentsDao->delete(['id' => $documentId]);
     } catch (\Exception $e) {
         $this->gr2err($e->getMessage(), ['service' => 'User/Documents']);
         return false;
     }
 }
예제 #2
0
 public function ajaxEditDocumentAction()
 {
     /**
      * @var BackofficeAuthenticationService $auth
      * @var Logger $logger
      * @var \DDD\Domain\User\Document\Documents|bool $documentsDomain
      */
     $auth = $this->getServiceLocator()->get('library_backoffice_auth');
     $documentsDao = new Documents($this->getServiceLocator());
     $logger = $this->getServiceLocator()->get('ActionLogger');
     $request = $this->getRequest();
     $result = ['status' => 'error', 'msg' => TextConstants::SERVER_ERROR];
     try {
         $documentsDao->beginTransaction();
         if (!$auth->hasRole(Roles::ROLE_PEOPLE_MANAGEMENT) && !$auth->hasRole(Roles::ROLE_PEOPLE_MANAGEMENT_HR)) {
             $result['msg'] = TextConstants::USER_DOCUMENT_CANNOT_BE_CREATE;
         } else {
             if ($request->isPost() && $request->isXmlHttpRequest()) {
                 $documentId = $this->params()->fromRoute('id');
                 $documentFile = null;
                 if (!is_null($request->getFiles('fileInfo'))) {
                     $documentFile = $request->getFiles();
                 }
                 $url = $request->getPost('url');
                 $data = ['creatorId' => $auth->getIdentity()->id, 'typeId' => $request->getPost('type_id'), 'file' => $documentFile, 'url' => !empty($url) ? $url : null, 'description' => $request->getPost('description')];
                 /**
                  * @var \DDD\Service\User\Documents $userDocumentsService
                  */
                 $userDocumentsService = $this->getServiceLocator()->get('service_user_documents');
                 $documentDomain = $userDocumentsService->getDocumentsData($documentId);
                 $msg = "{$documentDomain->getType()} document was edited.";
                 $userDocumentsService->addDocument($data, $documentId);
                 $logger->save(Logger::MODULE_USER, $request->getPost('user_id'), Logger::ACTION_USER_DOCUMENT, $msg);
                 $documentsDao->commitTransaction();
                 Helper::setFlashMessage(['success' => TextConstants::SUCCESS_UPDATE]);
                 $result = ['status' => 'success', 'msg' => TextConstants::SUCCESS_UPDATE, 'userId' => $documentDomain->getUserId()];
             }
         }
     } catch (\Exception $ex) {
         $documentsDao->rollbackTransaction();
     }
     return new JsonModel($result);
 }