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; }
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() ); }
function vehicleBind() { $bind = array(); foreach ($this->parent_id as $level => $val) { $bind[$this->inflect($level . '_id')] = $val; } $bind[$this->inflect($this->entity->getType() . '_id')] = $this->entity->getId(); return $bind; }