forked from science-ation/science-ation
42 lines
1.7 KiB
PHP
42 lines
1.7 KiB
PHP
<?
|
|
|
|
function db_update_131_pre()
|
|
{
|
|
global $config, $pdo;
|
|
$year = $config['FAIRYEAR'];
|
|
// since there's only ever been award sponsors in the system, we can
|
|
// add a sponsorship entry with a value of the total sum of the prizes given
|
|
// for each sponsor
|
|
|
|
$q = $pdo->prepare('SELECT * FROM sponsors');
|
|
$q->execute();
|
|
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
|
|
$total = 0;
|
|
$awardq = $pdo->prepare("SELECT * FROM award_awards WHERE sponsors_id=? AND year=?");
|
|
$awardq->execute([$r->id,$year]);
|
|
while ($awardr = $awardq->fetch(PDO::FETCH_OBJ)) {
|
|
$prizeq = $pdo->prepare("SELECT cash,scholarship,value,number FROM award_prizes WHERE award_awards_id=?");
|
|
$prizeq->execute([$awardr->id]);
|
|
while ($prizer = $prizeq->fetch(PDO::FETCH_OBJ)) {
|
|
// some people never set the value for some reason, i dunno why..
|
|
$realvalue = max($prizer->cash + $prizer->scholarship, $prizer->value);
|
|
$totalvalue = $realvalue * $prizer->number;
|
|
$total += $totalvalue;
|
|
}
|
|
}
|
|
echo "Creating sponsorship for ID: $r->id value: $total\n";
|
|
$pdo->prepare("INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES (
|
|
?,
|
|
'sfawards',
|
|
?,
|
|
'pending',
|
|
'25',
|
|
?)");
|
|
$pdo->execute([$r->id,$total,$year]);
|
|
$stmt = $pdo->prepare("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES (?,NOW(),0,'Automatically created sponsorship from existing sponsor. type=award, value=\$?, status=pending, probability=25%')");
|
|
$stmt->execute([$r->id,$total]);
|
|
}
|
|
}
|
|
|
|
?>
|