-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournament_64.controller.inc
105 lines (85 loc) · 3.03 KB
/
tournament_64.controller.inc
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* @file
* Tournament 64 classes
*
*/
class Tour64LeaguesEntityController extends EntityAPIController {
public function save($entity, DatabaseTransaction $transaction = NULL) {
$entity->changed = REQUEST_TIME;
if (empty($entity->{$this->idKey}) || !empty($entity->is_new)) {
// Set the creation timestamp if not set, for new entities.
if (empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
if (empty($entity->uid)) {
global $user;
$entity->uid = $user->uid;
}
}
// convert date to UTC
$timezone = date_default_timezone();
$datetime = new dateObject($entity->close_time, $timezone);
$timezone = 'UTC';
$datetime->setTimezone(new DateTimeZone($timezone));
$entity->close_time = $datetime->format('Y-m-d H:i:s');
return parent::save($entity, $transaction);
}
}
class Tour64EntriesEntityController extends EntityAPIController {
public function save($entity, DatabaseTransaction $transaction = NULL) {
$entity->changed = REQUEST_TIME;
if (empty($entity->{$this->idKey}) || !empty($entity->is_new)) {
// Set the creation timestamp if not set, for new entities.
if (empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
if (empty($entity->uid)) {
global $user;
$entity->uid = $user->uid;
}
if (empty($entity->paid)) {
$entity->paid = 'N';
}
}
// fill in predictions if we have all our picks
if (!empty($entity->winners[57]) and
!empty($entity->winners[58]) and
!empty($entity->winners[59]) and
!empty($entity->winners[60]) and
!empty($entity->winners[61]) and
!empty($entity->winners[62]) and
!empty($entity->winners[63])) {
$final_two = array($entity->winners[61], $entity->winners[62]);
$final_four = array($entity->winners[57], $entity->winners[58], $entity->winners[59], $entity->winners[60]);
$second_place = array_values(array_diff($final_two, array($entity->winners[63])));
$tie_third = array_values(array_diff($final_four, $final_two));
$entity->prediction_first = $entity->winners[63];
$entity->prediction_second = $second_place[0];
$entity->prediction_third = $tie_third[0];
$entity->prediction_fourth = $tie_third[1];
} else {
$entity->prediction_first = NULL;
$entity->prediction_second = NULL;
$entity->prediction_third = NULL;
$entity->prediction_fourth = NULL;
}
return parent::save($entity, $transaction);
}
}
class Tour64Leagues extends Entity {
protected function defaultLabel() {
return $this->description;
}
protected function defaultUri() {
return array('path' => 'tournament-64/' . $this->identifier());
}
}
class Tour64Entries extends Entity {
protected function defaultLabel() {
return $this->nickname;
}
protected function defaultUri() {
return array('path' => 'tournament-64/' . $this->league_id . '/entries/' . $this->identifier());
}
}