public function run() { //Dependency injection $this->m_DatabaseConnection = new \DatabaseConnection(); $this->m_Login = new model\LoginModel($this->m_DatabaseConnection); $this->v_Login = new view\LoginView($this->m_Login); $this->c_Login = new controller\LoginController($this->m_Login, $this->v_Login); $this->m_Registration = new model\RegistrationModel(); $this->m_RegistrationDAL = new model\RegistrationDAL($this->m_DatabaseConnection); $this->v_Registration = new view\RegistrationView($this->m_Registration, $this->m_RegistrationDAL); $this->c_Registration = new controller\RegistrationController($this->v_Registration, $this->m_Registration, $this->m_RegistrationDAL); //Controller must be run first since state is changed if ($this->c_Registration->userWantToRegister()) { $viewToRender = $this->v_Registration; $this->registerNewUser = true; if ($this->c_Registration->userWantToRegisterNewUser()) { $this->c_Registration->doRegistration(); } } else { $viewToRender = $this->v_Login; $this->c_Login->doControl(); $this->loggedIn = $this->m_Login->isLoggedIn($this->v_Login->getUserClient()); } //Generate output $v_DateTime = new view\DateTimeView(); $v_Layout = new view\LayoutView(); $v_Layout->render($this->registerNewUser, $this->loggedIn, $viewToRender, $v_DateTime); }
/** * @throws \Exception */ public function run() { try { if ($this->navView->userWantsToDoPubsAndBeers()) { $html = $this->doPub(); } elseif ($this->navView->userWantsToDoAdmin()) { $html = $this->doAdmin(); } $this->layoutView->render($html); } catch (\Exception $e) { error_log($e->getMessage() . "\n", 3, \Settings::ERROR_LOG); if (\Settings::DEBUG_MODE) { throw $e; } else { // show generic error view here echo $e->getMessage(); } } }
/** * Handle user input */ public function listen() { if ($this->regCtrlr->registerLinkPressed()) { $this->regCtrlr->listen(); $this->renderRegView = true; $this->renderSearchView = false; $this->renderMyProfile = false; $this->renderSettingsView = false; } else { if ($this->layoutView->searchButtonPost()) { try { $usernameSearch = $this->layoutView->getUserSearchTerm(); $this->searchController->searchUser($usernameSearch); $this->searchController->listen(); $this->renderSearchView = true; $this->renderRegView = false; $this->renderMyProfile = false; $this->renderSettingsView = false; } catch (SUsernameMissingException $e) { $this->layoutView->setSearchMsgUsernameMissing(); } catch (SInvalidCharactersException $e) { $this->layoutView->setSearchMsgInvalidCharacters(); } } else { if ($this->layoutView->logoutButtonPost()) { $this->logCtrlr->logout(); } else { if ($this->layoutView->myProfileButtonPost()) { $this->userProfileController->setUserProfile(null); $this->userProfileController->listen(); $this->renderMyProfile = true; $this->renderRegView = false; $this->renderSearchView = false; $this->renderSettingsView = false; } else { if ($this->layoutView->settingsButtonPost()) { $this->settingsController->listen(); $this->renderSettingsView = true; $this->renderMyProfile = false; $this->renderRegView = false; $this->renderSearchView = false; /* if($this->settingsController->renderProfileView()) { var_dump("Profile from settings (nested)"); $this->userProfileController->setUserProfile(null); $this->userProfileController->listen(); $this->renderMyProfile = true; $this->renderRegView = false; $this->renderSearchView = false; $this->renderSettingsView = false; } */ } else { if ($this->settingsView->saveButtonPost()) { $this->settingsController->saveChanges(); $this->renderRegView = false; $this->renderSearchView = false; $this->renderMyProfile = false; $this->renderSettingsView = false; } else { $this->logCtrlr->listen(); $this->renderRegView = false; $this->renderSearchView = false; $this->renderMyProfile = false; $this->renderSettingsView = false; } } } } } } }