The professor's cas login * @firstName [OPT] The professor's firstName * @lastName [OPT] The professor's lastName * * @return created Whether the professor has been created * ---------------------------------------------------------*/ public function create_prof(String $casLogin, ?String $firstName, ?String $lastName) : bool{ /* (1) Create user in meta database ---------------------------------------------------------*/ /* (1) Try to insert user */ $st = $this->pdo->prepare("INSERT INTO meta_vhost.casUser(casLogin, firstName, lastName) VALUES(:cas_login, :first_name, :last_name)"); /* (2) Manage statement error */ if( is_bool($st) ) return FALSE; /* (3) Try to execute */ $success = $st->execute([ ':cas_login' => $casLogin, ':first_name' => $firstName, ':last_name' => $lastName ]); /* (4) Dispatch execution error */ return $success; } /* (2) Check if a professor exists (by its casLogin) * * @casLogin The professor's cas login * * @return exists Whether the professor exists * ---------------------------------------------------------*/ public function prof_exists(String $casLogin) : bool{ /* (1) Prepare Statement */ $st = $this->pdo->prepare("SELECT casLogin FROM meta_vhost.casUser WHERE casLogin = :cas_login;"); /* (2) Statement eror */ if( is_bool($st) ) return FALSE; /* (3) Bind params and execute */ $success = $st->execute([ ':cas_login' => $casLogin ]); /* (4) Manage execution error */ if( !$success ) return FALSE; /* (7) Return That it exists */ return is_array( $st->fetch() ); } /* (3) Get available departments for a CAS login * * @casLogin The professor's CAS username * * @return departments The list of available departments (empty on error) * ---------------------------------------------------------*/ public function get_prof_departments(String $casLogin) : array{ /* (1) Prepare Statement */ $st = $this->pdo->prepare("SELECT d2.iddepartement idDep, d2.label labelDep, d2.databaseName dbName FROM meta_vhost.casUser JOIN meta_vhost.linkedDep D ON casUser.casLogin = D.casUser_casLogin JOIN meta_vhost.departement d2 ON D.departement_iddepartement = d2.iddepartement WHERE casLogin = :cas_login"); /* (2) Check if statement error */ if( is_bool($st) ) return []; /* (3) Bind params and execute sstatement */ $success = $st->execute([ ':cas_login' => $casLogin ]); /* (4) Manage error */ if( !$success ) return []; /* (5) Get data */ $fetched = $st->fetchAll(); /* (6) Return [] on no result */ if( $fetched === false ) return []; /* (7) Return data */ return $fetched; } /* (4) Deletes a professor * * @casLogin The professor's CAS username * * @return deleted Whether the professor have been deleeted successfully * ---------------------------------------------------------*/ public function delete_prof(String $casLogin) : bool{ /* (1) Prepare statement */ $st = $this->pdo->prepare('DELETE FROM meta_vhost.casUser WHERE casLogin = :cas_login'); /* (2) Manage statement error */ if( is_bool($st) ) return FALSE; /* (3) Try to execute */ $success = $st->execute([ ':cas_login' => $casLogin ]); /* (4) Dispatch execution error */ return $success; } /* (5) Check if a link exists * * @casLogin The professor's cas login * @idDep The department id * * @return exists Whether the professor exists * ---------------------------------------------------------*/ public function link_exists(String $casLogin, int $idDep) : bool{ /* (1) Prepare Statement */ $st = $this->pdo->prepare("SELECT * FROM meta_vhost.linkedDep WHERE departement_iddepartement = :id_dep AND casUser_casLogin = :cas_login"); /* (2) Statement eror */ if( is_bool($st) ) return FALSE; /* (3) Bind params and execute */ $success = $st->execute([ ':id_dep' => $idDep, ':cas_login' => $casLogin ]); /* (4) Manage execution error */ if( !$success ) return FALSE; /* (7) Return That it exists */ return is_array( $st->fetch() ); } /* (6) Associates a professor to a department * * @casLogin The professor's CAS username * @idDep The department id * * @return linked Whether the link have been created * ---------------------------------------------------------*/ public function link(String $casLogin, int $idDep) : bool{ /* (1) Prepare statement */ $st = $this->pdo->prepare("INSERT INTO meta_vhost.linkedDep(departement_iddepartement, casUser_casLogin) VALUES(:id_dep, :cas_login);"); /* (2) Manage statement error */ if( is_bool($st) ) return FALSE; /* (3) Try to execute request */ $success = $st->execute([ ':id_dep' => $idDep, ':cas_login' => $casLogin ]); /* (4) Dispatch execution error */ return $success; } /* (7) Remove a department from a professor * * @casLogin The professor's CAS username * @idDep The department id * * @return unlinked Whether the link have been removed * ---------------------------------------------------------*/ public function unlink(String $casLogin, int $idDep) : bool{ /* (1) Prepare statement */ $st = $this->pdo->prepare("DELETE FROM meta_vhost.linkedDep WHERE departement_iddepartement = :id_dep AND casUser_casLogin = :cas_login;"); /* (2) Manage statement error */ if( is_bool($st) ) return FALSE; /* (3) Try to execute request */ $success = $st->execute([ ':id_dep' => $idDep, ':cas_login' => $casLogin ]); /* (4) Dispatch execution error */ return $success; } }