forked from science-ation/science-ation
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?
|
|
|
|
function db_update_122_post()
|
|
{
|
|
global $config, $pdo;
|
|
$year = $config['FAIRYEAR'];
|
|
$q = $pdo->prepare("SELECT * FROM judges_timeslots WHERE year=?");
|
|
$q->execute([$year]);
|
|
$round = array();
|
|
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
|
|
$type = $r['type'];
|
|
|
|
if (!array_key_exists($type, $round)) {
|
|
$round[$type]['starttime'] = $r['starttime'];
|
|
$round[$type]['endtime'] = $r['endtime'];
|
|
$round[$type]['date'] = $r['date'];
|
|
}
|
|
|
|
if ($r['starttime'] < $round[$type]['starttime']) {
|
|
$round[$type]['starttime'] = $r['starttime'];
|
|
}
|
|
|
|
if ($r['endtime'] > $round[$type]['endtime']) {
|
|
$round[$type]['endtime'] = $r['endtime'];
|
|
}
|
|
}
|
|
|
|
foreach ($round as $type => $d) {
|
|
$stmt = $pdo->prepare("INSERT INTO judges_timeslots (round_id,type,date,starttime,endtime,year)
|
|
VALUES ('0',?,?,?,?,?)");
|
|
$stmt->execute([$type,$d['date'],$d['starttime'],$d['endtime'],$year]);
|
|
$round_id = $pdo->lastInsertId();
|
|
|
|
$stmt = $pdo->prepare("UPDATE judges_timeslots SET
|
|
round_id=?, type='timeslot'
|
|
|
|
WHERE type=? AND year=?");
|
|
$stmt->execute([$round_id,$type,$year]);
|
|
/* Undo the set we just did to the round we just inserted */
|
|
$stmt = $pdo->prepare("UPDATE judges_timeslots SET
|
|
round_id='0',type=?
|
|
|
|
WHERE id=?");
|
|
$stmt->execute([$type,$round_id]);
|
|
}
|
|
}
|
|
|
|
?>
|