/**
  * Handle user input 
  */
 public function listen()
 {
     if ($this->regCtrlr->registerLinkPressed()) {
         $this->regCtrlr->listen();
         $this->renderRegView = true;
     } else {
         $this->logCtrlr->listen();
         $this->renderRegView = false;
     }
 }
 public function run()
 {
     //CREATE OBJECTS OF THE VIEWS
     $loginM = new \model\LoginModel();
     $dtv = new \view\DateTimeView();
     $layoutV = new \view\LayoutView();
     $registerM = new \model\RegisterModel();
     $registerV = new \view\RegisterView();
     $loginC = new LoginController($loginM);
     $registerC = new \controller\RegisterController($registerM, $registerV);
     $loggedInSuccessfully = false;
     if ($layoutV->didUserPressRegistrationLink()) {
         $lv = $registerV;
         $registerC->doRegister();
     } else {
         $lv = new \view\LoginView($loginM);
         $loggedInSuccessfully = $loginC->doLogin();
         //returns bool
     }
     $layoutV->render($loggedInSuccessfully, $lv, $dtv);
 }
 public function render()
 {
     try {
         $sessionModel = new SessionModel();
         $masterView = new MasterView();
         // Dependency injection of sessionModel to make sure they all user same.
         $loginController = new LoginController($sessionModel);
         $isLoggedIn = $loginController->checkLogin();
         $umlToCodeController = new UmlToCodeController(new InterpretModel());
         switch (NavView::getAction()) {
             case NavView::$umlSubmit:
                 if ($isLoggedIn) {
                     $masterView->SetMemberVIew($umlToCodeController->showMemberView($sessionModel));
                     break;
                 }
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
             case NavView::$umlGetLists:
                 if ($isLoggedIn) {
                     $masterView->SetProjectsView($umlToCodeController->projectsView($sessionModel));
                     $masterView->SetMemberVIew($umlToCodeController->showMemberView($sessionModel));
                     break;
                 }
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
             case NavView::$showProject:
                 if ($isLoggedIn) {
                     $umlToCodeController->selectProject($sessionModel);
                     $masterView->SetMemberVIew($umlToCodeController->showMemberView($sessionModel));
                     break;
                 }
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
             case NavView::$deleteProject:
                 if ($isLoggedIn) {
                     $umlToCodeController->deleteUmlProject($sessionModel);
                     $masterView->SetMemberVIew($umlToCodeController->showMemberView($sessionModel));
                     break;
                 }
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
             case NavView::$registerView:
                 $registerController = new RegisterController();
                 $masterView->SetRegisterView($registerController->registerView());
                 break;
             case NavView::$login:
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
             case NavView::$logoutView:
                 $loginController->logout();
                 break;
             default:
                 if ($isLoggedIn) {
                     $masterView->SetMemberVIew($umlToCodeController->showMemberView($sessionModel));
                     break;
                 }
                 $masterView->SetGuestView($umlToCodeController->showGuestView());
                 $masterView->SetLoginView($loginController->loginView());
                 break;
         }
         return $masterView->render();
     } catch (Exception $e) {
         header('Location: /' . \Settings::$ROOT_PATH . '/common/error.html');
         return null;
     }
 }
示例#4
0
 /**
  * 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;
                         }
                     }
                 }
             }
         }
     }
 }