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;
    }
Exemplo n.º 2
0
 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;
 }