diff --git a/build/router/controller/ics.php b/build/router/controller/ics.php index b33a49a..f4535e5 100644 --- a/build/router/controller/ics.php +++ b/build/router/controller/ics.php @@ -92,52 +92,55 @@ /* [1] Get events data =========================================================*/ /* (1) Get the list of available events */ - $sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd"); - $sqlr->execute([ ':idd' => $this->diplome_id ]); - $events = $sqlr->fetchAll(); + // $sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd"); + // $sqlr->execute([ ':idd' => $this->diplome_id ]); + // $events = $sqlr->fetchAll(); /* (2) Manage error */ - if( !$events ) - die("Correction not available for this diplome"); + // if( !$events ) + // die("Correction not available for this diplome"); /* [2] Get location data =========================================================*/ - foreach($events as &$event){ + // foreach($events as &$event){ - $event['location'] = []; + $location = []; /* (1) Get the list of available locations*/ - $sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM location WHERE id_event = :ide"); - $sqlr->execute([ ':ide' => $event['id_event'] ]); - $locations = $sqlr->fetchAll(); + $sqlr = DatabaseDriver::getPDO()->prepare("SELECT l.id_location as idl, l.name as name, l.basename as basename, e.name as ename, e.color as color FROM location as l, event as e WHERE l.id_event = e.id_event AND e.id_diplome = :idd GROUP BY idl, name, basename, ename, color"); + $sqlr->execute([ ':idd' => $this->diplome_id ]); + $fetched = $sqlr->fetchAll(); - if( !$locations ) - $locations = []; + if( !$fetched ){ + $fetched[] = []; + $locdata[] = []; + } - foreach($locations as $location) - $event['location'][] = $location; + foreach($fetched as $raw){ - } + if( !isset($location[$raw['ename']]) ) + $location[$raw['ename']] = []; + + $location[$raw['ename']][] = intval( $raw['idl'] ); + + $locdata[$raw['ename']] = [ $raw['name'], $raw['basename'], $raw['color'] ]; + + } + + // } echo "