示例#1
0
 /**
  * Returns the values of the identifier fields of an entity
  *
  * Doctrine must know about this entity, that is, the entity must already
  * be persisted or added to the identity map before. Otherwise an
  * exception is thrown.
  *
  * @param  object $entity  The entity for which to get the identifier
  * @throws FormException   If the entity does not exist in Doctrine's
  *                         identity map
  */
 public function getIdentifierValues($entity)
 {
     if (!$this->unitOfWork->isInIdentityMap($entity)) {
         throw new FormException('Entities passed to the choice field must be managed');
     }
     return $this->unitOfWork->getEntityIdentifier($entity);
 }
 /**
  * @param ClassMetadata $class
  * @param array         $entityData
  * @param string        $revType
  */
 private function saveRevisionEntityData($class, $entityData, $revType)
 {
     $params = array($this->getRevisionId(), $revType);
     $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR);
     foreach ($class->fieldNames as $field) {
         $params[] = $entityData[$field];
         $types[] = $class->fieldMappings[$field]['type'];
     }
     foreach ($class->associationMappings as $field => $assoc) {
         if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             if ($entityData[$field] !== null) {
                 $relatedId = $this->uow->getEntityIdentifier($entityData[$field]);
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
                 if ($entityData[$field] === null) {
                     $params[] = null;
                     $types[] = \PDO::PARAM_STR;
                 } else {
                     $params[] = $relatedId[$targetClass->fieldNames[$targetColumn]];
                     $types[] = $targetClass->getTypeOfColumn($targetColumn);
                 }
             }
         }
     }
     $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types);
 }
 /**
  * Find a single document with the given query and select fields.
  *
  * @param string $documentName The document to find.
  * @param array $query The query criteria.
  * @param array $select The fields to select
  * @return object $document
  */
 public function findOne(array $query = array(), array $select = array())
 {
     $result = $this->_collection->findOne($query, $select);
     if ($result !== null) {
         return $this->_unitOfWork->getOrCreateDocument($this->_documentName, $result);
     }
     return null;
 }
示例#4
0
 /**
  * Vrne array sprememb polj posamezne entitete
  *
  * @param Entity $entity
  * @return array
  */
 protected function getEntityChanges($entity)
 {
     $result = [];
     $changes = $this->uow->getEntityChangeSet($entity);
     foreach ($changes as $field => $change) {
         list($old, $new) = $change;
         if ($this->isEntity($old)) {
             $old = $old ? $old->getId() : $old;
         }
         if ($this->isEntity($new)) {
             $new = $new ? $new->getId() : $new;
         }
         if ($old != $new) {
             $result[$field] = [$old, $new];
         }
     }
     return $result;
 }
示例#5
0
 /**
  * Checks if the instance is managed by the EntityManager.
  * 
  * @param object $entity
  * @return boolean TRUE if this EntityManager currently manages the given entity
  *                 (and has it in the identity map), FALSE otherwise.
  */
 public function contains($entity)
 {
     return $this->_unitOfWork->isInIdentityMap($entity) && !$this->_unitOfWork->isRegisteredRemoved($entity);
 }
示例#6
0
 /**
  * Determines whether an entity instance is managed in this EntityManager.
  *
  * @param object $entity
  * @return boolean TRUE if this EntityManager currently manages the given entity, FALSE otherwise.
  */
 public function contains($entity)
 {
     return $this->_unitOfWork->isScheduledForInsert($entity) || $this->_unitOfWork->isInIdentityMap($entity) && !$this->_unitOfWork->isScheduledForDelete($entity);
 }
示例#7
0
 /**
  * Helper method to initialize a lazy loading proxy or persistent collection.
  *
  * This method is a no-op for other objects
  *
  * @param object $obj
  */
 public function initializeObject($obj)
 {
     $this->unitOfWork->initializeObject($obj);
 }
示例#8
0
 /**
  * {@inheritDoc}
  */
 public function initializeObject($entity)
 {
     $this->unitOfWork->initializeObject($entity);
 }