Add formations to output JSON

This commit is contained in:
Unknown 2018-02-20 20:20:23 +01:00 committed by SeekDaSky
parent 5262318527
commit 1b0a52ded6
1 changed files with 23 additions and 9 deletions

View File

@ -22,6 +22,7 @@ class Excel
public function post($args){
if(isset($_FILES["file"]["tmp_name"])){
//put everything in a try so we catch all PhpExcel exceptions and return a clean API Response
try{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$reader->setReadDataOnly(true);
@ -42,6 +43,8 @@ class Excel
$UE = [];
//array containing all the UEs
$allUE = [];
//array containing all the formations
$allFormations = [];
/*
* declare the lambda that will add finalized UE to the array
@ -65,7 +68,7 @@ class Excel
/*
* declaring the lambda tha twill extract the list of formation involved in the group
*/
$getFormations = function(?string $group) use (&$formation) : array{
$getFormations = function(?string $group) use (&$formation,&$allFormations) : array{
if(!$group) return [$formation];
//replace the generic "INFO" keyword by the actual formation
@ -78,7 +81,18 @@ class Excel
$groups = array_map('trim', $groups);
//delete empty strings
return array_filter($groups);
$groups = array_filter($groups);
foreach ($groups as $group){
if(!isset($allFormations[$group])){
$allFormations[$group] = [
"name" => $group,
"internal" => strpos(strtolower($group),"info") !== false ? true : false
];
}
}
return $groups;
};
/*
@ -146,8 +160,8 @@ class Excel
if ($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex())->getCalculatedValue()){
$UE["groups"]["Course"][] = [
"VH" => $UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getValue()),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getCalculatedValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getCalculatedValue()),
"professor" => $UESpreadsheet->getCellByColumnAndRow(7,$row->getRowIndex())->getValue() ?: null
];
}
@ -156,8 +170,8 @@ class Excel
if($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex())->getCalculatedValue()){
$UE["groups"]["TD"][] = [
"VH" => $UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex())->getValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getValue()),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex())->getCalculatedValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getCalculatedValue()),
"professor" => $UESpreadsheet->getCellByColumnAndRow(10,$row->getRowIndex())->getValue() ?: null
];
}
@ -166,8 +180,8 @@ class Excel
if($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex())->getCalculatedValue()){
$UE["groups"]["TP"][] = [
"VH" => $UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex())->getCalculatedValue(),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex())->getValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getValue()),
"internalStudentPart" => $getInternalStudentPart($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex())->getCalculatedValue()),
"formations" => $getFormations($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex())->getCalculatedValue()),
"professor" => $UESpreadsheet->getCellByColumnAndRow(13,$row->getRowIndex())->getValue() ?: null
];
}
@ -222,7 +236,7 @@ class Excel
return [ 'data' => ["professors" => $allProf, "UEs" => $allUE ] ];
return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
}catch (Exception $e){
return [ 'error' => new Error(Err::UnknownError) ];
}