diff --git a/build/api/core/Checker.php b/build/api/core/Checker.php index 6e117da..63f338b 100755 --- a/build/api/core/Checker.php +++ b/build/api/core/Checker.php @@ -44,6 +44,10 @@ // On recupere le sous-type si défini $flags = isset($match[3]) ? explode(',', substr($match[3], 1)) : null; + // Si numeric -> to String + if( is_numeric($value) ) + $value = (string) $value; + // On effectue la verification de taille $lenCheck = $checker && is_string($value) && strlen($value) <= $max && strlen($value) >= $min; @@ -91,6 +95,11 @@ return $checker && is_numeric($value) && $value <= 2147483647 && $value >= 0; break; + // Entier relatif (neg ou pos) + case 'int': + return $checker && is_int($value); + break; + // String quelconque (peut etre vide) case 'text': return $checker && is_string($value); @@ -143,7 +152,7 @@ break; case "float": - return $checker && is_float($value); + return $checker && ( is_int($value) || is_float($value) ); break; default: diff --git a/build/api/module/ueController.php b/build/api/module/ueController.php index 8cb9846..66da246 100644 --- a/build/api/module/ueController.php +++ b/build/api/module/ueController.php @@ -42,4 +42,129 @@ class ueController{ } + /* (2) Creates a new UE + * + * @code The code of the UE + * @label The UE label (name) + * @required If the UE is required + * @volumeCours The UE required volume of COURSES + * @volumeTD The UE required volume of TD + * @volumeTP The UE required volume of TP + * @disabled [OPT] If it is disabled + * @defaultFormation [OPT] If there is a foreign key for a default formation (if only one formation) + * + * @return created_code The created UE code (if no error) + * + ---------------------------------------------------------*/ + public static function post($args){ + $code = ""; + $label = ""; + $required = false; + $volumeCours = 0; + $volumeTD = 0; + $volumeTP = 0; + $disabled = true; + $defaultFormation = -1; + extract($args); + + /* Get the ue repo */ + /** @var ue $ue_repo */ + $ue_repo = Repo::getRepo('ue'); + + /* (1) Check if ue code already exists */ + $exists = $ue_repo->get($code); + + /* (2) If found -> already exists */ + if( count($exists) > 0 ) + return ['error' => new Error(Err::AlreadyExists)]; + + /* (3) Else try to create */ + $repo_rtn = $ue_repo->create( + $code, + $label, + $required, + $volumeCours, + $volumeTD, + $volumeTP, + $disabled, + is_int($defaultFormation) && $defaultFormation < 0 ? null : $defaultFormation + ); + + + /* (4) If repo error -> return it */ + if( is_null($repo_rtn) ) + return ['error' => new Error(Err::RepoError)]; + + + /* (5) Else return UID */ + return ['created_code' => $repo_rtn]; + + } + + + /* (3) Deletes an existing UE + * + * @code The UE code + * + * @return deleted Whether it has been removed + * + ---------------------------------------------------------*/ + public static function delete($args){ + $code = ''; + extract($args); + + /* Get the ue repo */ + /** @var ue $ue_repo */ + $ue_repo = Repo::getRepo('ue'); + + /* (1) Try to delete */ + return ['deleted' => $ue_repo->delete($code)]; + + } + + + /* (4) Edits an existing UE + * + * @code The code of the UE + * @label [OPT] The UE label (name) + * @required [OPT] If the UE is required + * @volumeCours [OPT] The UE required volume of COURSES + * @volumeTD [OPT] The UE required volume of TD + * @volumeTP [OPT] The UE required volume of TP + * @disabled [OPT] If it is disabled + * @defaultFormation [OPT] default formation for this UE (-1 to unset, NULL to ignore) + * + * @return updated Whether it has been updated + * + ---------------------------------------------------------*/ + public static function put($args){ + $code = ""; + $label = ""; + $required = false; + $volumeCours = 0; + $volumeTD = 0; + $volumeTP = 0; + $disabled = true; + $defaultFormation = null; + extract($args); + + /* Get the ue repo */ + /** @var ue $ue_repo */ + $ue_repo = Repo::getRepo('ue'); + + /* (1) Try to update */ + return ['updated' => $ue_repo->update( + $code, + $label, + $required, + $volumeCours, + $volumeTD, + $volumeTP, + $disabled, + $defaultFormation + )]; + + } + + } \ No newline at end of file diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 567231d..b161ede 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -221,21 +221,25 @@ class professor extends Repo_i { /* (1) Prepare Statement */ $st = $this->pdo->prepare("SELECT * FROM `Professeur` WHERE `casLogin` = :cas_login"); - /* (2) Bind params and execute statement */ + /* (2) Check if statement error */ + if( is_bool($st) ) + return NULL; + + /* (3) Bind params and execute statement */ $success = $st->execute([ ':cas_login' => $cas_login ]); - /* (3) Manage error */ + /* (4) Manage error */ if( !$success ) return NULL; - /* (4) Get data */ + /* (5) Get data */ $fetched = $st->fetch(); - /* (5) Return NULL on no result */ + /* (6) Return NULL on no result */ if( $fetched === false ) return NULL; - /* (6) Return data */ + /* (7) Return data */ return $fetched; } diff --git a/build/database/repo/ue.php b/build/database/repo/ue.php index 2c0f82c..d9e6e0e 100644 --- a/build/database/repo/ue.php +++ b/build/database/repo/ue.php @@ -18,16 +18,17 @@ class ue extends Repo_i { * * @code The code of the UE * @label The UE label (name) + * @required If the UE is required * @volumeCours The UE required volume of COURSES * @volumeTD The UE required volume of TD * @volumeTP The UE required volume of TP - * @disabled If it is disabled - * @defaultFormation If there is a foreign key for a default formation (if only one formation) + * @disabled [OPT] If it is disabled + * @defaultFormation [OPT] If there is a foreign key for a default formation (if only one formation) * * @return created_code Code of the created UE (NULL on error) * ---------------------------------------------------------*/ - public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false, ?int $defaultFormation = null) : ?int { + public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false, ?int $defaultFormation = null) : ?string { /* (1) Prepare request */ $st = $this->pdo->prepare("INSERT INTO UE(`code`, `label`, `required`, `volumeCours`, `volumeTD`, `volumeTP`, `disabled`, `Formation_idFormation`) @@ -39,14 +40,14 @@ class ue extends Repo_i { /* (3) Bind params and execute request */ $success = $st->execute([ - "code" => $code, - "label" => $label, - "required" => $required ? 1 : 0, - "volCours" => $volumeCours, - "volTD" => $volumeTD, - "volTP" => $volumeTP, - "disabled" => $disabled ? 1 : 0, - "idFormation" => $defaultFormation + ':code' => $code, + ':label' => $label, + ':required' => $required ? 1 : 0, + ':volCours' => $volumeCours, + ':volTD' => $volumeTD, + ':volTP' => $volumeTP, + ':disabled' => $disabled ? 1 : 0, + ':idFormation' => $defaultFormation ]); /* (4) Manage execution error */ @@ -54,7 +55,7 @@ class ue extends Repo_i { return null; /* (5) Return insert id */ - return $this->pdo->lastInsertId(); + return $code; } @@ -68,7 +69,7 @@ class ue extends Repo_i { * @volumeTD [OPT] The UE's new volume of TD * @volumeTP [OPT] The UE's new volume of TP * @disabled [OPT] Whether the UE is disabled - * @defaultFormation [OPT] The default formation foreign key + * @defaultFormation [OPT] The default formation foreign key (-1 to unset) * * @return updated Whether the update have been successful * @@ -80,15 +81,25 @@ class ue extends Repo_i { $bind_param = [ ':code' => $code ]; if( !is_null($label) ){ $build_rq[] = '`label` = :label'; $bind_param[':label'] = $label; } - if( !is_null($required) ){ $build_rq[] = '`required` = :required'; $bind_param[':required'] = $required; } + if( !is_null($required) ){ $build_rq[] = '`required` = :required'; $bind_param[':required'] = $required?1:0; } if( !is_null($volumeCours) ){ $build_rq[] = '`volumeCours` = :volumeCours'; $bind_param[':volumeCours'] = $volumeCours; } if( !is_null($volumeTD) ){ $build_rq[] = '`volumeTD` = :volumeTD'; $bind_param[':volumeTD'] = $volumeTD; } if( !is_null($volumeTP) ){ $build_rq[] = '`volumeTP` = :volumeTP'; $bind_param[':volumeTP'] = $volumeTP; } - if( !is_null($disabled) ){ $build_rq[] = '`disabled` = :disabled'; $bind_param[':disabled'] = $disabled; } - if( !is_null($defaultFormation) ){ $build_rq[] = '`Formation_idFormation` = :defaultFormation'; $bind_param[':defaultFormation'] = $defaultFormation; } + if( !is_null($disabled) ){ $build_rq[] = '`disabled` = :disabled'; $bind_param[':disabled'] = $disabled?1:0; } + + // not null @defaultFormation -> set it + if( !is_null($defaultFormation) ){ + + // if @defaultFormation is (-1) -> unset + if( $defaultFormation < 0 ){ $build_rq[] = '`Formation_idFormation` = NULL'; } + // else -> set to new value + else{ $build_rq[] = '`Formation_idFormation` = :defaultFormation'; $bind_param[':defaultFormation'] = $defaultFormation; } + + } + /* (2) ERROR if no updated field */ - if( count($build_rq) <= 0 || count($bind_param) <= 1 ) + if( count($build_rq) <= 0 ) return FALSE; /* (3) Build request */ @@ -160,14 +171,19 @@ class ue extends Repo_i { * @return ues The UEs matching code (NULL on error) * ---------------------------------------------------------*/ - public function get(?String $code=null) : ?array{ + public function get(?String $code=null) : array{ /* (1) Manage if no id given */ - $cond = is_null($code) ? '' : ' WHERE `code` = :code'; + $cond = is_null($code) ? '' : 'WHERE `code` = :code'; $parm = is_null($code) ? [] : [':code' => $code]; /* (2) Prepare Statement */ - $st = $this->pdo->prepare("SELECT * FROM `UE`$cond GROUP BY `label` ASC"); + $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $st = $this->pdo->prepare("SELECT ue.code, ue.label, ue.disabled, ue.required, ue.volumeCours, ue.volumeTD, ue.volumeTP, IFNULL(ue.Formation_idFormation, -1) idForm, f.labelFormation labelForm + FROM `UE` ue + LEFT JOIN Formation f ON ue.Formation_idFormation = f.idFormation + $cond + ORDER BY `ue`.`label` ASC"); /* (3) Bind params and execute statement */ if( is_bool($st) ) return []; diff --git a/config/modules.json b/config/modules.json index 61c2d2a..4f744ef 100644 --- a/config/modules.json +++ b/config/modules.json @@ -185,17 +185,17 @@ "des": "Creates a new UE", "per": [], "par": { - "code": { "des": "UE code.", "typ": "varchar(2,30,alphanumeric)" }, - "label": { "des": "UE label", "typ": "varchar(2,30,alphanumeric)" }, - "required": { "des": "If UE is required", "typ": "bool" }, - "volumeCours": { "des": "Number of course hours for UE", "typ": "float" }, - "volumeTD": { "des": "Number of TD hours for UE", "typ": "float" }, - "volumeTP": { "des": "Number of TP hours for UE", "typ": "float" }, - "disabled": { "des": "Whether UE is disabled", "typ": "boolean" }, - "defaultFormation": { "des": "UID for optional default formation", "typ": "id", "opt": true } + "code": { "des": "UE code.", "typ": "varchar(4,20,alphanumeric)" }, + "label": { "des": "UE label", "typ": "varchar(4,30,alphanumeric)" }, + "required": { "des": "If UE is required", "typ": "bool" }, + "volumeCours": { "des": "Number of course hours for UE", "typ": "float" }, + "volumeTD": { "des": "Number of TD hours for UE", "typ": "float" }, + "volumeTP": { "des": "Number of TP hours for UE", "typ": "float" }, + "disabled": { "des": "Whether UE is disabled", "typ": "boolean" }, + "defaultFormation": { "des": "UID for optional default formation (-1 if none)", "typ": "int", "opt": true, "def": -1 } }, "out": { - "created_code": { "des": "Created UE code", "typ": "varchar(2,30,alphanumeric)" } + "created_code": { "des": "Created UE code", "typ": "varchar(4,20,alphanumeric)" } } }, @@ -203,11 +203,41 @@ "des": "Get one or all UE", "per": [], "par": { - "URL0": { "des": "Optional UE code.", "typ": "varchar(2,30,alphanumeric)", "ren": "code", "opt": true } + "URL0": { "des": "Optional UE code.", "typ": "varchar(4,20,alphanumeric)", "ren": "code", "opt": true } }, "out": { "ues": { "des": "UE list", "typ": "array" } } + }, + + + "DELETE": { + "des": "Deletes an existing UE", + "per": [], + "par": { + "URL0": { "des": "UE code.", "typ": "varchar(4,20,alphanumeric)", "ren": "code" } + }, + "out": { + "deleted": { "des": "Whether it has been deleted", "typ": "boolean" } + } + }, + + "PUT": { + "des": "Edits an existing UE", + "per": [], + "par": { + "URL0": { "des": "UE code.", "typ": "varchar(4,20,alphanumeric)", "ren": "code" }, + "label": { "des": "UE label", "typ": "varchar(4,30,alphanumeric)", "opt": true }, + "required": { "des": "If UE is required", "typ": "bool", "opt": true }, + "volumeCours": { "des": "Number of course hours for UE", "typ": "float", "opt": true }, + "volumeTD": { "des": "Number of TD hours for UE", "typ": "float", "opt": true }, + "volumeTP": { "des": "Number of TP hours for UE", "typ": "float", "opt": true }, + "disabled": { "des": "Whether UE is disabled", "typ": "boolean", "opt": true }, + "defaultFormation": { "des": "UID for optional default formation (-1 for none)", "typ": "int", "opt": true } + }, + "out": { + "updated": { "des": "Whether the UE has been updated", "typ": "boolean" } + } } diff --git a/public_html/asset/svg/bell.svg b/public_html/asset/svg/bell.svg new file mode 100644 index 0000000..822f455 --- /dev/null +++ b/public_html/asset/svg/bell.svg @@ -0,0 +1,44 @@ + +image/svg+xml \ No newline at end of file diff --git a/webpack/component/teacher/view.vue b/webpack/component/teacher/view.vue index dae6a93..401e99c 100644 --- a/webpack/component/teacher/view.vue +++ b/webpack/component/teacher/view.vue @@ -59,7 +59,7 @@
-
+
diff --git a/webpack/component/ue/view.vue b/webpack/component/ue/view.vue index c549486..a51c9e3 100644 --- a/webpack/component/ue/view.vue +++ b/webpack/component/ue/view.vue @@ -1,38 +1,110 @@