Exemple #1
0
 /**
  * @param \obo\Entity $entity
  * @return bool
  */
 public static function isEntityBasedInRepository(\obo\Entity $entity)
 {
     $primaryPropertyName = $entity->entityInformation()->primaryPropertyName;
     if (!$entity->primaryPropertyValue()) {
         return false;
     }
     return (bool) self::countRecords(self::queryCarrier()->where("AND [{$primaryPropertyName}] = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $entity->primaryPropertyValue()));
 }
Exemple #2
0
 /**
  * @param \obo\Entity $owner
  * @param array $foreignKey
  * @param boolean $autoCreate
  * @return \obo\Entity|null
  */
 public function entityForOwnerForeignKey(\obo\Entity $owner, array $foreignKey, $autoCreate = true)
 {
     if ($owner->primaryPropertyValue() === null) {
         return null;
     }
     $this->owner = $owner;
     $entityClassNameToBeConnected = $this->entityClassNameToBeConnected;
     $entityManagerName = $entityClassNameToBeConnected::entityInformation()->managerName;
     $specification = $entityManagerName::querySpecification();
     if (\count($foreignKey) === 1) {
         $specification->where("{{$foreignKey[0]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $owner->primaryPropertyValue());
     } else {
         $this->ownerNameInProperty = $foreignKey[1];
         $specification->where("{{$foreignKey[0]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER . " AND {{$foreignKey[1]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $owner->primaryPropertyValue(), $owner->entityInformation()->className);
     }
     if ($entity = $entityManagerName::findEntity($specification, false)) {
         return $entity;
     } else {
         return ($autoCreate and $this->autoCreate and !$owner->isDeleted()) ? $entityManagerName::entityFromArray([$foreignKey[0] => $owner]) : null;
     }
 }
 /**
  * @param \obo\Carriers\QueryCarrier $specification
  * @param string $repositoryName
  * @param \obo\Entity $owner
  * @param string $targetEntity
  */
 protected function constructJoinQueryForRelationship(\obo\Carriers\QueryCarrier $specification, $repositoryName, \obo\Entity $owner, $targetEntity)
 {
     $targetEntityPropertyNameForSoftDelete = $targetEntity::entityInformation()->propertyNameForSoftDelete;
     if ($targetEntityPropertyNameForSoftDelete === "") {
         $specification->join("JOIN [{$repositoryName}] ON [{$owner->entityInformation()->repositoryName}] = " . $this->informationForEntity($owner->entityInformation())["columns"][$owner->entityInformation()->informationForPropertyWithName($owner->entityInformation()->primaryPropertyName)->columnName]["placeholder"] . " AND [{$targetEntity::entityInformation()->repositoryName}] = [{$targetEntity::informationForPropertyWithName($targetEntity::entityInformation()->primaryPropertyName)->columnName}]", $owner->primaryPropertyValue());
     } else {
         $softDeleteJoinQuery = "AND [{$targetEntity::entityInformation()->repositoryName}].[{$targetEntity::informationForPropertyWithName($targetEntityPropertyNameForSoftDelete)->columnName}] = %b";
         $specification->join("JOIN [{$repositoryName}] ON [{$owner->entityInformation()->repositoryName}] = " . $this->informationForEntity($owner->entityInformation())["columns"][$owner->entityInformation()->informationForPropertyWithName($owner->entityInformation()->primaryPropertyName)->columnName]["placeholder"] . " AND [{$targetEntity::entityInformation()->repositoryName}] = [{$targetEntity::informationForPropertyWithName($targetEntity::entityInformation()->primaryPropertyName)->columnName}]" . $softDeleteJoinQuery, $owner->primaryPropertyValue(), FALSE);
     }
 }
 /**
  * @param \obo\Entity $entity
  */
 public function removeEntity(\obo\Entity $entity)
 {
     $primaryPropertyValue = $entity->primaryPropertyValue();
     $repositoryName = $entity->entityInformation()->repositoryName;
     unset($this->data[$repositoryName][$primaryPropertyValue]);
 }