function LoadFromDB() { $this->party = PouetParty::spawn($_GET["which"]); if (!$this->party) return; $this->party->addeduser = PouetUser::spawn( $this->party->addedUser ); if (isset($_GET["when"])) { $this->year = $_GET["when"]; } else { $r = SQLLib::selectRow(sprintf_esc("select party_year from prods where party = %d order by rand() limit 1",$_GET["which"])); $this->year = $r->party_year; } if ($this->year < 100) { $this->year += ($this->year < 50 ? 2000 : 1900); } $this->prods = array(); $s = new BM_Query("prods"); $s->AddWhere( sprintf_esc("(prods.party = %d AND prods.party_year = %d) or (prodotherparty.party = %d AND prodotherparty.party_year = %d)",$this->party->id,$this->year,$this->party->id,$this->year) ); // this is where it gets nasty; luckily we can fake it relatively elegantly: ORM won't notice if we override some of the field selections $s->AddJoin("left","prodotherparty",sprintf_esc("prodotherparty.prod = prods.id and (prodotherparty.party = %d AND prodotherparty.party_year = %d)",$this->party->id,$this->year)); foreach($s->fields as &$v) { if ($v == "prods.party_compo as prods_party_compo") { $v = "COALESCE(prodotherparty.party_compo,prods.party_compo) as prods_party_compo"; } if ($v == "prods.party_place as prods_party_place") { $v = "COALESCE(prodotherparty.party_place,prods.party_place) as prods_party_place"; } } $dir = "DESC"; if ($_GET["reverse"]) $dir = "ASC"; $this->sortByCompo = false; switch($_GET["order"]) { case "type": $s->AddOrder("prods.type ".$dir); break; case "name": $s->AddOrder("prods.name ".$dir); break; case "group": $s->AddOrder("prods.group1 ".$dir); $s->AddOrder("prods.group2 ".$dir); $s->AddOrder("prods.group3 ".$dir); break; case "party": $s->AddOrder("prods_party.name ".$dir); $s->AddOrder("prods.party_year ".$dir); $s->AddOrder("prods.party_place ".$dir); break; case "thumbup": $s->AddOrder("prods.voteup ".$dir); break; case "thumbpig": $s->AddOrder("prods.votepig ".$dir); break; case "thumbdown": $s->AddOrder("prods.votedown ".$dir); break; case "avg": $s->AddOrder("prods.voteavg ".$dir); break; case "views": $s->AddOrder("prods.views ".$dir); break; default: { $s->AddOrder( "COALESCE(prodotherparty.party_compo,prods.party_compo)" ); $s->AddOrder( "COALESCE(prodotherparty.party_place,prods.party_place)" ); $this->sortByCompo = true; // include invitations on top $inv = new BM_Query("prods"); $inv->AddWhere( sprintf_esc("(prods.invitation = %d AND prods.invitationyear = %d)",$this->party->id,$this->year,$this->party->id,$this->year) ); $inv->AddOrder( "prods.addedDate" ); $prods = $inv->perform(); foreach($prods as &$v) { $v->party_compo = 1; // invit unset($v->placings); } $this->prods = array_merge( $this->prods, $prods ); } break; } $prods = $s->perform(); $this->prods = array_merge( $this->prods, $prods ); PouetCollectPlatforms($this->prods); PouetCollectAwards($this->prods); }
function LoadFromDB() { $this->party = PouetParty::spawn( $_GET["which"] ); $this->title = $this->party->name." ".(int)$_GET["when"]." results"; }