function save($requestedSaveId = null) { $this->requestedSaveId = $requestedSaveId; if ($this->getSchema()->isGlobal($this->entity->getType())) { $id = $this->entity->getId(); $existingId = $this->levelFinder()->findEntityIdByTitle($this->entity->getType(), $this->entity->getTitle()); if (false == $existingId) { $this->getReadAdapter()->insert($this->entity->getTable(), $this->getBind()); $id = $this->getReadAdapter()->lastInsertId(); $this->entity->setId($id); } else { $this->entity->setId($existingId); } return $id; } else { $existingId = $this->levelFinder()->findEntityIdByTitle($this->entity->getType(), $this->entity->getTitle()); if (!$existingId) { $this->getReadAdapter()->insert($this->inflect($this->entity->getTable()), $this->getBind()); } } $id = $existingId ? $existingId : $this->getReadAdapter()->lastInsertId(); if (!$this->entity->getId()) { $this->entity->setId($id); } return $id; }
function save($requestedSaveId = null) { $this->requestedSaveId = $requestedSaveId; if ($this->getSchema()->isGlobal($this->entity->getType())) { $id = $this->entity->getId(); $existingId = $this->levelFinder()->findEntityIdByTitle($this->entity->getType(), $this->entity->getTitle()); if (false == $existingId) { $this->getReadAdapter()->insert($this->entity->getTable(), $this->getBind()); $id = $this->getReadAdapter()->lastInsertId(); $this->entity->setId($id); } else { $this->entity->setId($existingId); } $this->createVehicleDefinition(); return $id; } else { if (is_array($this->parent_id)) { $prevLevel = $this->getSchema()->getPrevLevel($this->entity->getType()); $parent_id = $this->parent_id[$prevLevel]; } else { $parent_id = $this->parent_id; } $existingId = $this->levelFinder()->findEntityIdByTitle($this->entity->getType(), $this->entity->getTitle(), $parent_id); if (!$existingId) { $this->getReadAdapter()->insert($this->inflect($this->entity->getTable()), $this->getBind()); } } $id = $existingId ? $existingId : $this->getReadAdapter()->lastInsertId(); if (!$this->entity->getId()) { $this->entity->setId($id); } $this->createVehicleDefinition(); return $id; }
protected function getQuery() { return sprintf( "UPDATE %s SET `title` = %s WHERE id = %d", $this->getReadAdapter()->quoteIdentifier( $this->entity->getTable() ), $this->getReadAdapter()->quote( $this->entity->getTitle() ), (int)$this->entity->getId() ); }