2009-09-09 02:38:57 +00:00
< ?
function db_update_131_pre ()
{
2025-01-29 03:30:48 +00:00
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
2009-09-09 02:38:57 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( 'SELECT * FROM sponsors' );
$q -> execute ();
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
$total = 0 ;
2025-02-09 17:24:37 +00:00
$awardq = $pdo -> prepare ( " SELECT * FROM award_awards WHERE sponsors_id=? AND year=? " );
$awardq -> execute ([ $r -> id , $year ]);
2025-01-29 03:30:48 +00:00
while ( $awardr = $awardq -> fetch ( PDO :: FETCH_OBJ )) {
2025-02-09 17:24:37 +00:00
$prizeq = $pdo -> prepare ( " SELECT cash,scholarship,value,number FROM award_prizes WHERE award_awards_id=? " );
$prizeq -> execute ([ $awardr -> id ]);
2025-01-29 03:30:48 +00:00
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 ;
2009-09-09 02:38:57 +00:00
}
}
echo " Creating sponsorship for ID: $r->id value: $total\n " ;
2024-12-12 16:24:45 -05:00
$pdo -> prepare ( " INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES (
2025-02-09 17:24:37 +00:00
? ,
2009-10-22 16:46:32 +00:00
'sfawards' ,
2025-02-09 17:24:37 +00:00
? ,
2009-09-09 02:38:57 +00:00
'pending' ,
'25' ,
2025-02-09 17:24:37 +00:00
? ) " );
$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 ]);
2009-09-09 02:38:57 +00:00
}
}
?>