public function save(UserRole $user) { $data = $user->getRawData(); if ($user->getUserRoleId() > 0) { $id = $user->getUserRoleId(); $this->tableGateway->update($data, array('aufri_users_role_id' => $id)); } else { if (!$this->tableGateway->insert($data)) { throw new \Exception("Could not new row {$id}"); } $id = (int) $this->tableGateway->lastInsertValue; } return $this->getOne(array('aufri_users_role_id' => $id)); }
/** * Function to set user roles * @return array $userRole array user role * @param array $data array containing data entered in the form * @param array $user array in which user data is saved */ public function setUserRole($data, $user) { $userRole = new UserRole(); $userRole->setRoleId($data['roles']); $userRole->setUserId($user->getId()); return $userRole; }