use src\ProjectWhisky\business\DistilleryBusiness; use src\ProjectWhisky\exceptions\CommentNotExistsException; use src\ProjectWhisky\exceptions\FuckedUpException; use Doctrine\Common\ClassLoader; require_once "rolestarter.php"; // gives to user role = 0 on first visit of the website: role = 0 - guest if (isset($_GET['id']) && is_int((int) $_GET['id']) && !empty($_GET['id'])) { /** * Connecting doctrine autoloader */ require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); $whiskyBiz = new WhiskyBusiness(); $whisky = $whiskyBiz->getWhisky($_GET["id"]); $barrelBiz = new BarrelBusiness(); $barrel = $barrelBiz->showBarrel($_GET["id"]); $distilleryBiz = new DistilleryBusiness(); $distillery = $distilleryBiz->getByWhisky($_GET["id"]); $commentBiz = new CommentBusiness(); $userBiz = new UserBusiness(); /** * Put comments data with user info into an array $participatedUsers */ if (!empty($commentBiz->showComments($_GET["id"]))) { foreach ($commentBiz->showComments($_GET["id"]) as $key => $comment) { $usersDataFromComments = $userBiz->getUserByComment($comment->getId()); $participatedUsers[$key]['userId'] = $usersDataFromComments->getId(); $participatedUsers[$key]['username'] = $usersDataFromComments->getUsername();
<?php session_start(); use src\ProjectWhisky\business\DistilleryBusiness; use src\ProjectWhisky\business\WhiskyBusiness; use Doctrine\Common\ClassLoader; /** * Connecting doctrine autoloader */ require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); /* Twig autoloader*/ require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); $distilleryBiz = new DistilleryBusiness(); $whiskyBiz = new WhiskyBusiness(); $distillery = $distilleryBiz->getDistillery($_GET["id"]); $whiskies = $whiskyBiz->getWhiskyByDistillery($_GET["id"]); /* print("<pre>"); print_r($distillery); print("</pre>"); */ $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("distillery_page.twig", array("user" => $_SESSION['user'], "distillery" => $distillery, "whiskies" => $whiskies)); print $view;
use src\ProjectWhisky\business\WhiskyBusiness; use src\ProjectWhisky\business\BarrelBusiness; use src\ProjectWhisky\business\DistilleryBusiness; use Doctrine\Common\ClassLoader; require_once "rolestarter.php"; require_once "adminRights.php"; // Redirects users ir guest from control panel to index.php if is not admin require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); if (!isset($_SESSION['whiskyMessage'])) { $_SESSION['whiskyMessage'] = ""; } $whiskyBiz = new WhiskyBusiness(); if (isset($_GET['whiskyname']) && !empty($_GET['whiskyname'])) { $whiskynameTrim = trim($_GET['whiskyname']); $whiskyList = $whiskyBiz->getWhiskiesByName($whiskynameTrim); $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("CP_whisky.twig", array("user" => $_SESSION['user'], "whiskies" => $whiskyList, "searchInput" => $whiskynameTrim)); } else { $whiskyList = $whiskyBiz->getWhiskyList(); $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("CP_whisky.twig", array("user" => $_SESSION['user'], "whiskies" => $whiskyList, "msg" => $_SESSION['whiskyMessage'])); } print $view; /** * Handling messages removal and appearance
require_once "rolestarter.php"; // gives to user role = 0 on first visit of the website: role = 0 - guest require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); if (isset($_GET['strength_rangeleft']) && isset($_GET['strength_rangeright']) && isset($_GET['score_rangeleft']) && isset($_GET['score_rangeright']) && isset($_GET['age_rangeright']) && isset($_GET['age_rangeright']) && isset($_GET['barrel_id']) && isset($_GET['region'])) { $whiskyBiz = new WhiskyBusiness(); $whiskyList = $whiskyBiz->getWhiskyBySearch($_GET["barrel_id"], $_GET["strength_rangeleft"], $_GET["strength_rangeright"], $_GET["score_rangeleft"], $_GET["score_rangeright"], $_GET["region"], $_GET["age_rangeleft"], $_GET["age_rangeright"]); $BarrelBiz = new BarrelBusiness(); $barrelList = $BarrelBiz->showAllBarrels(); $distilleryBiz = new DistilleryBusiness(); $regionList = $distilleryBiz->getRegionList(); $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("whisky_search_results.twig", array("user" => $_SESSION['user'], "whiskies" => $whiskyList, "barrels" => $barrelList, "distilleries" => $regionList)); print $view; } else { $whiskyBiz = new WhiskyBusiness(); $whiskyList = $whiskyBiz->getWhiskyList(); $BarrelBiz = new BarrelBusiness(); $barrelList = $BarrelBiz->showAllBarrels(); $distilleryBiz = new DistilleryBusiness(); $regionList = $distilleryBiz->getRegionList(); $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("whisky_search.twig", array("user" => $_SESSION['user'], "whiskies" => $whiskyList, "barrels" => $barrelList, "distilleries" => $regionList)); print $view; } ob_flush();
} } else { $_SESSION['whiskyMessage'] = "Allowed file size is 2MB"; } } } else { $_SESSION['whiskyMessage'] = "Only .png, .jpg, .jpeg and .gif files are allowed."; } } $hidden = 0; $_SESSION['savedData']['rating_aroma'] = $_SESSION['savedData']['rating_aroma'] * 2; $_SESSION['savedData']['rating_color'] = $_SESSION['savedData']['rating_color'] * 2; $_SESSION['savedData']['rating_taste'] = $_SESSION['savedData']['rating_taste'] * 2; $_SESSION['savedData']['rating_aftertaste'] = $_SESSION['savedData']['rating_aftertaste'] * 2; // Add whisky to DB $whiskyBiz = new WhiskyBusiness(); $addWhisky = $whiskyBiz->addWhisky($_SESSION['savedData']['name'], $_SESSION['savedData']['distillery'], $_SESSION['savedData']['price'], $_SESSION['savedData']['age'], $_SESSION['savedData']['strength'], $_SESSION['savedData']['barrel_id'], $newImagePath, $hidden, $_SESSION['savedData']['rating_aroma'], $_SESSION['savedData']['rating_color'], $_SESSION['savedData']['rating_taste'], $_SESSION['savedData']['rating_aftertaste'], $_SESSION['savedData']['text_aroma'], $_SESSION['savedData']['text_color'], $_SESSION['savedData']['text_taste'], $_SESSION['savedData']['text_aftertaste'], $_SESSION['savedData']['review'], $_SESSION['savedData']['user_id']); if ($addWhisky == false) { throw new FuckedUpException(); } $_SESSION['whiskyMessage'] = "success"; header("Location: CP_whisky_add.php?updated=1"); } catch (EmptyDataException $e) { $_SESSION['whiskyMessage'] = "missing"; } catch (NoImageException $e) { $_SESSION['whiskyMessage'] = "image_missing"; } catch (FuckedUpException $e) { $_SESSION['whiskyMessage'] = "error"; } } // Get distillery data
<?php /** * IMPORTANT: add following things in every controller: * session_start() * require_once("rolestarter.php"); * "user" => $_SESSION['user'] needs to be sent to Twig */ session_start(); use src\ProjectWhisky\business\WhiskyBusiness; use Doctrine\Common\ClassLoader; require_once "rolestarter.php"; // gives to user role = 0 on first visit of the website: role = 0 - guest /** * Connecting doctrine autoloader */ require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); $whiskyList = new WhiskyBusiness(); $loader = new Twig_Loader_Filesystem("src/ProjectWhisky/presentation"); $twig = new Twig_Environment($loader); $view = $twig->render("home.twig", array("whiskies" => $whiskyList->getWhiskyList(), "user" => $_SESSION['user'])); print $view;
use src\ProjectWhisky\business\UserBusiness; use src\ProjectWhisky\exceptions\EmptyDataException; use src\ProjectWhisky\exceptions\NoImageException; use src\ProjectWhisky\exceptions\FuckedUpException; use Doctrine\Common\ClassLoader; require_once "rolestarter.php"; require_once "adminRights.php"; // Redirects users ir guest from control panel to index.php if is not admin require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new ClassLoader("src"); $classLoader->register(); require_once "lib/Twig/Autoloader.php"; Twig_Autoloader::register(); $whisky_id = $_GET["id"]; // Get Whisky Data $whiskyBiz = new WhiskyBusiness(); $whisky_data = $whiskyBiz->getWhisky($whisky_id); // Get Distillery Data $distilleryBiz = new DistilleryBusiness(); $distillery_data = $distilleryBiz->getDistilleryList(); // Get Barrel Data $barrelBiz = new BarrelBusiness(); $barrel_data = $barrelBiz->showAllBarrels(); /** * Initiate $_SESSION['savedData'] and $_SESSION['whiskyMessage'] */ if (!isset($_SESSION['savedData'])) { $_SESSION['savedData'] = array(); $_SESSION['whiskyMessage'] = array(); } /**