getDBRef() public method

Fetches the document pointed to by a database reference
public getDBRef ( array $ref ) : array
$ref array A database reference.
return array Returns the database document pointed to by the reference.
 public function testGetDBRef()
 {
     for ($i = 0; $i < 50; $i++) {
         $this->object->insert(array('x' => rand()));
     }
     $obj = $this->object->findOne();
     $ref = $this->object->createDBRef($obj);
     $obj2 = $this->object->getDBRef($ref);
     $this->assertNotNull($obj2);
     $this->assertEquals($obj['x'], $obj2['x']);
 }
 /**
  * Sets the active participant arrays on the thread.
  *
  * @see FOS\MessageBundle\Document\Thread::doEnsureActiveParticipantArrays()
  * @param array $thread
  */
 private function createThreadActiveParticipantArrays(array &$thread)
 {
     $activeParticipants = array();
     $activeRecipients = array();
     $activeSenders = array();
     foreach ($thread['participants'] as $participantRef) {
         foreach ($thread['metadata'] as $metadata) {
             if ($participantRef['$id'] == $metadata['participant']['$id'] && $metadata['isDeleted']) {
                 continue 2;
             }
         }
         $participantIsActiveRecipient = $participantIsActiveSender = false;
         foreach ($thread['messages'] as $messageRef) {
             $message = $this->threadCollection->getDBRef($messageRef);
             if (null === $message) {
                 throw new \UnexpectedValueException(sprintf('Message "%s" not found for thread "%s"', $messageRef['$id'], $thread['_id']));
             }
             if (!isset($message['sender']['$id'])) {
                 throw new \UnexpectedValueException(sprintf('Sender reference not found for message "%s"', $messageRef['$id']));
             }
             if ($participantRef['$id'] == $message['sender']['$id']) {
                 $participantIsActiveSender = true;
             } elseif (!$thread['isSpam']) {
                 $participantIsActiveRecipient = true;
             }
             if ($participantIsActiveRecipient && $participantIsActiveSender) {
                 break;
             }
         }
         if ($participantIsActiveSender) {
             $activeSenders[] = (string) $participantRef['$id'];
         }
         if ($participantIsActiveRecipient) {
             $activeRecipients[] = (string) $participantRef['$id'];
         }
         if ($participantIsActiveSender || $participantIsActiveRecipient) {
             $activeParticipants[] = (string) $participantRef['$id'];
         }
     }
     $thread['activeParticipants'] = $activeParticipants;
     $thread['activeRecipients'] = $activeRecipients;
     $thread['activeSenders'] = $activeSenders;
 }
Beispiel #3
0
 /**
  * getDBRef.
  */
 public function getDBRef($ref)
 {
     $this->time->start();
     $return = parent::getDBRef($ref);
     $time = $this->time->stop();
     $this->log(array('type' => 'getDBRef', 'ref' => $ref, 'time' => $time));
     return $return;
 }
Beispiel #4
0
 protected function doGetDBRef(array $reference)
 {
     return $this->mongoCollection->getDBRef($reference);
 }