-
Notifications
You must be signed in to change notification settings - Fork 1
/
v1_party.php
74 lines (67 loc) · 2.11 KB
/
v1_party.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
if (!defined("POUET_API")) exit();
$party = PouetParty::spawn($_GET["id"]);
$year = (int)@$_GET["year"];
$result = new stdClass();
if ($party)
{
$result->success = true;
$result->party = $party->ToAPI();
$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)",$party->id,$year,$party->id,$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)",$party->id,$year));
/*
foreach($s->fields as &$v)
{
if ($v == "prods.party_compo as prods_party_compo")
{
$v = "IF(prodotherparty.id,prodotherparty.party_compo,prods.party_compo) as prods_party_compo";
}
if ($v == "prods.party_place as prods_party_place")
{
$v = "IF(prodotherparty.id,prodotherparty.party_place,prods.party_place) as prods_party_place";
}
}
*/
$links = SQLLib::selectRow(sprintf("SELECT * FROM `partylinks` WHERE party = %d and year = %d",$party->id,$year));
if ($links)
{
unset($links->id);
unset($links->party);
unset($links->year);
$result->party["links"] = $links;
}
$prods = $s->perform();
PouetCollectPlatforms($prods);
PouetCollectAwards($prods);
if ($prods)
{
$result->party["prods"] = array();
foreach($prods as $prod)
{
$result->party["prods"][] = $prod->ToAPI();
}
}
$inv = new BM_Query("prods");
$inv->AddWhere( sprintf_esc("(prods.invitation = %d AND prods.invitationyear = %d)",$party->id,$year) );
$inv->AddOrder( "prods.addedDate" );
$invitations = $inv->perform();
PouetCollectPlatforms($invitations);
PouetCollectAwards($invitations);
if ($invitations)
{
$result->party["invitations"] = array();
foreach($invitations as $prod)
{
$result->party["invitations"][] = $prod->ToAPI();
}
}
}
else
{
$result->error = true;
}
output($result);
?>