Merge branch 'statistics'

This commit is contained in:
Unknown 2018-03-01 15:57:43 +01:00
commit 8e7694502e
5 changed files with 107 additions and 17 deletions

View File

@ -54,6 +54,8 @@ class Excel
$allUE = []; $allUE = [];
//array containing all the formations //array containing all the formations
$allFormations = []; $allFormations = [];
//can the current UE have a default formation
$isDefaultFormationPossible = false;
/* /*
* declare the lambda that will add finalized UE to the array * declare the lambda that will add finalized UE to the array
@ -78,11 +80,12 @@ class Excel
* declaring the lambda tha twill extract the list of formation involved in the group * declaring the lambda tha twill extract the list of formation involved in the group
*/ */
$getFormations = function(?string $group) use (&$formation,&$allFormations) : array{ $getFormations = function(?string $group) use (&$formation,&$allFormations) : array{
if(!$group){ $group = trim($group);
if($group == ""){
if(!isset($allFormations[$formation])){ if(!isset($allFormations[$formation])){
$allFormations[$formation] = [ $allFormations[$formation] = [
"name" => $formation, "name" => $formation,
"internal" => 1 "internal" => strpos($formation,"Info") !== false ? true : false
]; ];
} }
return [$formation]; return [$formation];
@ -129,7 +132,7 @@ class Excel
}; };
$exitWithNullException = function(){ $exitWithNullException = function(){
exit(json_encode(["error" => true, "message" => "NullCelException"])); exit(json_encode(["error" => true, "message" => "NullCellException"]));
}; };
//starting the iteration //starting the iteration
@ -167,6 +170,8 @@ class Excel
$UE["TpVH"] = ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0.0; $UE["TpVH"] = ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0.0;
$UE["TpGroup"] = ($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0; $UE["TpGroup"] = ($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0;
$UE["defaultFormation"] = null;
$isDefaultFormationPossible = true;
continue; continue;
} }
@ -178,33 +183,60 @@ class Excel
]; ];
//compute Course //compute Course
if (($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ if (is_numeric(($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){
$UE["groups"]["Course"][] = [ $group = [
"VH" => ($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "VH" => ($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"professor" => ($UESpreadsheet->getCellByColumnAndRow(7,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null "professor" => ($UESpreadsheet->getCellByColumnAndRow(7,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null
]; ];
if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){
$UE["defaultFormation"] = $group["formations"][0];
}else{
$UE["defaultFormation"] = null;
$isDefaultFormationPossible = false;
}
$UE["groups"]["Course"][] = $group;
} }
//compute TDs //compute TDs
if(($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ if(is_numeric(($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){
$UE["groups"]["TD"][] = [ $group = [
"VH" => ($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "VH" => ($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"professor" => ($UESpreadsheet->getCellByColumnAndRow(10,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null "professor" => ($UESpreadsheet->getCellByColumnAndRow(10,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null
]; ];
if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){
$UE["defaultFormation"] = $group["formations"][0];
}else{
$UE["defaultFormation"] = null;
$isDefaultFormationPossible = false;
}
$UE["groups"]["TD"][] = $group;
} }
//compute TPs //compute TPs
if(($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ if(is_numeric(($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){
$UE["groups"]["TP"][] = [ $group = [
"VH" => ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "VH" => ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()),
"professor" => ($UESpreadsheet->getCellByColumnAndRow(13,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null "professor" => ($UESpreadsheet->getCellByColumnAndRow(13,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null
]; ];
if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){
$UE["defaultFormation"] = $group["formations"][0];
}else{
$UE["defaultFormation"] = null;
$isDefaultFormationPossible = false;
}
$UE["groups"]["TP"][] = $group;
} }
} }
@ -307,12 +339,22 @@ class Excel
$tpRepo = Repo::getRepo("tp"); $tpRepo = Repo::getRepo("tp");
foreach ($allUE as $codeUE => $UE){ foreach ($allUE as $codeUE => $UE){
if($UE["defaultFormation"]){
$UE["defaultFormationId"] = $allFormations[$UE["defaultFormation"]]["dbId"];
}else{
$UE["defaultFormationId"] = null;
}
$ueRepo->create(utf8_decode($codeUE), $ueRepo->create(utf8_decode($codeUE),
utf8_decode($UE["name"]), utf8_decode($UE["name"]),
$UE["required"] == "OBL", $UE["required"] == "OBL",
$UE["CourseVH"], $UE["CourseVH"],
$UE["TdVH"], $UE["TdVH"],
$UE["TpVH"]); $UE["TpVH"],
false,
$UE["defaultFormationId"]
);
if(isset($UE["groups"])){ if(isset($UE["groups"])){
foreach ($UE["groups"] as $type => $groups){ foreach ($UE["groups"] as $type => $groups){
foreach ($groups as $group){ foreach ($groups as $group){

View File

@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 27/02/18
* Time: 17:31
*/
namespace api\module;
use database\core\Repo;
class Formation
{
public static function get($args){
$idForm = 0;
extract($args);
/** @var \database\repo\formation $repo */
$repo = Repo::getRepo("formation");
return ["data" => $repo->getStat($idForm)];
}
}

View File

@ -42,4 +42,24 @@ class formation extends Repo_i {
]); ]);
} }
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() ?: [];
}
} }

View File

@ -102,7 +102,7 @@ class professor extends Repo_i {
"idProf" => $id "idProf" => $id
]); ]);
return $st->fetch(); return $st->fetch() ?: [];
} }
} }

View File

@ -13,9 +13,9 @@ use database\core\Repo_i;
class ue extends Repo_i { class ue extends Repo_i {
public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false) : int { public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false, ?int $defaultFormation = null) : int {
$st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled) $st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled, Formation_idFormation)
VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled) "); VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled, :idFormation) ");
$st->execute([ $st->execute([
"code" => $code, "code" => $code,
@ -24,7 +24,8 @@ class ue extends Repo_i {
"volCours" => $volumeCours, "volCours" => $volumeCours,
"volTD" => $volumeTD, "volTD" => $volumeTD,
"volTP" => $volumeTP, "volTP" => $volumeTP,
"disabled" => $disabled ? 1 : 0 "disabled" => $disabled ? 1 : 0,
"idFormation" => $defaultFormation
]); ]);
return $this->pdo->lastInsertId(); return $this->pdo->lastInsertId();