From cbdf34c5d5025fb7f072417bb873760e36b4803d Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Tue, 26 May 2020 12:40:14 +0200 Subject: [PATCH] Add final presentation CMS website --- compiti/presentazione-dbms-php/controller.php | 13 ++++++ compiti/presentazione-dbms-php/details.php | 28 ++++++++++++ compiti/presentazione-dbms-php/head.php | 3 ++ compiti/presentazione-dbms-php/list.php | 33 ++++++++++++++ compiti/presentazione-dbms-php/model.php | 45 +++++++++++++++++++ compiti/presentazione-dbms-php/schema.sql | 28 ++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 compiti/presentazione-dbms-php/controller.php create mode 100644 compiti/presentazione-dbms-php/details.php create mode 100644 compiti/presentazione-dbms-php/head.php create mode 100644 compiti/presentazione-dbms-php/list.php create mode 100644 compiti/presentazione-dbms-php/model.php create mode 100644 compiti/presentazione-dbms-php/schema.sql diff --git a/compiti/presentazione-dbms-php/controller.php b/compiti/presentazione-dbms-php/controller.php new file mode 100644 index 0000000..c334aa8 --- /dev/null +++ b/compiti/presentazione-dbms-php/controller.php @@ -0,0 +1,13 @@ + + + + + + + + + Leggi articolo + + +
+ Torna indietro +

+

+ +

+ + + " class="img-fluid" alt="Immagine"> + + +

+
+ + diff --git a/compiti/presentazione-dbms-php/head.php b/compiti/presentazione-dbms-php/head.php new file mode 100644 index 0000000..eb63786 --- /dev/null +++ b/compiti/presentazione-dbms-php/head.php @@ -0,0 +1,3 @@ + + + diff --git a/compiti/presentazione-dbms-php/list.php b/compiti/presentazione-dbms-php/list.php new file mode 100644 index 0000000..1307cc8 --- /dev/null +++ b/compiti/presentazione-dbms-php/list.php @@ -0,0 +1,33 @@ + + + + + + + + + Lista articoli + + +
+

Tutti gli articoli

+ + + +
+ + " class="card-img-top" alt="Article image"> + +
+
+

+

Da scritto il

+ " class="btn btn-primary">Leggi +
+
+ +
+ + diff --git a/compiti/presentazione-dbms-php/model.php b/compiti/presentazione-dbms-php/model.php new file mode 100644 index 0000000..668da77 --- /dev/null +++ b/compiti/presentazione-dbms-php/model.php @@ -0,0 +1,45 @@ + '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; +} diff --git a/compiti/presentazione-dbms-php/schema.sql b/compiti/presentazione-dbms-php/schema.sql new file mode 100644 index 0000000..d917e77 --- /dev/null +++ b/compiti/presentazione-dbms-php/schema.sql @@ -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) +);