Commit 2a5962bd authored by Stephane Crozat's avatar Stephane Crozat
Browse files

Ajout des jours de début et de fin des Api, modif des vues, modif du PHP pour utiliser les vues

parent 0879efb0
Backup DB
HTTPS HTTPS
Gestion d'erreurs DB Gestion d'erreurs DB
Élucidation fonctionnement CAS (cf Mattermost)
...@@ -27,8 +27,8 @@ class DB { ...@@ -27,8 +27,8 @@ class DB {
} }
function subList($utclogin) { function subList($utclogin) {
$sql = "SELECT code, name, year, semester, TO_CHAR(subdate,'DD/MM/YYYY') as subdate $sql = "SELECT *
FROM api JOIN subscribe ON api.code=subscribe.api FROM vSubscription
WHERE utclogin='".$utclogin."'"; WHERE utclogin='".$utclogin."'";
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->execute(); $st->execute();
...@@ -51,10 +51,9 @@ class DB { ...@@ -51,10 +51,9 @@ class DB {
} }
function apiList($utclogin, $semester, $year) { function apiList($utclogin, $semester, $year) {
$sql = "SELECT code, name $sql = "SELECT *
FROM api FROM vApi
WHERE semester='".$semester."' AND year=".$year." WHERE semester='".$semester."' AND year=".$year.";
ORDER BY code, name";
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->execute(); $st->execute();
$res = $st->fetchAll(PDO::FETCH_ASSOC); $res = $st->fetchAll(PDO::FETCH_ASSOC);
......
...@@ -15,6 +15,8 @@ class Api { ...@@ -15,6 +15,8 @@ class Api {
name : text name : text
year : year year : year
semester : H|E semester : H|E
dbegin : date
dend : date
} }
note right of Api : (name,year,semester) key note right of Api : (name,year,semester) key
......
...@@ -6,9 +6,12 @@ CREATE TABLE api ( ...@@ -6,9 +6,12 @@ CREATE TABLE api (
name TEXT NOT NULL, name TEXT NOT NULL,
year INTEGER NOT NULL, year INTEGER NOT NULL,
semester CHAR(1) NOT NULL, semester CHAR(1) NOT NULL,
dbegin DATE NOT NULL,
dend DATE NOT NULL,
CHECK (code>0), CHECK (code>0),
CHECK (year>2018 AND year<2100), CHECK (year>2018 AND year<2100),
CHECK (semester IN ('H','E')), CHECK (semester IN ('H','E')),
CHECK (dbegin<=dend),
UNIQUE (name,year,semester) UNIQUE (name,year,semester)
); );
...@@ -21,16 +24,21 @@ CREATE TABLE subscribe ( ...@@ -21,16 +24,21 @@ CREATE TABLE subscribe (
/** Test dataset **/ /** Test dataset **/
INSERT INTO api VALUES ( INSERT INTO api VALUES (
1,'Poésie et ingénierie',2019,'H' 1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd')
); );
INSERT INTO api VALUES ( INSERT INTO api VALUES (
2,'Cloud big data blockchain IA',2019,'H' 2,'Cloud big data blockchain IA',2019,'H',TO_DATE('20190125','yyyymmdd'),TO_DATE('20190131','yyyymmdd')
); );
INSERT INTO subscribe VALUES ( INSERT INTO subscribe VALUES (
'crozatst',1,TO_DATE('20181018','YYYYMMDD') 'crozatst',1,TO_DATE('20181018','YYYYMMDD')
); );
CREATE VIEW vSubscrition AS CREATE OR REPLACE VIEW vApi AS
SELECT ap.code, ap.name, ap.year, ap.semester, su.subdate, su.utclogin FROM SELECT ap.code, ap.name, ap.year, ap.semester, TO_CHAR(ap.dbegin,'TMDay FMDD TMMonth') AS dbegin, TO_CHAR(ap.dend,'TMDay FMDD TMMonth') AS dend
subscribe su JOIN api ap ON ap.code=su.api FROM api ap
ORDER BY ap.year, ap.semester, su.utclogin, ap.code; ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code;
CREATE OR REPLACE VIEW vSubscrition AS
SELECT ap.*, TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, su.utclogin
FROM subscribe su JOIN vApi ap ON ap.code=su.api
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code, su.utclogin;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment