Example #1
0
 /**
  * @return void
  */
 public function loadEntities()
 {
     if (!$this->owner->isBasedInRepository()) {
         return;
     }
     foreach ($this->relationShip->findEntities() as $entity) {
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("beforeConnectToOwner", $entity, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName]);
         $this->setValueForVariableWithName($entity, $entity->primaryPropertyValue());
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("afterConnectToOwner", $entity, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName]);
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity($this->relationShip->ownerPropertyName . "Connected", $this->owner, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName, "addedEntity" => $entity]);
     }
 }
Example #2
0
 /**
  * @param \obo\Entity $entity
  * @return void
  */
 public function insertEntity(\obo\Entity $entity)
 {
     if ($entity->isBasedInRepository()) {
         throw new \obo\Exceptions\Exception("Can't insert entity into storage. Entity is already persisted.");
     }
     $this->dibiConnection->query("INSERT INTO [{$entity->entityInformation()->repositoryName}] ", $this->convertDataForImport($entity->changedProperties($entity->entityInformation()->persistablePropertiesNames, true, true), $entity->entityInformation()));
     if ($autoIncrementProperty = $this->informations[$entity->entityInformation()->className]["autoIncrementProperty"]) {
         $entity->setValueForPropertyWithName($this->dibiConnection->getInsertId(), $autoIncrementProperty);
     }
 }
Example #3
0
File: Many.php Project: Hlavos/obo
 public function add(\obo\Entity $entity)
 {
     if ($this->connectViaPropertyWithName !== "") {
         $entity->setValueForPropertyWithName($this->owner, $this->connectViaPropertyWithName);
         if ($this->ownerNameInProperty !== "") {
             $entity->setValueForPropertyWithName($this->owner->entityInformation()->name, $this->ownerNameInProperty);
         }
         if ($entity->isBasedInRepository() and $this->owner->isBasedInRepository()) {
             $entity->save();
         }
         if (!$this->owner->isBasedInRepository()) {
             \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->registerEvent(new \obo\Services\Events\Event(["onObject" => $this->owner, "name" => "afterInsert", "actionAnonymousFunction" => function () use($entity) {
                 if ($entity->isBasedInRepository()) {
                     $entity->save();
                 }
             }, "actionArguments" => []]));
         }
     } elseif ($this->connectViaRepositoryWithName !== "") {
         if ($entity->isBasedInRepository() and $this->owner->isBasedInRepository()) {
             $this->createRelationshipInRepositoryForEntity($entity);
         } else {
             if (!$entity->isBasedInRepository()) {
                 $owner = $this->owner;
                 \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->registerEvent(new \obo\Services\Events\Event(["onObject" => $entity, "name" => "afterInsert", "actionAnonymousFunction" => function () use($owner, $entity) {
                     if ($owner->isBasedInRepository()) {
                         $this->createRelationshipInRepositoryForEntity($entity);
                     }
                 }, "actionArguments" => []]));
             }
             if (!$this->owner->isBasedInRepository()) {
                 \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->registerEvent(new \obo\Services\Events\Event(["onObject" => $this->owner, "name" => "afterInsert", "actionAnonymousFunction" => function () use($entity) {
                     if ($entity->isBasedInRepository()) {
                         $this->createRelationshipInRepositoryForEntity($entity);
                     }
                 }, "actionArguments" => []]));
             }
         }
     } else {
         throw new \obo\Exceptions\Exception("This relationship is not well configured");
     }
 }