public function toArray()
 {
     return ['code' => $this->code, 'message' => $this->message, 'limit' => $this->limit, 'user' => $this->user->getUsername()];
 }
Ejemplo n.º 2
0
 /**
  * Map the creator and changer to the document.
  *
  * @param Document      $document
  * @param UserInterface $creator
  * @param UserInterface $changer
  */
 private function mapCreatorAndChanger(Document $document, UserInterface $creator = null, UserInterface $changer = null)
 {
     $document->addField($this->factory->createField('changer', $changer ? $changer->getUsername() : null, 'string'));
     $document->addField($this->factory->createField('changer_id', $changer ? $changer->getId() : null, 'string'));
     $document->addField($this->factory->createField('creator', $creator ? $creator->getUsername() : null, 'string'));
     $document->addField($this->factory->createField('creator_id', $creator ? $creator->getId() : null, 'string'));
 }
Ejemplo n.º 3
0
 /**
  * Updates the collaborator with the given connection and user to the entity with the specified identifier.
  *
  * @param ConnectionInterface $conn The connection of the user
  * @param string $type The type of the entity
  * @param mixed $id The id of the entity
  * @param string $connectionId The id of the connection of the user
  * @param UserInterface $user The user being added as collaborator
  */
 private function updateCollaboration(ConnectionInterface $conn, $type, $id, $connectionId, UserInterface $user)
 {
     $entityCollaborationUpdated = false;
     $connectionCollaborationUpdated = false;
     $identifier = $this->getUniqueCollaborationKey($type, $id);
     $userId = $user->getId();
     /** @var Collaboration[] $entityCollaborations */
     $entityCollaborations = $this->collaborationsEntityCache->fetch($identifier) ?: [];
     /** @var Collaboration[] $connectionCollaborations */
     $connectionCollaborations = $this->collaborationsConnectionCache->fetch($connectionId) ?: [];
     if (!array_key_exists($connectionId, $this->connections)) {
         $this->connections[$connectionId] = $conn;
     }
     if (array_key_exists($identifier, $entityCollaborations)) {
         $entityCollaborations[$identifier]->setChanged(time());
         $entityCollaborationUpdated = true;
     }
     if (array_key_exists($connectionId, $connectionCollaborations)) {
         $connectionCollaborations[$connectionId]->setChanged(time());
         $connectionCollaborationUpdated = true;
     }
     $collaboration = new Collaboration($connectionId, $userId, $user->getUsername(), $user->getFullName(), $type, $id);
     if (!$entityCollaborationUpdated) {
         $entityCollaborations[$connectionId] = $collaboration;
     }
     if (!$connectionCollaborationUpdated) {
         $connectionCollaborations[$identifier] = $collaboration;
     }
     $this->collaborationsEntityCache->save($identifier, $entityCollaborations);
     $this->collaborationsConnectionCache->save($connectionId, $connectionCollaborations);
 }