/** * @param Role $role * @return Role */ public function saveRole(Role $role) { $id = $role->getRoleId(); $data = $role->getArrayCopy(); if ($id > 0) { $this->update($data, array('roleId' => $id)); } else { unset($data['roleId']); $this->insert($data); } if (!$role->getRoleId()) { $role->setRoleId($this->getLastInsertValue()); } return $role; }