Beispiel #1
0
 /**
  * Save entity data
  *
  * @param array $metadataCollection
  * @throws Exception
  */
 public function save(array $metadataCollection)
 {
     if (empty($this->_entityid) && empty($this->_eid)) {
         throw new Exception("Cannot save connection since neither an entityid nor an eid was set");
     }
     $dto = new ConnectionDto();
     $dto->id = $this->_eid;
     $dto->name = $this->_entityid;
     $dto->type = $this->_type;
     $dto->parentRevisionNr = $this->_revisionid;
     $dto->revisionNote = $this->_revisionnote;
     $dto->state = $this->_workflow;
     // Convert expiration date to datetime object
     $expirationDate = $this->_expiration;
     if (!is_null($expirationDate)) {
         $expirationDate = \DateTime::createFromFormat(DateTime::ATOM, $this->_expiration);
     }
     $dto->expirationDate = $expirationDate;
     $dto->metadataUrl = $this->_metadataurl;
     $dto->allowAllEntities = $this->_allowedall == 'yes';
     $dto->arpAttributes = $this->_arpAttributes;
     $dto->manipulationCode = $this->_manipulation;
     $dto->isActive = $this->_active == 'yes';
     $dto->notes = $this->_notes;
     // Build nested metadata collection
     $flatMetadataCollection = array();
     /** @var $metadata Metadata */
     foreach ($metadataCollection as $metadata) {
         $flatMetadataCollection[$metadata->getKey()] = $metadata->getValue();
     }
     $metadataAssembler = new MetadataTreeBuilder();
     $nestedMetadataCollection = $metadataAssembler->build($flatMetadataCollection, new MetadataDefinitionHelper($this->_config), $this->_type);
     $dto->metadata = $nestedMetadataCollection;
     $connection = $this->getConnectionService()->save($dto, true);
     $this->_eid = $connection->getId();
     $this->currentRevision = $connection->getLatestRevision();
     $this->_id = $this->currentRevision->getId();
     $this->_revisionid = $this->currentRevision->getRevisionNr();
     $this->_modified = false;
 }
Beispiel #2
0
 /**
  * Sets latest revision.
  *
  * Adds revision to collection using it's number as key so that the count of revisions does not increase when saving fails
  *
  * @param Revision  $connectionRevision
  */
 private function setLatestRevision(Revision $connectionRevision)
 {
     if (is_null($this->revisions)) {
         $this->revisions = new ArrayCollection();
     }
     $this->revisions[$connectionRevision->getRevisionNr()] = $connectionRevision;
 }