This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b2dc20
commit cbdf34c
Showing
6 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
include_once 'model.php'; | ||
|
||
if (!isset($_GET) && array_key_exists("id", $_GET)) | ||
die("ID non valido."); | ||
|
||
$id = $_GET["id"]; | ||
$article = getArticleById($id); | ||
$images = getImagesByArticleId($id); | ||
|
||
if (count($images) == 1 && $images[0]["path"] == null) | ||
$images = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- Detail VIEW --> | ||
|
||
<?php | ||
include "controller.php"; | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="it"> | ||
<head> | ||
<?php include "head.php" ?> | ||
<title>Leggi articolo</title> | ||
</head> | ||
<body> | ||
<div class="container mt-4"> | ||
<a href="list.php">Torna indietro</a> | ||
<h1><?= $article["title"] ?></h1> | ||
<p class="lead"> | ||
<?= $article["subtitle"] ?> | ||
</p> | ||
|
||
<?php foreach ($images as $image) { ?> | ||
<img src="/static/images/<?= $image["path"] ?>" class="img-fluid" alt="Immagine"> | ||
<?php } ?> | ||
|
||
<p><?= $article["body"] ?></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<link rel="stylesheet" href="/static/css/bootstrap.min.css"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- List VIEW --> | ||
|
||
<?php | ||
include "model.php"; | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="it"> | ||
<head> | ||
<?php include "head.php" ?> | ||
<title>Lista articoli</title> | ||
</head> | ||
<body> | ||
<div class="container mt-4"> | ||
<h1>Tutti gli articoli</h1> | ||
|
||
<? var_dump(getAllArticles()) ?> | ||
<?php foreach (getAllArticles() as $article) { ?> | ||
<div class="card mb-2"> | ||
<?php if ($article["path"] !== null) { ?> | ||
<img src="/static/images/<?= $article["path"] ?>" class="card-img-top" alt="Article image"> | ||
<?php } ?> | ||
<div class="card-body"> | ||
<h5 class="card-title"><?= $article["title"] ?></h5> | ||
<p class="card-text"><?= $article["subtitle"] ?></p> | ||
<p class="text-muted">Da <?= $article["aa_name"] . " " . $article["aa_surname"] ?> scritto il <?= $article["creation_date"] ?></p> | ||
<a href="details.php?id=<?= $article["id"] ?>" class="btn btn-primary">Leggi</a> | ||
</div> | ||
</div> | ||
<?php } ?> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
$connection_data = [ | ||
'db_host' => 'mysql', | ||
'db_user' => 'root', | ||
'db_pass' => 'ROOT', | ||
'db_db' => 'articles' | ||
]; | ||
|
||
|
||
function getAllArticles() { | ||
$conn_data = $GLOBALS["connection_data"]; | ||
$conn = mysqli_connect($conn_data['db_host'], $conn_data['db_user'], $conn_data['db_pass'], $conn_data['db_db']); | ||
$sql = "SELECT a.*, aa.name AS aa_name, aa.surname AS aa_surname, i.path FROM articles.article a LEFT JOIN articles.contains c ON c.id_articles = a.id LEFT JOIN articles.image i ON c.id_image = i.id JOIN articles.author aa ON a.author_id = aa.id GROUP BY a.id"; | ||
$res = mysqli_query($conn, $sql); | ||
mysqli_close($conn); | ||
|
||
$returnData = []; | ||
while ($row = mysqli_fetch_assoc($res)) | ||
$returnData[] = $row; | ||
return $returnData; | ||
} | ||
|
||
function getArticleById(int $id) { | ||
$conn_data = $GLOBALS["connection_data"]; | ||
$conn = mysqli_connect($conn_data['db_host'], $conn_data['db_user'], $conn_data['db_pass'], $conn_data['db_db']); | ||
$sql = "SELECT * FROM articles.article WHERE id=$id"; | ||
$res = mysqli_query($conn, $sql); | ||
mysqli_close($conn); | ||
|
||
return mysqli_fetch_assoc($res); | ||
} | ||
|
||
function getImagesByArticleId(int $id) { | ||
$conn_data = $GLOBALS["connection_data"]; | ||
$conn = mysqli_connect($conn_data['db_host'], $conn_data['db_user'], $conn_data['db_pass'], $conn_data['db_db']); | ||
|
||
$sql = "SELECT i.path AS path FROM articles.article a LEFT JOIN articles.contains c ON c.id_articles = a.id LEFT JOIN articles.image i ON c.id_image = i.id WHERE a.id=$id"; | ||
$res = mysqli_query($conn, $sql); | ||
mysqli_close($conn); | ||
|
||
$returnData = []; | ||
while ($row = mysqli_fetch_assoc($res)) | ||
$returnData[] = $row; | ||
return $returnData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
USE articles; | ||
|
||
CREATE TABLE IF NOT EXISTS articles.article ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(20) NOT NULL, | ||
subtitle VARCHAR(30) NOT NULL, | ||
body VARCHAR(4096) NOT NULL, | ||
creation_date DATE NOT NULL, | ||
author_id INT NOT NULL, | ||
FOREIGN KEY (author_id) REFERENCES author(id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS articles.author ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(20) NOT NULL, | ||
surname VARCHAR(30) NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS articles.image ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
path VARCHAR(100) NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS articles.contains ( | ||
id_articles INT NOT NULL, | ||
id_image INT NOT NULL, | ||
PRIMARY KEY (id_articles, id_image) | ||
); |