Commit c3e66a37 authored by Stephane Crozat's avatar Stephane Crozat

Ajout indicateur #21

parent c90b6f8e
......@@ -132,7 +132,7 @@ class DB {
}
public function apiListResp($admin, $utclogin) {
$sql = 'SELECT *
$sql = 'SELECT *, indicator(utclogin, week, year) AS indicator
FROM vsubscription
WHERE semester=:semester AND year=:year AND resplogin=:resp' ;
$st = $this->conn->prepare($sql);
......
......@@ -148,7 +148,7 @@ class Views {
}
else if (is_null($sub['validation'])) {
// At least one waiting subscription
echo "<p> <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]</a> ".$this->printStudent($sub)."</p>";
echo "<p> <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]</a> ".$this->printStudent($sub)." <span>Exclusivité : $sub[indicator]%</span></p>";
}
else {
// validation = FALSE lignes ignored
......
......@@ -12,13 +12,16 @@ INSERT INTO localuser (utclogin) VALUES ('dore');
INSERT INTO localuser (utclogin) VALUES ('nsalzman');
INSERT INTO localuser (utclogin) VALUES ('dauzatbr');
INSERT INTO localuser (utclogin) VALUES ('jlaforet');
INSERT INTO localuser (utclogin) VALUES ('icaillea');
INSERT INTO api ( id, dbegin, code, name, description, duration, size, ects, resplogin) VALUES (
'1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',
TO_DATE('20190701','yyyymmdd'),1,'Poésie et ingénierie','Lorem ipsum dolor sit amet',5,3,2,'crozatst'
'1006e8dc-2178-11e9-8edb-4bc5e8f8599c',
TO_DATE('20190701','yyyymmdd'),1,'Concevoir une formation','Concevoir et animer une formation courte',3,4,1,'icaillea'
);
INSERT INTO api ( id, dbegin, code, name, description, duration, size, ects, resplogin) VALUES (
'5e06e8dc-2178-11e9-8edb-4bc5e8f8599c',
TO_DATE('20190701','yyyymmdd'),5,'Poésie et ingénierie','Lorem ipsum dolor sit amet',5,3,2,'crozatst'
);
INSERT INTO api VALUES (
'2afa8472-2178-11e9-b2b0-07511495b3b2',
......@@ -59,8 +62,8 @@ INSERT INTO api VALUES (
);
INSERT INTO api VALUES (
'1052b3a0-217d-11e9-aabc-037b6e1a6a16',
TO_DATE('20190708','yyyymmdd'),10,'Habilitation électrique','Formation préalable à l''habilitation électrique.',5,2,2,'dauzatbr'
'8882b3a0-217d-11e9-aabc-037b6e1a6a16',
TO_DATE('20190708','yyyymmdd'),8,'Habilitation électrique','Formation préalable à l''habilitation électrique.',5,2,2,'dauzatbr'
);
INSERT INTO api VALUES (
......@@ -74,13 +77,13 @@ INSERT INTO api VALUES (
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'dore','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
'dore','5e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'sdesterc','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
'sdesterc','5e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'nsalzman','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
'nsalzman','5e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'dore','2afa8472-2178-11e9-b2b0-07511495b3b2',TO_DATE('20190121','yyyymmdd')
......
......@@ -6,6 +6,56 @@ CREATE OR REPLACE FUNCTION unaccent_string(TEXT) RETURNS TEXT AS $$
);
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION nb_api(TEXT, TEXT) RETURNS INTEGER AS $$
/* Returns number of api for one week and year */
DECLARE
w ALIAS FOR $1;
y ALIAS FOR $2;
c INTEGER;
BEGIN
SELECT COUNT(*) INTO c
FROM vapi
WHERE week=w AND year=y;
RETURN c;
END;
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION nb_sub(TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
/* Returns number of subsciption for one student for one week and year */
DECLARE
student ALIAS FOR $1;
w ALIAS FOR $2;
y ALIAS FOR $3;
c INTEGER;
BEGIN
SELECT COUNT(*) INTO c
FROM vsubscription
WHERE utclogin=student AND week=w AND year=y;
RETURN c;
END;
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION indicator(TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
/* Returns indicator one student for one week and year */
DECLARE
student ALIAS FOR $1;
w ALIAS FOR $2;
y ALIAS FOR $3;
nb_sub FLOAT;
nb_api FLOAT;
BEGIN
nb_sub = nb_sub(student,w,y);
nb_api = nb_api(w,y);
IF nb_sub = 0 THEN
RETURN -1;
ELSIF nb_sub = 1 THEN
RETURN 100;
ELSE
RETURN 100 * (1 - (nb_sub / nb_api));
END IF;
END;
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION is_available(TEXT, TEXT, TEXT) RETURNS BOOLEAN AS $$
/* Returns True if student has no api validated for same week and year */
DECLARE
......
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