65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lucas
|
|
* Date: 20/02/18
|
|
* Time: 21:35
|
|
*/
|
|
|
|
namespace database\repo;
|
|
|
|
|
|
use database\core\Repo_i;
|
|
|
|
class formation extends Repo_i {
|
|
|
|
public function create(string $label, bool $isInternal) : int{
|
|
$st = $this->pdo->prepare("INSERT INTO Formation (labelFormation, isInternal) VALUE (:label,:isInternal);");
|
|
|
|
$st->execute([
|
|
"label" => $label,
|
|
"isInternal" => $isInternal? 1 : 0
|
|
]);
|
|
|
|
return $this->pdo->lastInsertId();
|
|
}
|
|
|
|
public function exists(string $label) : int{
|
|
$st = $this->pdo->prepare("SELECT idFormation FROM Formation WHERE labelFormation = :label");
|
|
|
|
$st->execute([
|
|
"label" => $label
|
|
]);
|
|
|
|
return $st->fetch()["idFormation"]?: 0;
|
|
}
|
|
|
|
public function delete(int $id) : bool{
|
|
$st = $this->pdo->prepare("DELETE FROM Formation WHERE idFormation = :id");
|
|
|
|
return $st->execute([
|
|
"id" => $id
|
|
]);
|
|
}
|
|
|
|
public function getStat(int $id) :array{
|
|
$st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, (VHCours + VHTd + VHTp) VHTotal, Form.isInternal isInternal
|
|
FROM Formation Form,
|
|
(SELECT IFNULL(SUM(C.volume),0) VHCours, GC.Formation_idFormation idForm FROM GroupeCours GC LEFT JOIN Cours C ON GC.Cours_idCours = C.idCours GROUP BY GC.Formation_idFormation) VHCours,
|
|
(SELECT IFNULL(SUM(T.volume),0) VHTd, GTD.Formation_idFormation idForm FROM GroupeTD GTD LEFT JOIN TD T ON GTD.TD_idTD = T.idTD GROUP BY GTD.Formation_idFormation) VHTd,
|
|
(SELECT IFNULL(SUM(T2.volume),0) VHTp, GTP.Formation_idFormation idForm FROM GroupeTP GTP LEFT JOIN TP T2 ON GTP.TP_idTP = T2.idTP GROUP BY GTP.Formation_idFormation) VHTp
|
|
WHERE
|
|
Form.idFormation = :idForm AND
|
|
VHCours.idForm = Form.idFormation AND
|
|
VHTp.idForm = Form.idFormation AND
|
|
VHTd.idForm = Form.idFormation;
|
|
");
|
|
|
|
$st->execute([
|
|
"idForm" => $id
|
|
]);
|
|
|
|
return $st->fetch() ?: [];
|
|
}
|
|
|
|
} |