Listing in beer and brewery

master
flejk 3 years ago
parent 147a41aa0c
commit c5b703308f

@ -4,15 +4,18 @@
## TO DO:
*Make searchbar work*
*Implement articles*
*Implement listing and following*
### Tasks
*search.php*
*implement tags*
*insert beer/brewery/article form - /admin.php*
*add beer to list/ add brewery to follow*
*article/brewery/beer/list .php*
*brewery/beer/list .php*

@ -4,6 +4,7 @@ require_once("model/db.php");
require_once("controller/getRecord.php");
require("view/header.php");
require("view/sidebar.php");
$record = getRecord($pdo, "article", $_GET["id"] );
$title = $record["title"];
@ -13,6 +14,4 @@ $date = $record["time"];
require("view/mainContent/mainContent.php");
require("view/sidebar.php");
include("view/footer.php");

@ -2,20 +2,33 @@
session_start();
require_once("model/db.php");
require_once("controller/getRecord.php");
require_once("view/mainContent/userButtons.php");
require("view/header.php");
require("view/sidebar.php");
$record = getRecord($pdo, "beer", $_GET["id"] );
$title = $record["name"];
$description = $record["description"];
$date = $record["time"];
$alc = $record["alc"];
$ibu = $record["ibu"];
$description = $record["description"];
$brewery_id = $record["brewery_id"];
$date = $record["time"];
require("view/mainContent/mainContent.php");
require("view/sidebar.php");
$brewery = getRecord($pdo, "brewery", $brewery_id )["name"];
require("view/mainContent/beerExtraInfo.php");
echo "Kappa";
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
if(isThisBound($pdo, "list", $_GET["id"], $_SESSION["id"])){
unfollowButton($pdo, "list", $_GET["id"], $_SESSION["id"]);
} else followButton($pdo, "list", $_GET["id"], $_SESSION["id"]);
showStars($pdo, $_GET["id"], $_SESSION["id"]);
}
include("view/footer.php");

@ -2,8 +2,10 @@
session_start();
require_once("model/db.php");
require_once("controller/getRecord.php");
require_once("controller/listLatest.php");
require("view/header.php");
require("view/sidebar.php");
$record = getRecord($pdo, "brewery", $_GET["id"] );
$title = $record["name"];
@ -11,10 +13,24 @@ $description = $record["description"];
$date = $record["time"];
$region = $record["region"];
$array = listBeersByBrewery($pdo, $_GET["id"]);
require("view/mainContent/mainContent.php");
require("view/mainContent/breweryExtraInfo.php");
require("view/sidebar.php");
$title = "Beers from $title";
$what = "beer";
require("view/sidebar/sidebarLister.php");
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
if(isThisBound($pdo, "follow", $_GET["id"], $_SESSION["id"])){
unfollowButton($pdo, "follow", $_GET["id"], $_SESSION["id"]);
} else followButton($pdo, "follow", $_GET["id"], $_SESSION["id"]);
}
include("view/footer.php");

@ -13,3 +13,20 @@ function getRecord($pdo, $from, $where ){
}
return $record;
}
function isThisBound($pdo, $where, $item_id, $user_id){
$conn = $pdo;
try {
if($where === "list"){
$item = "beer_id";
}else $item = "brewery_id";
$sql = "SELECT * FROM $where WHERE $item = $item_id AND user_id = $user_id";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)return true;
else return false;
} catch (PDOException $e) {
echo "Error in $where: Not Found";
}
}

@ -56,3 +56,17 @@ function listLatestArticle($pdo, $where){
return $arrayOfArticles;
}
function listBeersByBrewery($pdo, $where){
$conn = $pdo;
try {
$stmt = $conn->prepare("SELECT * FROM beer WHERE brewery_id = $where");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$arrayBeers = $stmt->fetchAll();
} catch (PDOException $e) {
echo "Error in Beers: " . $e->getMessage();
}
return $arrayBeers;
}

@ -12,7 +12,7 @@ insert into user ( nick, mail, password ) values ( 'aa', 'test@mail.cz', '$2y$10
insert into brewery (name, region, description) values ( 'Zichovec', 'Louny', 'Remeslny pivovar');
insert into brewery (name, region, description) values ( 'Siberia', 'Praha 9-Vysočany', 'Remeslny pivovar');
insert into brewery (name, region, description) values ( 'Siberia', 'Praha 9-Vysocany', 'Remeslny pivovar');
insert into brewery (name, region, description) values ( 'Matuska', 'Broumy', 'Remeslny pivovar');
insert into brewery (name, region, description) values ( 'Cestmir', 'Stara Boleslav', 'Remeslny pivovar');
insert into brewery (name, region, description) values ( 'Prazdroj', 'Plzen', 'Pilsner Urquell');

@ -21,6 +21,33 @@ body {
background-color:white;
}
/* Tagy */
.taglist .tag{
margin-right:.4em;
padding:.5em;
background:#e8e6dc;
color:#000;
border-radius:5px;
border:1px solid #aaa;
font-size:.9rem;
display:inline-block;
}
.taglist .tag a{
color: #000;
}
.taglist .tag a:hover{
color:#fff;
}
.taglist {
display:flex;
align-items:center;
margin-bottom:.5em
}
/* - Nadpisy - */
h1, h2, h3 {
font-family: 'Signika Negative', sans-serif;
@ -75,7 +102,7 @@ nav > div.profile {
justify-content: space-between;
}
nav ul, nav li {
ul, li {
list-style: none;
text-align: justify;
}
@ -127,6 +154,27 @@ aside ul, aside li {
text-align: left;
}
/* Tables */
table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
min-width: 400px;
border-radius: 5px 5px 0 0;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
table th,
table td {
padding: 12px 15px;
border: 1px solid #575757;
}
table tbody tr {
border: 3px solid #575757;
}
/* Formulář */

@ -0,0 +1,14 @@
<div class="content">
<table>
<tr>
<td>Alcohol Volume:</td>
<td>IBU:</td>
<td>From brewery:</td>
</tr>
<tr>
<td><?= $alc ?></td>
<td><?= $ibu ?></td>
<td><a href="brewery.php?id=<?= $brewery_id ?>"><?= $brewery ?></a></td>
</tr>
</table>
</div>

@ -0,0 +1,10 @@
<div class="content">
<table>
<tr>
<td>From:</td>
</tr>
<tr>
<td><?= $region ?></td>
</tr>
</table>
</div>

@ -0,0 +1,35 @@
<?php
function unfollowButton($pdo, $where, $item_id, $user_id){
print_r($pdo);
$conn = $pdo;
try {
$sql = "SELECT * FROM $from WHERE id = $where";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$record = $stmt->fetch();
} catch (PDOException $e) {
echo "Error in $from: Not Found";
}
return $record;
}
function followButton($pdo, $where, $item_id, $user_id){
print_r($pdo);
$conn = $pdo;
try {
$sql = "SELECT * FROM $from WHERE id = $where";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$record = $stmt->fetch();
} catch (PDOException $e) {
echo "Error in $from: Not Found";
}
return $record;
}
function showStars($pdo, $beer_id, $user_id){
print_r($pdo);
}
Loading…
Cancel
Save