Esempio n. 1
0
 /**
  * @throws Exception if the key is unkown
  * @return \model\Product
  */
 public function getSelectedProduct()
 {
     assert($this->navigation->customerWantsToSeeProduct());
     $unique = $this->navigation->getProductID();
     $product = $this->catalog->getProductFromUnique($unique);
     if ($product != null) {
         return $product;
     }
     throw new \Exception("unknown key");
 }
Esempio n. 2
0
 public function doStore()
 {
     if ($this->navigationView->customerWantsToSeeProduct()) {
         //setup controller
         $selectedProduct = $this->productCatalogView->getSelectedProduct();
         $productLikes = new \model\ProductLikes($selectedProduct);
         $popularityView = new \view\PopularityView($this->navigationView, $selectedProduct, $productLikes);
         $likeController = new PopularityController($popularityView, $productLikes);
         //execute child controller
         $likeController->doLike();
         //initiate view
         $this->productView = new \view\ProductView($selectedProduct, $this->navigationView, $popularityView);
     }
 }
Esempio n. 3
0
 /**
  * Checks what controller to instansiate and return value of to HTMLView.
  */
 public function doControll()
 {
     $controller;
     try {
         switch (\view\NavigationView::getAction()) {
             case \view\NavigationView::$actionAddUser:
                 $controller = new ParticipantController();
                 return $controller->addUser();
                 break;
             case \view\NavigationView::$actionShowUser:
                 $controller = new ParticipantController();
                 return $controller->show();
                 break;
             case \view\NavigationView::$actionAddProject:
                 $controller = new ParticipantController();
                 return $controller->addProject();
             default:
                 $controller = new ParticipantController();
                 return $controller->showAll();
                 break;
         }
     } catch (\Exception $e) {
         error_log($e->getMessage() . "\n", 3, \Settings::$ERROR_LOG);
         if (\Settings::$DO_DEBUG) {
             throw $e;
         } else {
             \view\NavigationView::RedirectToErrorPage();
             die;
         }
     }
 }
Esempio n. 4
0
 public function echoHTML($body)
 {
     if ($body === NULL) {
         throw new \Exception("HTMLView::echoHTML does not allow body to be null");
     }
     $html = "\n\t\t\t\t<!DOCTYPE html>\n\t\t\t\t<html>\n\t\t\t\t<head>\n\t\t\t\t<meta charset=\"utf-8\">\n\t\t\t\t</head>\n\t\t\t\t<body>";
     $html .= \view\NavigationView::getMenu();
     $html .= "{$body}\n\t\t\t\t</body>\n\t\t\t\t</html>";
     echo $html;
 }
 /**
  * @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();
         }
     }
 }
Esempio n. 6
0
 public function doControl()
 {
     // setup everything for the login
     $userDAL = new \model\UserDAL();
     $sessionHandler = new \common\SessionHandler();
     $cookieHandler = new \view\CookieHandler();
     $loginModel = new \model\LoginModel($sessionHandler, $userDAL);
     $loginView = new \view\LoginView($sessionHandler, $cookieHandler, $loginModel);
     $loginController = new \controller\LoginController($loginModel, $loginView);
     $isLoggedIn = $loginController->doLoginAction();
     // The first view is always the AdminView
     $this->view = new \view\AdminView($loginView, $this->navView, $isLoggedIn);
     // Don't want to continue further down if not logged in
     if (!$isLoggedIn) {
         return;
     }
     if ($this->navView->adminWantsToAddBeer()) {
         $this->view = new \view\AddBeerView($sessionHandler, $this->adminFacade->getPubs());
         if ($this->view->adminPressedSave()) {
             $beer = $this->view->getBeer();
             if ($beer == null) {
                 return;
             }
             $pubBeer = $this->view->getPubBeer($beer->getId());
             $this->adminFacade->addBeer($beer);
             $this->adminFacade->addPubBeer($pubBeer);
             $this->navView->redirectToBeer($beer->getId());
         }
     } elseif ($this->navView->adminWantsToAddPub()) {
         $this->view = new \view\AddPubView($sessionHandler);
         if ($this->view->adminPressedSave()) {
             $pub = $this->view->getPub();
             if ($pub == null) {
                 return;
             }
             $this->adminFacade->addPub($pub);
             $this->navView->redirectToPub($pub->getId());
         }
     }
 }
Esempio n. 7
0
 public function getHTML($title, \view\NavigationView $nav, $body)
 {
     $link = $nav->getGameLink();
     echo "<!DOCTYPE html>\n      <html>\n        <head>\n          <meta charset=\"" . $this->charset . "\">\n          <title>{$title}</title>\n          <link rel='stylesheet' href='../tick-tack-toe/style/style.css'>\n        </head>\n        <body>\n          <h2>{$title}</h2>\n          {$body}\n          {$link}\n        </body>\n      </html>";
 }
 /**
  * Controller function to add a project.
  * Function returns HTML or Redirect.
  * 
  * @TODO: Move to an own controller?
  * 
  * @return Mixed
  */
 public function addProject()
 {
     $view = new \view\ProjectView();
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $project = $view->getProject();
         $project->setOwner($this->participantRepository->get($view->getOwnerUnique()));
         $this->projectRepository->add($project);
         \view\NavigationView::RedirectToUser($view->getOwnerUnique());
     } else {
         return $view->getForm($this->participantRepository->get(\view\NavigationView::getId()));
     }
 }
Esempio n. 9
0
 /**
  * @throws \BeerDoesNotExistException
  */
 public function viewBeer()
 {
     $beerID = $this->navView->getBeerId();
     $beer = $this->beers->getById($beerID);
     $this->beerView = new \view\BeerView($beer);
 }