public function createSessionData($userEmail) { $facade = new UserFacade(); try { $session = array(); $user = $facade->findByEmail($userEmail); if ($user != NULL) { $session = array('id' => $user->getId(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'admin' => $user->getAdmin(), 'active' => $user->getActive(), 'type' => $user->getType(), 'birthdate' => $user->getBirthdate()->format('d/m/Y'), 'phone' => $user->getPhone()); $groups = array(); foreach ($user->getGroup() as $userGroup) { $group = $userGroup->getGroup(); $groups[] = array('group_id' => $group->getId(), 'group_name' => $group->getName()); } $session['groups'] = $groups; } return $session; } catch (\Exception $ex) { throw new Exception($ex->getMessage()); } }
function cadastrar($name, $acronym, $email, $phone, $address, $description) { $facade = new GroupFacade(); $userGroupFacade = new UserGroupFacade(); $userFacade = new UserFacade(); $userData = $this->sessionstorage->getUserSession(); if ($name == NULL || $name == '') { throw new Exception('O nome do grupo não pode ser nulo'); } $grupo = new Group(NULL, $name, $acronym, $description, $email, $phone, $address); try { $savedGroup = $facade->save($grupo); $user = $userFacade->findById($userData['id']); $userGroup = new UserGroup(NULL, TRUE); $userGroup->setGroup($savedGroup); $userGroup->setUser($user); $userGroupFacade->save($userGroup); return TRUE; } catch (\Exception $ex) { throw new Exception($ex->getMessage()); } }