[repo.category] added get() usual | [repo.professor] fix..

This commit is contained in:
xdrm-brackets 2018-03-06 16:15:01 +01:00
parent 6bcccdae7f
commit 0a0135487f
2 changed files with 43 additions and 6 deletions

View File

@ -68,4 +68,41 @@ class category extends Repo_i{
}
}
/* (4) Gets a category by its UID ||| getAll
*
* @cat_id<int> [OPT] The category UID, if not set, getAll()
*
* @return categories<array> The categories matching id (NULL on error)
*
---------------------------------------------------------*/
public function get(?int $cat_id=null) : ?array{
/* (1) Manage if no id given */
$cond = is_null($cat_id) ? '' : ' WHERE `idCategorie` = :id';
$parm = is_null($cat_id) ? [] : [':id' => $cat_id];
/* (2) Prepare Statement */
$st = $this->pdo->prepare("SELECT * FROM `Categorie`$cond ORDER BY `labelCategorie` ASC");
/* (3) Bind params and execute statement */
if( is_bool($st) ) return [];
$success = $st->execute($parm);
/* (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;
}
}

View File

@ -170,14 +170,14 @@ class professor extends Repo_i {
* @return teachers<array> The professors matching id (NULL on error)
*
---------------------------------------------------------*/
public function get(?int $prof_id=null) : ?array{
public function get(?int $prof_id=null) : array{
/* (1) Manage if no id given */
$cond = is_null($prof_id) ? '' : ' WHERE `idProfesseur` = :id';
$parm = is_null($prof_id) ? [] : [':id' => $prof_id];
/* (2) Prepare Statement */
$st = $this->pdo->prepare("SELECT * FROM `Professeur`$cond GROUP BY abreviation ASC");
$st = $this->pdo->prepare("SELECT * FROM `Professeur`$cond ORDER BY abreviation ASC");
/* (3) Bind params and execute statement */
if( is_bool($st) ) return [];