Now saved location (to correct)

This commit is contained in:
xdrm-brackets 2017-09-15 20:04:04 +02:00
parent 5e2bd71411
commit ca7f5bbc6a
2 changed files with 73 additions and 26 deletions

View File

@ -177,22 +177,59 @@
// {6} Exctract event's image // // {6} Exctract event's image //
$ev = $this->extractEvent("$time-$uid", [$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]); $ev = $this->extractEvent("$time-$uid", [$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]);
$this->event[$uid][$time][1] = $ev[0];
$this->event[$uid][$time][2] = $ev[1];
$this->event[$uid][$time][3] = $color;
// {7} Check if already exists // /* {7} Check @event if already exists */ {
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT basename, color, id_diplome FROM event WHERE basename = :bd AND color = :c AND id_diplome = :idd");
$sqlr->execute([ ':bd' => $ev[0], ':c' => $color, ':idd' => $this->d_uid ]);
// {7.1} If does not -> insert // $read_name = is_null($ev['name']) ? '?' : $ev['name'];
if( !$sqlr->fetch() ){
$sqlr = DatabaseDriver::getPDO()->prepare("INSERT INTO event(id_event,basename,color,id_diplome,name) VALUES(DEFAULT,:bd,:c,:idd,:n)"); $sqlr = DatabaseDriver::getPDO()->prepare("SELECT id_event FROM event WHERE basename = :bn AND color = :c AND id_diplome = :idd");
$sqlr->execute([ ':bd' => $ev[0], ':c' => $color, ':idd' => $this->d_uid, ':n' => $ev[0] ]); $sqlr->execute([ ':bn' => $read_name, ':c' => $color, ':idd' => $this->d_uid ]);
$fetched = $sqlr->fetch();
// {7.1} If not found in db -> insert //
if( !$fetched ){
// {7.2} Insert new event //
$sqlr = DatabaseDriver::getPDO()->prepare("INSERT INTO event(id_event,basename,color,id_diplome,name) VALUES(DEFAULT,:bn,:c,:idd,:n)");
$sqlr->execute([ ':c' => $color, ':idd' => $this->d_uid, ':bn' => $read_name, ':n' => $read_name ]);
// {7.3} Store id in current event //
$event_id = DatabaseDriver::getPDO()->lastInsertId();
}else
$event_id = $fetched['id_event'];
} }
/* (8) Check @location if already exists */ {
$read_location = is_null($ev['location']) ? '?' : $ev['location'];
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT id_location FROM location WHERE basename = :bn AND id_event = :ide");
$sqlr->execute([ ':bn' => $read_location, ':ide' => $event_id ]);
$fetched = $sqlr->fetch();
// {8.1} If not found in db -> insert //
if( !$fetched ){
// {8.2} Insert new location //
$sqlr = DatabaseDriver::getPDO()->prepare("INSERT INTO location(id_location,id_event,basename,name) VALUES(DEFAULT,:ide,:bn,:n)");
$sqlr->execute([ ':ide' => $event_id, ':bn' => $read_location, ':n' => $read_location ]);
// {8.3} Store id in current location //
$location_id = DatabaseDriver::getPDO()->lastInsertId();
}else
$location_id = $fetched['id_location'];
}
/* (9) Store local data for ics */
$this->event[$uid][$time][1] = $location_id;
} }
@ -246,7 +283,7 @@
/* (2) Manage copy error */ /* (2) Manage copy error */
if( !$copied ) if( !$copied )
return [ '?', null ]; return [ 'name' => null, 'location' => null ];
/* (3) Save to jpeg */ /* (3) Save to jpeg */
\imagesavealpha($clip, true); \imagesavealpha($clip, true);
@ -272,7 +309,7 @@
/* (2) Manage error */ /* (2) Manage error */
}catch(\Exception $e){ }catch(\Exception $e){
$read = [ '?', null ]; return [ 'name' => null, 'location' => null ];
} }
@ -386,14 +423,24 @@
---------------------------------------------------------*/ ---------------------------------------------------------*/
foreach($events as $start_t=>$data){ foreach($events as $start_t=>$data){
/* (1) Search if there is a correction in the database */
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT name FROM event WHERE basename = :bn AND id_diplome = :idd AND color = :col");
$sqlr->execute([ ':bn' => $data[1], ':idd' => $this->d_uid, ':col' => $data[3] ]);
/* (2) If there's a traduction */ /* (1) If a name -> Search if there is a correction in the database */
$basename=$data[1]; $sqlr = DatabaseDriver::getPDO()->prepare("SELECT e.id_event as ide, l.id_location as idl, l.id_location as idl e.name as ename, l.name as lname FROM event as e, location as l WHERE e.id_event = l.id_event AND l.id_location= :idl");
if( ($fetched=$sqlr->fetch()) ) $sqlr->execute([ ':idl' => $data[1] ]);
$data[1] = $fetched['name'];
/* (2) Default values */
$ide = -1;
$idl = -1;
$name = '?';
$location = '?';
/* (2) If a match found -> set it */
if( ($fetched=$sqlr->fetch()) ){
$ide = $fetched['ide'];
$idl = $fetched['idl'];
$name = $fetched['ename'];
$location = $fetched['lname'];
}
/* (3) Build ICS event */ /* (3) Build ICS event */
$RAW .= "BEGIN:VEVENT\n"; $RAW .= "BEGIN:VEVENT\n";
@ -401,10 +448,10 @@
$RAW .= "DTSTART:${start_t}\n"; $RAW .= "DTSTART:${start_t}\n";
$RAW .= "DTEND:${data[0]}\n"; $RAW .= "DTEND:${data[0]}\n";
$RAW .= "UID:$start_t\n"; // required $RAW .= "UID:$start_t\n"; // required
$RAW .= "DESCRIPTION:$basename${data[3]}\n"; $RAW .= "DESCRIPTION:event@$ide\n"; // event@id_event
$RAW .= "SUMMARY:${data[1]}\n"; $RAW .= "SUMMARY:$name\n";
if( !is_null($data[2]) ) $RAW .= "DESCRIPTION:location@$idl\n"; // location@id_location
$RAW .= "LOCATION:${data[2]}\n"; $RAW .= "LOCATION:$location\n";
$RAW .= "CATEGORIES: UPPA Calendar\n"; $RAW .= "CATEGORIES: UPPA Calendar\n";
$RAW .= "END:VEVENT\n"; $RAW .= "END:VEVENT\n";
} }

View File

@ -87,12 +87,12 @@
// Amphi ... // // Amphi ... //
if( preg_match('@^a[nm](?:[bp][hln])?[ir] ?(.+)$@i', $lines[$i], $m) ) // 'amphi A', 'amphi 600 droit' if( preg_match('@^a[nm](?:[bp][hln])?[ir] ?(.+)$@i', $lines[$i], $m) ) // 'amphi A', 'amphi 600 droit'
return [ $title, "Amphi ${m[1]}" ]; return [ 'name' => $title, 'location' => "Amphi ${m[1]}" ];
// S... OR 5... // // S... OR 5... //
if( preg_match('@^[S|5] ?(.+)@i', $lines[$i], $m) ) // 'S10', 'S22' if( preg_match('@^[S|5] ?(.+)@i', $lines[$i], $m) ) // 'S10', 'S22'
return [ $title, "S. ${m[1]}" ]; return [ 'name' => $title, 'location' => "S. ${m[1]}" ];
// If not 'Cours', 'CTD', 'TD', 'TP' // // If not 'Cours', 'CTD', 'TD', 'TP' //
if( preg_match('@^(co[hu][trn][s5]|t[dp|c[mn]|ct[dp])@i', $lines[$i]) ) if( preg_match('@^(co[hu][trn][s5]|t[dp|c[mn]|ct[dp])@i', $lines[$i]) )
@ -102,7 +102,7 @@
} }
return [ $title, $lines[2] ]; return [ 'name' => $title, 'location' => $lines[2] ];
} }