コード例 #1
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->serviceManager = Bootstrap::getServiceManager();
     $this->document = new Document();
     $this->document->setId(1);
     $this->document->setDocument('This is the document');
     $contentType = new ContentType();
     $contentType->setExtension('.xyz');
     $this->document->setContentType($contentType);
     $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock();
     $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $viewHelperManager = $this->serviceManager->get('viewhelpermanager');
     $viewHelperManager->setService('isAllowed', $authorizeServiceMock);
     $this->documentLink = $this->serviceManager->get('viewhelpermanager')->get('versionDocumentlink');
     $urlViewHelperMock = $this->getMockBuilder(Url::class)->disableOriginalConstructor()->getMock();
     $urlViewHelperMock->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $viewHelperManager->setService('url', $urlViewHelperMock);
 }
コード例 #2
0
 /**
  * Returns true if a document can be merged.
  *
  * @return bool
  */
 public function canBeMerged()
 {
     return $this->document->getContentType()->getExtension() === 'docx' && in_array($this->document->getType()->getType(), $this->canBeMergedTypes);
 }
コード例 #3
0
ファイル: CreateVersion.php プロジェクト: debranova/project
 /**
  * @return Version;
  */
 public function createVersion()
 {
     set_time_limit(0);
     /*
      * Depending on some settings, we are doing different things.
      * a PO or FPP can always be overwritten, so we will throw the previous version away.
      *
      * This will give the impression that the previous version is overwritten, but we actually will
      * create a new version and delete the previous one (only for PO and FPP)
      */
     switch ($this->getVersionType()->getId()) {
         case VersionType::TYPE_PO:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_FPP:
             //FPP == PO == CR
             $previousVersion = $this->getProjectService()->getLatestProjectVersion($this->getVersionType(), null, true);
             if (!is_null($previousVersion)) {
                 $this->getVersionService()->removeEntity($previousVersion);
             }
             break;
         case VersionType::TYPE_CR:
             break;
         case VersionType::TYPE_SR:
             break;
     }
     /*
      * Create the version first
      */
     $version = new Version();
     $version->setProject($this->getProject());
     $version->setVersionType($this->getVersionType());
     $version->setApproved(Version::STATUS_SELECTED);
     $authentication = $this->getServiceLocator()->getServiceLocator()->get('zfcuser_auth_service');
     $version->setContact($authentication->getIdentity());
     $version->setDateStart($this->getProject()->getDateStart());
     $version->setDateEnd($this->getProject()->getDateEnd());
     /*
      * Auto submit always the created version
      */
     switch ($this->getVersionType()->getId()) {
         case VersionType::TYPE_PO:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_FPP:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_CR:
             $version->setDateSubmitted(new \DateTime());
             break;
         case VersionType::TYPE_SR:
             break;
     }
     /*
      * Transfer the documents to the version
      */
     foreach ($this->getVersionDocuments() as $document) {
         /*
          * When the document is if the correct type, we allow to merge it
          */
         try {
             if ($version->getVersionType()->getId() !== VersionType::TYPE_CR && $this->getDocumentService()->setDocument($document)->canBeMerged()) {
                 $mergedVersionDocument = new Document();
                 $mergedVersionDocument->setVersion($version);
                 $mergedVersionDocument->setContentType($document->getContentType());
                 /*
                  * Create the document by referencing to the corresponding plugin
                  */
                 $mergedDocument = $this->getController()->createMergedDocument()->setDocument($document)->createProposal();
                 /*
                  * Determine the type and select the name and document type
                  */
                 switch ($version->getVersionType()->getId()) {
                     case VersionType::TYPE_PO:
                         $mergedVersionDocument->setType($this->getDocumentService()->getDocumentTypeByType(Type::TYPE_NAME_PO_DOCUMENT));
                         $mergedVersionDocument->setDocument('Auto Generated Merged PO');
                         break;
                     case VersionType::TYPE_FPP:
                     case VersionType::TYPE_CR:
                         $mergedVersionDocument->setType($this->getDocumentService()->getDocumentTypeByType(Type::TYPE_NAME_FPP_DOCUMENT));
                         $mergedVersionDocument->setDocument('Auto Generated Merged FPP');
                         break;
                     default:
                         throw new \InvalidArgumentException(sprintf("Documents if this type %s cannot be merged for version %s", $this->getDocumentService()->getDocument()->getType(), $version->getVersionType()));
                         break;
                 }
                 $mergedVersionDocument->setSize(strlen($mergedDocument->getMergedDocument()));
                 /*
                  * Create the object and save it
                  */
                 $mergedVersionDocumentObject = new DocumentObject();
                 $mergedVersionDocumentObject->setObject($mergedDocument->getMergedDocument());
                 $mergedVersionDocumentObject->setDocument($mergedVersionDocument);
                 $this->getVersionService()->newEntity($mergedVersionDocumentObject);
             }
         } catch (\Exception $exception) {
             //Save at least the version because this is now not handled by the new document
             $version = $this->getVersionService()->newEntity($version);
             $logger = $this->getServiceLocator()->getServiceLocator()->get('ZendLog');
             $logger->Error(sprintf("Exception: Merge conflict during version create - documentId %s", $document->getId()));
             $logger->Info(sprintf("Message %s. Trace %s", $exception->getMessage(), $exception->getTraceAsString()));
         }
         /*
          * Save the document finally to avoid confusion with the merged documents which holds references
          * to the used objects
          */
         /*
          * Save the original document here in the version
          */
         $object = $document->getObject()[0]->getObject();
         //Rewind to have the stream back
         rewind($object);
         $versionDocument = new Document();
         $versionDocument->setVersion($version);
         $versionDocument->setDocument($document->getDocument());
         $versionDocument->setType($document->getType());
         $versionDocument->setSize($document->getSize());
         $versionDocument->setContentType($document->getContentType());
         $versionDocumentObject = new DocumentObject();
         $versionDocumentObject->setObject($object);
         $versionDocumentObject->setDocument($versionDocument);
         $this->getVersionService()->newEntity($versionDocumentObject);
     }
     /*
      * Copy the cost and effort in the corresponding effortVersion and costEffort tables
      */
     foreach ($this->getAffiliationService()->findAffiliationByProjectAndWhich($this->getProject()) as $affiliationService) {
         /*
          * Create the affiliationVersion.
          *
          * @var Affiliation
          */
         $affiliation = $affiliationService->getAffiliation();
         $affiliationVersion = new AffiliationVersion();
         $affiliationVersion->setAffiliation($affiliation);
         $affiliationVersion->setContact($affiliation->getContact());
         $affiliationVersion->setVersion($version);
         $affiliationVersion = $this->getAffiliationService()->newEntity($affiliationVersion);
         /*
          * Include the cost
          */
         $costPerAffiliation = $this->getProjectService()->findCostByAffiliation($affiliation);
         foreach ($costPerAffiliation as $cost) {
             $costVersion = new Cost\Version();
             $costVersion->setAffiliationVersion($affiliationVersion);
             $costVersion->setCosts($cost->getCosts());
             $costVersion->setDateStart($cost->getDateStart());
             $costVersion->setDateEnd($cost->getDateEnd());
             $this->getProjectService()->newEntity($costVersion);
         }
         /*
          * Include the effort
          */
         foreach ($this->getProject()->getWorkpackage() as $workpackage) {
             /*
              * Include the cost
              */
             $effortPerAffiliationAndWorkpackage = $this->getProjectService()->findEffortByWorkpackageAndAffiliation($workpackage, $affiliation);
             foreach ($effortPerAffiliationAndWorkpackage as $effort) {
                 $effortVersion = new Effort\Version();
                 $effortVersion->setAffiliationVersion($affiliationVersion);
                 $effortVersion->setWorkpackage($effort->getWorkpackage());
                 $effortVersion->setEffort($effort->getEffort());
                 $effortVersion->setDateStart($effort->getDateStart());
                 $effortVersion->setDateEnd($effort->getDateEnd());
                 $this->getProjectService()->newEntity($effortVersion);
             }
         }
     }
     /*
      * Update the project
      */
     $this->getProject()->setMode(Project::MODE_DEFAULT);
     $this->getProjectService()->updateEntity($this->getProject());
     return $version;
 }