-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBBTournament.php
3029 lines (2781 loc) · 108 KB
/
BBTournament.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Model object for a BinaryBeast Tournament
*
* It can be used to <b>create</b>, <b>manipulate</b>, <b>delete</b>, and <b>list</b> BinaryBeast tournaments
*
*
* > Content
* > ******
* >
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#tutorials Tutorials}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#methods Methods}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#properties Properties}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#magicProperties Magic Properties}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#constants Constants}
* >
* >
* > Examples and Tutorials .[#tutorials]
* > ******
* >
* > All examples assume <var>$bb</var> is an instance of {@link BinaryBeast}
* >
* > <b>Tutorials:</b>
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#listing Listing Tournaments}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#create Create a New Tournament}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#round-format Configure Round Format}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#adding-teams Adding Teams}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#list-teams Listing Teams}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-groups Starting Group Rounds}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-random Starting Brackets - Random}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-manual Starting Brackets - Manual}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-seeded Starting Brackets - Seeded}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#open-matches Loading / Listing Unplayed Matches}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#reporting Reporting Matches}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#report-batch Reporting Multiple Matches}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#embedding Embedding your Tournament}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#callbacks Callbacks}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#drawing Accessing Groups/Brackets Data}
* > > - {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#deleting Deleting the Tournament}
* >
*
*
* ## Listing Tournaments .[#listing]
*
* <b>Example: Load list of tournaments created by your account:</b>
*
* Includes any tournaments you've marked as private {@link BBTournament::public},
* as defined in the 3rd parameter
* <code>
* $tournaments = $bb->tournament->list_my(null, 300, true);
* foreach($tournaments as $tournament) {
* echo '<a href="/my/path/to/viewing/a/tournament?id=' . $tournament->id . '">' . $tournament->title . '</a>';
* }
* </code>
*
* <b>Example: Load a filtered list of your tournaments, using the keyword 'starleague':</b>
*
* Note: since we didn't define the 3rd parameter, private tournaments will NOT be included {@link BBTournament::public}
* <code>
* $tournaments = $bb->tournament->list_my('starleague');
* foreach($tournaments as $tournament) {
* echo '<a href="/my/path/to/viewing/a/tournament?id=' . $tournament->id . '">' . $tournament->title . '</a>';
* }
* </code>
*
* <b>Example: Load a list of the most popular tournaments on BinaryBeast right now:</b>
* <code>
* $tournaments = $bb->tournament->list_popular();
* foreach($tournaments as $tournament) {
* echo '<a href="' . $tournament->url . '">' . $tournament->title . '</a>';
* }
* </code>
*
* <b>Example: Load a list of the most popular Quake Live tournaments on BinaryBeast right now:</b>
* <code>
* $tournaments = $bb->tournament->list_popular('QL');
* foreach($tournaments as $tournament) {
* echo '<a href="' . $tournament->url . '">' . $tournament->title . '</a>';
* }
* </code>
*
*
* ## Create a New Tournament .[#create]
*
* Let's run through a quick example of how to create a new tournament using the {@link BinaryBeast::touranment()} factory method
*
* Be sure to check out the available properties ({@see m#agicProperties}), they won't be covered in the example
*
* The code below will create a 1v1 single elimination tournament, with the bronze / 3rd place round enabled
* <code>
* $tournament = $bb->tournament();
* $tournament->title = 'Hello world!';
* $tournament->elimination = BinaryBeast::ELIMINATION_SINGLE;
* $tournament->bronze = true;
* if(!$tournament->save()) {
* var_dump($bb->last_error);
* }
* </code>
*
*
* ## Configure Round Format .[#round-format]
*
* By round format, I mean the best_of value for each round in a bracket
*
* Assume <var>$tournament</var> is a double elimination tournament
*
* The example below will set ALL rounds in the winners' bracket to best of 3, and the finals with best of 5:
* <code>
* foreach($tournament->rounds->winners as $round) {
* $round->best_of = 3;
* }
* $tournament->rounds->finals->best_of = 5;
* </code>
*
* Now we can use either {@link BBTournament::save_rounds()} or {@link BBTournament::save()} to submit the changes:
*
* <b>Using {@link BBTournament::save_rounds()}</b>
* <code>
* if(!$tournament->save_rounds()) {
* var_dump($tournament->error());
* }
* </code>
* <b>Using {@link BBTournament::save()}</b>
* <code>
* if(!$tournament->save()) {
* var_dump($tournament->error());
* }
* </code>
*
*
* ## Add Teams to the Tournament .[#adding-teams]
*
* There are two ways to do it, but the optimal method is to use {@link BinaryBeast::team()}
*
* You COULD use {@link BinaryBeast::team()}, then call {@link BBTeam::init()}, but doing it through
* the tournament is faster and more error proof
*
*
* Note: If {@link BinaryBeast::team()} returns <var>null</var>, check {@link BinaryBeast::last_error} for an explanation
*
* The example below assumes <var>$tournament</var> is elimination tournament and hasn't started yet
*
* Please see {@link BBTeam} documentation for a list of attributes and methods available in instances of BBTeam
*
* <b>Add 8 confirmed teams
* <code>
* for($x = 0; $x < 8; $x++) {
* $team = $tournament->team();
* $team->confirm();
* $team->display_name = 'New Confirmed Team ' . ($x + 1);
* }
* </code>
* <b>Add 3 unconfirmed teams</b>
* <code>
* for($x = 0; $x < 3; $x++) {
* $team = $tournament->team();
* $team->unconfirm();
* $team->display_name = 'New Unonfirmed Team ' . ($x + 1);
* }
* </code>
*
* There are 3 ways to save a new team:
*
* <b>1) Using {@link BBTournament::save()}</b>
* <code>
* if(!$tournament->save()) {
* var_dump($bb->last_error);
* }
* </code>
* <b>2) Using {@link BBTournament::save_teams()}</b>
* <code>
* if(!$tournament->save_teams()) {
* var_dump($bb->last_error);
* }
* </code>
* <b>3) Using {@link BBTeam::save()}</b>
*
* <b>Caution: </b> this method requires that the tournament already be saved!
* <code>
* foreach($tournament->teams as $team) {
* if(!$team->save()) {
* var_dump($bb->last_error);
* }
* }
* </code>
*
*
* ## Listing Teams .[#list-teams]
*
* Getting a list of teams within a tournament is simple, and there are a few ways to do it
*
* You can use {@link BBTournament::teams()} to give you a simple list of EVERY team in the tournament, even
* new ones you haven't saved yet
*
* <b>Example: teams():</b>
* <code>
* $teams = $tournament->teams();
* echo sizeof($teams) . ' teams found in the tournament';
* foreach($teams as $team) {
* //$team is a BBTeam instance, do whatever you want with it now
* }
* </code>
*
* You can also get team lists filtered by status
*
* <b>Example: list only confirmed teams</b>
* <code>
* $confirmed_teams = $tournament->confirmed_teams();
* echo sizeof($confirmed_teams) . ' teams have been confirmed in the tournament';
* </code>
*
* The same is true for banned, and unconfirmed
*
* <b>Example: list only unconfirmed teams</b>
* <code>
* $unconfirmed_teams = $tournament->unconfirmed_teams();
* echo sizeof($unconfirmed_teams) . ' teams have been unconfirmed in the tournament';
* </code>
* <b>Example: list only banned teams</b>
* <code>
* $banned_teams = $tournament->banned_teams();
* echo sizeof($banned_teams) . ' teams have been banned from the tournament';
* </code>
*
* ## Starting Group Rounds .[#start-groups]
*
* <b>Note: </b>Unfortunately for the moment, this library is limited to "random" group seeding
*
* To start the group rounds, first you need an inactive tournament with {@link BBTournament::type_id} set to 1
*
* The example assumes you have a valid tournament with type_id = 1, and enough active teams to fill {@link BBTournament::group_count}
*
* You can use the {@link BBHelper} class to verify that the tournament is ready
* {@link BBHelper::tournament_can_start} will return either (bool)true, or a string error
* <code>
* if(($error = BBHelper::tournament_can_start($tournament) !== true) {
* var_dump(array('start_error' => $error));
* }
* </code>
*
* <b>Example: start the group rounds</b>
* <code>
* if(!$tournament->start()) {
* var_dump($bb->last_error);
* }
* </code>
*
* We can now even use BBHepler to verify it's now in group rounds using {@link BBHelper::tournament_in_group_rounds}
* <code>
* if(!BBHelper::tournament_in_group_rounds($tournament)) {
* var_dump(array('Active-Groups expected...', 'tournament_status' => $tournament->status));
* }
* </code>
*
* Easy enough!
*
*
* ## Starting Brackets - Random .[#start-brackets-random]
*
* Starting brackets with random positions is very simple
*
* <b>Note: </b>You don't have to worry about freewins / bye's, they will added automatically
*
*
* <b>Example: start bracket with random seeding</b>
* The default seeding method is 'random', so all we have to do is call start(), very easy
* <code>
* if(!$tournament->start()) {
* var_dump($bb->last_error);
* }
* </code>
*
* ## Starting Brackets - Manual .[#start-brackets-manual]
*
* You also have the option of starting brackets, and manually defining all of the starting positions
*
*
* To start with specific starting positions, you have to do two things:<br />
* - Set the first argument of save() to 'manual', or {@link BinaryBeast::SEEDING_MANUAL}
* - Provide an array of either {@link BBTeam} objects or team id integers in the exact order you want them to appear in the brackets
*
* <br />
* <b>Note:</b> To define a freewin, just use a value of <b>(int) 0</b> in that position
*
* <b>First step: </b>Setup an array of teams in order
*
* Let's assume we have 7 players, <var>$team1</var>, <var>$team2</var>, ..., <var>$team7</var>, and one freewin
* <code>
* $order = array($team7, $team2, $team5, $team1, 0, $team3, $team4, $team6);
* </code>
*
* <b>Final step: </b>Execute {@link BBTournament::start()}:
* <code>
* if(!$tournament->start(BinaryBeast::SEEDING_MANUAL, $order)) {
* var_dump($bb->error);
* }
* </code>
*
* Success! Just for ease of mind, we can verify a few things:
*
* <b>Use BBHelper to verify the tournament status:</b>
* <code>
* if(!BBHelper::tournament_in_brackets($tournament)) {
* var_dump(array('Expected brackets!, 'found' => $tournament->status));
* }
* </code>
*
* <b>We can also verify position values</b>
* Note: if <var>$team1</var> was NOT saved using a reference (aka <var>$team</var> = <var>&$tournament->team()</var>),
* you may have to call {@link BBTeam::reload} to insure it has the latest values
* <code>
* if($team7->position != 0) {
* var_dump(array('Team 7 position expected to be 7!', 'position' => $team7->position));
* }
* if($team2->position != 1) {
* var_dump(array('Team 2 position expected to be 7!', 'position' => $team7->position));
* }
* </code>
* etc etc...
*
*
* ## Starting Brackets - Seeded .[#start-brackets-seeded]
*
* 'sports' and 'balanced' seeding work very similarly, it's not within the scope
* of this documentation to explain the difference
*
* They work much like 'manual' - but instead of defining initial positions,
* you're defining team rank
*
* So if you want the top 3 ranks to be <var>$team7</var>, <var>$team3</var>, <var>$team1</var>, and randomize the rest,
* just provide an array with those 3 teams, and it will fill in the rest with random
* ranks
*
* See start()'s documentation for more details: {@link BBTournament::start()}
*
* <b>Example: Setup ranks only for top 3 teams, randomize the rest, and start with 'sports' seeding:</b>
* <code>
* $order = array($team7, $team3, $team1);
* if(!$tournament->start(BinaryBeast::SEEDING_SPORTS, $order)) {
* var_dump($bb->last_error);
* }
* </code>
*
* ## Resetting brackets or Groups .[#resetting]
*
* If you need to reset the brackets or groups, it's very simple:
* <code>
* if(!$tournament->reopen()) {
* var_dump($bb->last_error());
* }
* </code>
*
*
* ## Loading / Listing Unplayed Matches .[#open-matches]
*
* We can use the {@link open_matches()} method, and the magic {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#m$open_matches $open_matches} property to find matches that need to be reported
*
* <b>Example: </b> Using {@link open_matches()}
* <code>
* $matches = $tournament->open_matches();
* foreach($matches as $match) {
* echo $match->team->display_name . ' vs ' . $match->team2->display_name . ' in round ' . $match->round_format->round . '<br />';
* }
* </code>
*
*
* <br /><br />
* You can use the magic {@link $open_matches} property to directly fetch one of the matches
*
* <b>Example: </b> Using the magic {@link $open_matches} property
* <code>
* $match = $tournament->open_matches[0];
* echo $match->team->display_name . ' vs ' . $match->team2->display_name . ' in round ' . ($match->round + 1) . '<br />';
* </code>
*
*
* ## Reporting Matches .[#reporting]
*
*
* The previous example showed us how to get unplayed {@link BBMatch} objects
*
* So assuming <var>$tournament</var> is an active tournament with brackets... first step:
* <code>
* $match = $tournament->open_matches[0];
* </code>
*
*
* Please refer to the documentation of {@link BBMatch} for more options, but here's a quick example:
*
* Key points in the example:
* - {@link BBMatch::team()} to grab the first team
* - {@link BBMatch::set_winner()} to define the first team as the winner
* - {@link BBMatch::report()} to save / report the match
*
* <b>Example: </b>Report a simple 1:0 match:
* <code>
* $match->set_winner($match->team());
* if(!$match->report()) {
* var_dump($bb->last_error);
* }
* echo $match->winner->display_name . ' defeated ' . $match->loser->display_name . ' in match ' . $match->id;
* </code>
*
*
* ## Reporting Multiple Matches .[#report-batch]
*
* The previous example demonstrated the use of {@link BBMatch::report()}, now let's look how to report multiple matches simultaneously
*
* <br />
* Firstly, go through all the open matches and define a winner so we have multiple matches to report
*
* <code>
* foreach($tournament->open_matches as $match) {
* $match->set_winner($match->team());
* }
* </code>
*
*
* <br /><br />
* Now we can either use {@link BBTournament::save_matches()}, or {@link BBTournament::save()}
*
* <b>Using {@link BBTournament::save_matches()}:</b>
* <code>
* if(!$tournament->save_matches()) {
* var_dump($bb->error_history);
* }
* </code>
*
*
* <br />
* <b>Using {@link BBTournament::save()}:</b>
* <code>
* if(!$tournament->save()) {
* var_dump($bb->error_history);
* }
* </code>
*
*
* ## Embedding your Tournament .[#embedding]
*
* There are two ways to do this
*
* - Using {@link BBHelper::embed_brackets()} and {@link BBHelper::embed_groups()}
* - Using {@link BBTournament::embed()}
*
*
* <b>Example - Brackets - Using BBHelper</b>
*
* Review the documentation in {@link BBHelper::embed_tournament()} to see the possible arguments
* <code>
* BBHelper::embed_brackets($tournament);
* </code>
*
*
* <b>Example - Groups - Using BBHelper</b>
*
* Review the documentation in {@link BBHelper::embed_tournament_groups()} to see the possible arguments
* <code>
* BBHelper::embed_groups($tournament);
* </code>
*
* <b>Example - Groups - Using BBTournament</b>
*
* Review the documentation in {@link BBTournament::embed_groups()} to see the possible arguments
* <code>
* $tournament->embed_groups();
* </code>
*
* <b>Example - Brackets - Using BBTournament</b>
*
* Review the documentation in {@link BBTournament::embed()} to see the possible arguments
* <code>
* $tournament->embed();
* </code>
*
*
* ## Callbacks .[#callbacks]
*
* Thanks to the {@link BBCallback} library class, you can register URLs for BinaryBeast to call whenever a certain event is triggered
*
* Here is a list of callbacks currently available for a tournament:
* - {@link on_create()}: Triggered when a new tournament is created
* - {@link on_change()}: Very generic, triggered by just about everything
* - {@link on_complete()}: The final match is reported
* - {@link on_delete()}: Tournament has been deleted
* - {@link on_delete()}: Tournament has been deleted
* - {@link on_match_reported()}: A new match result has been reported
* - {@link on_match_unreported()}: A match result has been unreported / deleted
* - {@link on_settings()}: A setting has changed (like the title, max_teams etc)
* - {@link on_start_brackets()}: Brackets have been generated
* - {@link on_start_groups()}: Group rounds have begun
* - {@link on_team_added()}: A new team has been added
* - {@link on_team_removed()}: A new team has been removed / deleted
* - {@link on_team_status()}: A new team's status has changed (Confirmed / Banned etc)
*
* <br />
*
*
* ## Example: Register a Callback
*
* Let's register a simple callback with {@link on_change()}:
* <code>
* $id = $tournament->on_change('http://yoursite.com/tournament/handle_callback.php');
* echo 'Callback registered succesfully! Callback ID: ' . $id;
* </code>
*
*
* ## Example: Handling a Callback
*
* Check out the documentation in {@link http://binarybeast.com/content/api/docs/php/class-BBCallback.html#handling BBCallback} for instructions on handling callbacks
*
*
* ## Example: Listing Registered Callbacks
*
* Use {@link BBModel::list_callbacks()} to determine what callbacks have been registered with your tournament
*
* <br /><br />
* {@link BBCallbackObject} documents the format you can expect this method to return
*
* <br /><br />
* <code>
* foreach($tournament->list_callbacks() as $callback) {
* echo $callback->id . ': (' . $callback->url . ') Triggered by: ' . $callback->event_description . '<br />';
* }
* </code>
*
*
*
*
* ## Example: Delete (Unregister) a Callback
*
* Again, refer to the documentation in {@link http://binarybeast.com/content/api/docs/php/class-BBCallback.html#deleting BBCallback} for this
*
*
*
*
* ## Accessing Groups/Brackets Data .[#drawing]
*
* You have the option of directly accessing the raw data from the brackets and group rounds themselves
*
* <br />
* There are two methods / properties available for this:
* - {@link brackets()} / {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#m$brackets BBTournament::$brackets}
* - {@link groups()} / {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#m$groups BBTournament::$groups}
*
* <br /><br />
* <b>Examples and Documentation</b> are available below:
* - <b>Groups: </b>{@link BBGroupsObject}
* - <b>Brackets: </b>{@link BBBracketsObject}
*
*
* ## Deleting the Tournament .[#deleting]
*
* Be <b>VERY</b> careful with this! there's no going back!!
*
* You can delete the tournament and all of its children however, with one quick
* potentially catastrophically mistaken swoop:
* <code>
* if(!$tournament->delete()) {
* var_dump($bb->last_error);
* }
* </code>
*
*
* ## More...
*
* Those are the basics, but there's a lot more to it - feel free to look through
* the documentation to see what else is available
*
*
* ## Next Step
*
* Your next step should be to review documentation for the following models, each one which are children of a BBTournament:<br />
* - {@link BBRound}
* - {@link BBTeam}
* - {@link BBMatch}
* - {@link BBMatchGame}
*
*
*
*
* @property boolean $title
* Tournament title
*
* @property boolean $public
* <b>Default: true</b><br />
* If true, this tournament can be found in the public lists + search
*
* @property-read string $url
* The URL to this tournament hosted on BinaryBeast.com
*
* @property-read string $status
* <b>Read Only</b><br />
* The current tournament status<br />
* <b>Building:</b> New tournament, still accepting signups, not accepting player-confirmations<br />
* <b>Confirmations:</b> Getting ready to start, still accepting signups, now accepting player-confirmations<br />
* <b>Active:</b> Brackets<br />
* <b>Active-Groups:</b> Round robin group rounds<br />
* <b>Active-Brackets:</b> Brackets after group-rounds <br />
* <b>Complete:</b> Final match has been reported<br />
*
* @property-read int $live_stream_count
* <b>Read Only</b><br />
* Number of streams associated with this tournament that are currently streaming
*
* @property-read string $game
* <b>Read Only</b><br />
* Name of this tournament's game, determined from {@link BBTournament::$game_code}
*
* @property-read string $network
* <b>Read Only</b><br />
* Name of the network for this game's tournament
*
* @property string $game_code
* <b>Default: HotS (StarCraft 2: Heart of the Swarm)</b><br />
* Unique game identifier, <br />
* Use {@link BBGame::search()} to search through our games list, and get the game_code values
*
* @property string $date_start
* YYYY-MM-DD HH:SS ({@link http://en.wikipedia.org/wiki/ISO_8601})
*
* @property int $type_id
* <b>Default: 0 (Elimination Brackets)</b><br />
* Tournament type - defines the stages of the tournament<br />
* Use {@link BinaryBeast::TOURNEY_TYPE_BRACKETS} and {@link BinaryBeast::ELIMINATION_SINGLE}<br />
* <b>warning: you cannot change this setting after the tournament has started, you'll have to {@link BBTournament::reopen()} first</b>
*
* @property int $elimination
* <b>Default: 1 (Single Elimination)</b><br />
* Elimination mode, single or double, simply 1 for single 2 for double<br />
* but you can also use {@link BinaryBeast::ELIMINATION_SINGLE} and {@link BinaryBeast::ELIMINATION_DOUBLE}
*
* @property boolean $bronze
* <b>Default: false</b><br />
* <b>Single Elimination Brackets Only</b><br />
* Set this true to enable the bronze bracket<br />
* aka the 3rd place decider
*
* @property int $team_mode
* <b>Default: 1 (1v1)</b><br />
* Number of players per team<br />
* 1 = a normal 1v1<br />
* Anything else indicates this is a team-based game<br />
*
* @property int $group_count
* <b>Default: 1</b><br />
* <b>Group Rounds Only</b><br />
* Number of groups to setup when starting round robin group rounds
*
* @property int $teams_from_group
* <b>Default: 2</b><br />
* <b>Group Rounds Only</b><br />
* Number of participants from each group that advance to the brackets
*
* @property string $location
* Generic description of where players should meet / coordinate (ie a bnet channel)
*
* @property int $max_teams
* <b>Default: 32</b><br />
* Maximum number of participants allowed to confirm their positions
*
*
* @property int $replay_uploads
* <b>Default: 1 (Optional)</b><br />
* Replay upload mode<br />
* {@link BinaryBeast::REPLAY_UPLOADS_OPTIONAL}<br />
* {@link BinaryBeast::REPLAY_UPLOADS_DISABLED}<br />
* {@link BinaryBeast::REPLAY_UPLOADS_MANDATORY}<br />
*
* @property int $replay_downloads
* <b>Default: 1 (Enabled)</b><br />
* Replay download mode<br />
* {@link BinaryBeast::REPLAY_DOWNLOADS_ENABLED}<br />
* {@link BinaryBeast::REPLAY_DOWNLOADS_DISABLED}<br />
* {@link BinaryBeast::REPLAY_DOWNLOADS_POST_COMPLETE}<br />
*
* @property string $description
* Generic description of the tournament<br />
* Plain text only - no html allowed
*
* @property mixed $hidden
* Special hidden (as you may have guessed) values that you can use to store custom data<br />
* The recommended use of this field, is to store a json_encoded string that contains your custom data
* <b>Note:</b> Can be set to an object / array, and it will be saved as a json_string,<br />
* and the encoding/decoding is <b>handled automatically</b> when the object is loaded and saved
*
*
* @property string $player_password
* <b>Strongly recommended</b><br />
* If set, players are required to provide this password before allowed to join<br />
* Use {@link BBTournament::generate_player_password()}
*
* @property BBMapObject[] $map_pool
* Array of approved maps in the map pool
*
* @property BBTeam[] $teams
* <b>Alias for {@link BBTournament::teams()}</b><br />
* An array of teams in this tournament
*
* @property BBTeam[] $confirmed_teams
* <b>Alias for {@link BBTournament::confirmed_teams()}</b><br />
* An array of confirmed teams in this tournament
*
* @property BBTeam[] $unconfirmed_teams
* <b>Alias for {@link BBTournament::unconfirmed_teams()}</b><br />
* An array of unconfirmed teams in this tournament
*
* @property BBTeam[] $banned_teams
* <b>Alias for {@link BBTournament::banned_teams()}</b><br />
* An array of banned teams in this tournament
*
* @property BBTeam[] $freewins
* <b>Alias for {@link BBTournament::freewins()}</b><br />
* An array of freewin teams
*
* @property int $teams_confirmed_count
* Number of confirmed teams in the tournament
*
* @property int $teams_joined_count
* Number of teams in the tournament, regardless of status
*
* @property BBRoundObject $rounds
* <b>Alias for {@link BBTournament::rounds()}</b><br />
* An object containing arrays of BBRound objects <br />
* each array is keyed by the the simple bracket label:<br />
* groups, winners, losers, bronze, finals<br />
*
* @property BBMatch[] $open_matches
* <b>Alias for {@link BBTournament::open_matches()}</b><br />
* An array of matches in this tournament that still need to be reported
*
* @property-read BBBracketsObject $brackets
* <b>Alias for {@link brackets()}</b><br />
* The data object containing elimination bracket matches and results
*
* @property-read BBGroupsObject $groups
* <b>Alias for {@link groups()}</b><br />
* The data object containing group rounds matches and results
*
* @todo consider allowing developers to set values for any custom properties, and save them in $notes
* @todo consider allowing developers to set values for any custom properties, and save them in $notes
*
* @todo Instead of flagging reloads when the race is changed, import the new values (may require update to the svc itself)
*
* @package BinaryBeast
* @subpackage Model
*
* @version 3.1.5
* @date 2013-07-05
* @since 2012-09-17
* @author Brandon Simmons <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php
* @license http://www.gnu.org/licenses/gpl.html
*/
class BBTournament extends BBModel {
//<editor-fold defaultstate="collapsed" desc="API svc name constants">
const SERVICE_LOAD = 'Tourney.TourneyLoad.Info';
const SERVICE_CREATE = 'Tourney.TourneyCreate.Create';
const SERVICE_UPDATE = 'Tourney.TourneyUpdate.Settings';
const SERVICE_DELETE = 'Tourney.TourneyDelete.Delete';
/**
* API svc name for fetching a tournament count
* @var string
*/
const SERVICE_COUNT = 'Tourney.TourneyList.Count';
/**
* API svc name for starting a tournament
* @var string
*/
const SERVICE_START = 'Tourney.TourneyStart.Start';
/**
* API svc name for resetting brackets/ groups
* @var string
*/
const SERVICE_REOPEN = 'Tourney.TourneyReopen.Reopen';
/**
* API svc name for allowing participant confirmations
* @var string
*/
const SERVICE_ALLOW_CONFIRMATIONS = 'Tourney.TourneySetStatus.Confirmation';
/**
* API svc name for disabling participant confirmations
* @var string
*/
const SERVICE_DISALLOW_CONFIRMATIONS = 'Tourney.TourneySetStatus.Building';
//
/**
* API svc name for loading a list of tournaments
* @var string
*/
const SERVICE_LIST = 'Tourney.TourneyList.Creator';
/**
* API svc name for loading a list of <b>popular</b> tournaments
* @var string
*/
const SERVICE_LIST_POPULAR = 'Tourney.TourneyList.Popular';
/**
* API svc name for loading a list of unplayed matches
* @var string
*/
const SERVICE_LIST_OPEN_MATCHES = 'Tourney.TourneyLoad.OpenMatches';
/**
* API svc name for loading / streaming a list of played matches
* @var string
*/
const SERVICE_STREAM_MATCHES = 'Tourney.TourneyMatch.Stream';
/**
* API svc name for loading a single match
* @var string
*/
const SERVICE_LOAD_MATCH = 'Tourney.TourneyLoad.Match';
/**
* API svc name for loading match details, given the participants
* @var string
*/
const SERVICE_LOAD_TEAM_PAIR_MATCH = 'Tourney.TourneyMatch.LoadTeamPair';
/**
* API svc name for listing the participants in the tournament
* @var string
*/
const SERVICE_LOAD_TEAMS = 'Tourney.TourneyLoad.Teams';
/**
* API svc name for performing a batch update of teams
* @var string
*/
const SERVICE_UPDATE_TEAMS = 'Tourney.TourneyTeam.BatchUpdate';
//
/**
* API svc name for listing the round format in the tournament
* @var string
*/
const SERVICE_LOAD_ROUNDS = 'Tourney.TourneyLoad.Rounds';
/**
* API svc name for performing a batch update of round format
* @var string
*/
const SERVICE_UPDATE_ROUNDS = 'Tourney.TourneyRound.BatchUpdate';
//
/**
* API svc name for loading the raw data of matchups and results in the brackets
* @var string
*/
const SERVICE_LOAD_BRACKETS = 'Tourney.TourneyDraw.Brackets';
/**
* API svc name for loading the raw data of matchups and results in the group rounds
* @var string
*/
const SERVICE_LOAD_GROUPS = 'Tourney.TourneyDraw.Groups';
/**
* API svc name used to remove a map from the map_pool
* @var string
*/
const SERVICE_REMOVE_MAP = 'Tourney.TourneyMapPool.Delete';
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Local Cache Settings">
const CACHE_OBJECT_TYPE = BBCache::TYPE_TOURNAMENT;
/**
* Cache the tournament info for 60 minutes
* @var int
*/
const CACHE_TTL_LOAD = 60;
/**
* Cache list results for 60 minutes
* @var int
*/
const CACHE_TTL_LIST = 60;
/**
* Cache team list results for 30 minutes
* @var int
*/
const CACHE_TTL_TEAMS = 30;
/**
* Cache match load results for 10 minutes
* @var int
*/
const CACHE_TTL_MATCH = 10;
/**
* Cache round format listing results for 60 minutes
* @var int
*/
const CACHE_TTL_ROUNDS = 60;
/**
* Cache queries for unplayed / open matches for 20 minutes
* @var int
*/
const CACHE_TTL_LIST_OPEN_MATCHES = 20;
/**
* Cache the Groups/Brackets drawing services
* @var int
*/
const CACHE_TTL_DRAW = 30;
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Callback event_id constants">
/**
* Callback event id for when a new tournament is created
* @var int
*/
const CALLBACK_CREATED = 12;
/**
* Callback event id for when a match has been reported
* @var int
*/
const CALLBACK_MATCH_REPORTED = 6;
/**
* Callback event id for when a match has been unreported
* @var int
*/
const CALLBACK_MATCH_UNREPORTED = 7;
/**
* Callback event id for when the tournament is deleted
* @var int
*/
const CALLBACK_DELETED = 8;
/**
* Callback event id for when the group rounds begin
* @var int
*/
const CALLBACK_GROUPS_STARTED = 1;
/**
* Callback event id for when the brackets begin
* @var int
*/
const CALLBACK_BRACKETS_STARTED = 2;
/**
* Callback event id for when the final match is reported, and the tournament finishes
* @var int
*/
const CALLBACK_COMPLETE = 3;
/**
* Callback event id for when a team is added to the tournament
* @var int
*/
const CALLBACK_TEAM_ADDED = 4;
/**
* Callback event id for when a team is removed from the tournament
* @var int
*/
const CALLBACK_TEAM_REMOVED = 4;
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Private properties and child arrays">
/**
* Array of participants within this tournament
* @var BBTeam[]
*/
private $teams;
/**
* Array of filtered team arrays, necessary for returning results by reference
*/
private $filtered_teams = array();
/**
* Object containing format for each round
* Keyed by bracket name, each of which is an array of BBRound objects
* @var BBRoundObject
*/
private $rounds;
/**
* Cache results from loading open matches from the API
* @var BBMatch[]
*/
private $open_matches;
/**
* Result of calling the TourneyDraw.Brackets service
* @var BBBracketsObject
*/
private $brackets;
/**
* Result of calling the TourneyDraw.Groups service
* @var BBGroupsObject
*/
private $groups;
/**
* Map pool objects
* @var BBMapObject[]
*/
private $map_pool;
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="BBModel implementations">
/**
* Default values for a new tournament
* @var array
*/
protected $default_values = array(
'title' => 'PHP API Test',
'public' => true,
'game_code' => 'HotS',
'type_id' => BinaryBeast::TOURNEY_TYPE_BRACKETS,
'elimination' => BinaryBeast::ELIMINATION_SINGLE,
'bronze' => false,
'team_mode' => 1,