forked from gfrenoy/TabT-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabtapi.php
2147 lines (1978 loc) · 89.9 KB
/
tabtapi.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
/** \internal
* TabT API
*
* A programming interface to access information managed
* by TabT, the table tennis information manager.
*
* @author Gaetan Frenoy <[email protected]>
* @version 0.7.23
*
* Copyright (C) 2007-2019 Gaëtan Frenoy ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @mainpage TabT API Documentation
*
* @htmlonly
* <h3>The programming interface (API) of TabT</h3>
* <p>To allow developpers and creative webmasters integrating data gathered in the TabT software, TabT provides
* a generic programming interface (in short "API") that can be used from any language and any platform.</p>
* <p>Everbody can consequently create his/her own application (club results management, tournament software, ...) of
* website (for his/her own club) based on the powerful TabT engine.</p>
* <p><img src="http://tabt.frenoy.net/data/documents/tabt-api-overview-en.png" alt="image" border="0">
* <h3>Quick start</h3>
* See the list of <a href="group__TabTAPIfunctions.html">available functions</a>.
* <h3>"SOAP" and "Web Services" technologies</h3>
* <p>The TabT API is based on <a href="http://en.wikipedia.org/wiki/SOAP">SOAP</a> and
* <a href="http://en.wikipedia.org/wiki/Web_service">Web service</a> technologies. Those frameworks are now available
* for any modern programming language like PHP, C#, VB.NET or java.</p>
* <h3>Contact</h3>
* <a href="https://babelut.be/@tabt" target="_blank"><img style="margin-right: 10px; border: 0; float: left;" src="mastodon.png" title="Mastodon icon"></a>
* To keep you up to date of the latest changes or for questions and suggestions or any kind of interaction with the
* developpers and other users of TabT API, we strongly suggest you to follow the TabT account on the
* <a href="https://en.wikipedia.org/wiki/Fediverse">Fediverse</a> (typically <a href="https://joinmastodon.org/">Mastodon</a>) :<br/>
* <a href="https://babelut.be/@tabt" target="_blank">@[email protected]</a>.
* <h3>License</h3>
* <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">
* <p><img style="margin-right: 10px; border: 0; float: left;" src="agplv3-88x31.png" title="GNU Affero General Public License"></a>
* TabT API is released under the terms of version 3 of the <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">
* GNU Affero General Public License</a> that is is a free, copyleft license for software, specifically designed to
* ensure cooperation with the community in the case of network server software. The GNU Affero GPL is designed
* specifically to ensure that the modified source code becomes available to the community. It requires the operator of
* a network server to provide the source code of the modified version running there to the users of that server.
* Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source
* code of the modified version.</p>
* @endhtmlonly
*/
/**
* TabT API types definition
*/
if (!include_once('tabtapi_types.php')) {
print('Cannot include TabT API types, please contact server administrator.');
exit();
}
/**
* @defgroup TabTAPIfunctions TabT API functions
* @brief All TabT API functions
* @{
*/
/**
* @brief Dummy test function to verify connectivity
*
* Before trying anything else, you should try to call this function that will return (see ::TestResponse) some basic
* information about the API server (like server timestamp and API version).
* If you specify your credentials in the request (see ::TestRequest), the server will also tell if you have
* a valid account on the server and which language you are currently using.
*
* @param[in] $Request TestRequest
* @return TestResponse
* @see TestRequest, TestResponse
* @version 0.7.16
* @ingroup TabTAPIfunctions
*/
function Test(stdClass $Request) {
$permissions = _MethodAPI(1, isset($Request->Credentials) ? $Request->Credentials : (object)array());
$res = array('Timestamp' => date("c"),
'ApiVersion' => TABTAPI_VERSION,
'IsValidAccount' => count($permissions)>0,
'Language' => $GLOBALS['lang'],
'Database' => $GLOBALS['site_info']['database'],
'RequestorIp' => long2ip($GLOBALS['api_caller_ip']),
'ConsumedTicks' => intval($GLOBALS['api_consumed']),
'CurrentQuota' => intval($GLOBALS['api_remaining_quota']),
'AllowedQuota' => intval($GLOBALS['api_quota_limit']));
return $res;
}
/**
* @brief GetSeasons returns the list of seasons available in the TabT database.
*
* Each season is identified by a unique positive number and a name.
* As an example, season ID of season 2007-2008 is 8.
*
* Here is the returned data if 2008-2009 is the current season
* <ul>
* <li><code>1 | 2001-2002 | false</code></li>
* <li><code>2 | 2002-2003 | false</code></li>
* <li>(...)</li>
* <li><code>7 | 2007-2008 | false</code></li>
* <li><code>8 | 2008-2009 | true</code></li>
* </ul>
*
* GetSeasons also returns the current season that is used in all other functions as
* the default season (when not specified explicitely)
*
* @param[in] $Credentials Optional identification of the caller
* @return GetSeasonsResponse
* @since Version 0.5
* @see CredentialsType, GetSeasonsResponse
* @ingroup TabTAPIfunctions
*/
function GetSeasons(stdClass $Credentials) {
$permissions = _MethodAPI(2, $Credentials);
$res = array();
$db = new DB_Session("SELECT id, name FROM seasoninfo;");
while ($db->next_record()) {
$res[] = array('Season' => $db->Record['id'],
'Name' => $db->Record['name'],
'IsCurrent' => $db->Record['id']==$GLOBALS['site_info']['season']);
if ($db->Record['id']==$GLOBALS['site_info']['season']) {
$CurrentSeason = $db->Record['id'];
$CurrentSeasonName = $db->Record['name'];
}
}
$db->free();
unset($db);
return array('CurrentSeason' => $CurrentSeason,
'CurrentSeasonName' => $CurrentSeasonName,
'SeasonEntries' => $res);
return $res;
}
/**
* @brief GetClubTeams returns a list with all the teams of a given club.
*
* Each club has one or more teams playing in divisions. This function lists all
* the teams of a given club.
*
* As an example, here is the returned data for VLB-295 (TTC Werchter) for season 2007-2008
* <ul>
* <li><code>389-7 | A | 389 | Afdeling 1 - Prov. Vl.-B/Br. - Heren | 1</code></li>
* <li><code>390-7 | B | 390 | Afdeling 2A - Prov. Vl.-B/Br. - Heren | 1</code></li>
* <li>(...)</li>
* <li><code>397-2 | F | 397 | Afdeling 5B - Prov. Vl.-B/Br. - Heren | 1</code></li>
* <li><code>396-9 | G | 396 | Afdeling 5A - Prov. Vl.-B/Br. - Heren | 1</code></li>
* <li>(...)</li>
* <li><code>401-2 | A | 401 | Afdeling 1 - Prov. Vl.-B/Br. - Veteranen | 3</code></li>
* <li><code>403-2 | B | 403 | Afdeling 3 - Prov. Vl.-B/Br. - Veteranen | 3</code></li>
* </ul>
*
* @param[in] Request Input parameters
* @return GetClubTeamsResponse
* @since Version 0.5
* @see GetClubTeamsRequest, GetClubTeamsResponse
* @ingroup TabTAPIfunctions
* @version 0.7.8
*/
function GetClubTeams(stdClass $Request) {
// Check permissions & quota
$permissions = _MethodAPI(3, isset($Request->Credentials) ? $Request->Credentials : (object)array());
// Extract function arguments
$Club = trim($Request->Club);
$Season = trim($Request->Season);
// Prepare database session
$db = new DB_Session();
// Check season
if (!isset($Season) || '' == $Season) {
$Season = $db->select_one("SELECT MAX(id) FROM seasoninfo;");
}
if (!is_numeric($Season)) {
throw new SoapFault('6', "Season [{$Season}] is not valid, must be numeric.");
}
$Season = intval($Season);
if ($db->select_one("SELECT COUNT(*) FROM seasoninfo WHERE id={$Season}") == 0) {
throw new SoapFault('7', "Season [{$Season}] is not valid.");
}
// Check club
$Club = str_replace(array('-','/',' '), '', strtoupper($Club));
if ($Club == '') {
throw new SoapFault('17', "Club is not valid, cannot be empty.");
}
list($ClubId, $ClubName) = _GetClubInfo($Season, $Club);
if (!is_numeric($ClubId) || $ClubId < 0) {
throw new SoapFault('9', "Club [{$Club}] is not valid.");
}
$q = <<<EOQ
SELECT
CONCAT(di.id,'-',dti.team_id) as teamid,
dti.indice as team,
di.id as div_id,
di.category as divisioncategory,
di.match_type_id as matchtype
FROM
divisionteaminfo dti,
divisioninfo di
WHERE 1
AND dti.season={$Season}
AND dti.club_id={$ClubId}
AND di.id=dti.div_id
ORDER BY
di.category ASC, dti.indice ASC
EOQ;
$db->query($q);
$TeamEntries = array();
while ($db->next_record()) {
$TeamEntries[] = array('TeamId' => $db->Record['teamid'],
'Team' => $db->Record['team'],
'DivisionId' => $db->Record['div_id'],
'DivisionName' => create_division_title_text(get_division_info($Season, $db->Record['div_id']), true),
'DivisionCategory' => $db->Record['divisioncategory'],
'MatchType' => $db->Record['matchtype']);
}
$db->free();
unset($db);
return array('ClubName' => $ClubName,
'TeamCount' => count($TeamEntries),
'TeamEntries' => $TeamEntries);
}
/**
* @brief Returns ranking of given division for a given week
*
* <p>GetDivisionRanking returns the ranking of all teams playing with a division after a given week.
* If no week is given, the latest one will be selected automatically. The last week means
* the week that starts just before the current date.</p>
* <p>With GetDivisionRanking, the webmaster can display on his/her website the ranking of the
* division where the teams of his/her club are playing.</p>
*
* <p>Example for division #390 after 18 weeks of VTTL competition (season 2007-2008):</p>
* <code>Afdeling 2A - Prov. Vl.-B/Br. - Heren</code>
* <ul>
* <li><code>1 | T.T. Groot-Bijgaarden A | 18 | 13 | 2 | 3 | 196 | 92 | 641 | 378 | 29</code></li>
* <li><code>2 | Werchter B | 18 | 11 | 4 | 3 | 158 | 130 | 525 | 400 | 25</code></li>
* <li><code>3 | Hurricane TTW C | 17 | 10 | 2 | 5 | 167 | 104 | 610 | 440 | 25</code></li>
* <li><code>4 | T.T.K. Vilvo F | 17 | 10 | 6 | 1 | 165 | 107 | 525 | 441 | 21</code></li>
* <li>(...)</li>
* </ul>
*
* <p>And here is the <a href="http://tabt.frenoy.net/data/documents/tabt-api-getdivisionranking-werchter.png">
* integration</a> into the <a href="http://www.ttcw.be/">Werchter TTC website</a>.</p>
*
* @see GetDivisionRankingRequest, GetDivisionRankingResponse
* @return GetDivisionRankingResponse
* @ingroup TabTAPIfunctions
* @version 0.7.14
*/
function GetDivisionRanking(stdClass $Request) {
// Check permissions & quota
$permissions = _MethodAPI(4, isset($Request->Credentials) ? $Request->Credentials : (object)array());
// Extract function arguments
$DivisionId = isset($Request->DivisionId) ? $Request->DivisionId : -1;
$WeekName = isset($Request->WeekName) ? trim($Request->WeekName) : '';
$RankingSystem = isset($Request->RankingSystem) ? $Request->RankingSystem : '';
// Create database session
$db = new DB_Session();
$db->Halt_On_Error = 'no';
// Check that division is a numeric value
if (!is_numeric($DivisionId))
{
throw new SoapFault('2', "DivisionId [{$DivisionId}] is not valid, must be numeric.");
}
// Retrieve season when this division was playerd
$q = "SELECT season, calendar_id FROM divisioninfo WHERE id={$DivisionId};";
list($season, $calendar_id) = $db->select_one_array($q);
// Check season
if (!is_numeric($season) || !($season > -1) || !is_numeric($calendar_id))
{
throw new SoapFault('3', "DivisionId [{$DivisionId}] is not valid.");
}
// Search week name
if ($WeekName == '' || !isset($WeekName)) {
// Week name not given, use last week (so we have the most "up-to-date" ranking)
$q = "SELECT MAX(week) FROM calendarweekname WHERE calendar_id={$calendar_id};";
$week = $db->select_one($q);
$q = "SELECT name FROM calendarweekname WHERE calendar_id={$calendar_id} and week={$week};";
$DatabaseWeekName = $db->select_one($q);
} else {
$WeekName = mysql_real_escape_string(ltrim($WeekName, '0'));
$q = "SELECT week, name FROM calendarweekname WHERE calendar_id={$calendar_id} and TRIM(LEADING '0' FROM name) LIKE '{$WeekName}';";
list($week, $DatabaseWeekName) = $db->select_one_array($q);
if (!is_numeric($week) || !($week > -1)) {
throw new SoapFault('4', "WeekName [{$WeekName}] is not valid for division [{$DivisionId}]");
}
}
if (trim($RankingSystem) == '')
{
// Default ranking system
$RankingSystem = $db->select_one("SELECT di.classement_type FROM divisioninfo di WHERE di.id={$DivisionId}");
}
if (!is_numeric($RankingSystem) || $db->select_one("SELECT COUNT(*) FROM classementtypeinfo WHERE id={$RankingSystem}") != 1)
{
throw new SoapFault('31', "Ranking system [{$RankingSystem}] is not valid.");
}
// Release database connection
$db->free();
unset($db);
// Execute classement function
include_once($GLOBALS['site_info']['path'].'public/calendar_fct.php');
include_once($GLOBALS['site_info']['path'].'public/classement_fct.php');
$entries = get_classement_for_division($RankingSystem, $season, $DivisionId, '', false, false, null, $DatabaseWeekName, 1, false, true);
if (!is_array($entries))
{
throw new SoapFault('5', "Unable to process ranking for division [{$DivisionId}], week name [{$WeekName}].");
}
$res = array();
foreach ($entries as $entry)
{
$res[] = array('Position' => $entry[$GLOBALS['str_Place']],
'Team' => $entry[$GLOBALS['str_TeamName']],
'GamesPlayed' => $entry[$GLOBALS['str_GamesPlayed']],
'GamesWon' => $entry[$GLOBALS['str_GamesWon']],
'GamesLost' => $entry[$GLOBALS['str_GamesLost']],
'GamesDraw' => $entry[$GLOBALS['str_GamesDraw']],
'GamesWO' => $entry[$GLOBALS['str_GamesWO']],
'IndividualMatchesWon' => $entry[$GLOBALS['str_MatchsWon']],
'IndividualMatchesLost' => $entry[$GLOBALS['str_MatchsLost']],
'IndividualSetsWon' => $entry[$GLOBALS['str_SetsWon']],
'IndividualSetsLost' => $entry[$GLOBALS['str_SetsLost']],
'Points' => $entry[$GLOBALS['str_Score']],
'TeamClub' => $entry[$GLOBALS['str_Club']]);
}
return array('DivisionName' => create_division_title_text(
get_division_info($season, $DivisionId), true),
'RankingEntries' => $res);
}
/**
* @brief Returns list of matches and, if they are available, the match results.
*
* According to the parameters given in the ::GetMatchesRequest, ::GetMatches can be used to
* extract all matches played into a division, by a club or by a given team.
*
* Example for team C of club VLB-225 (Hurricane TTW) for season 2006-2007
* <ul>
* <li><code>01/016 | 01 | 2006-09-15 | 19:45:00 | Hurricane C | Meerdaal D | 12-4</code></li>
* <li><code>02/014 | 02 | 2006-09-22 | 19:45:00 | Essenbeek B | Hurricane C | 6-10</code></li>
* <li><code>03/014 | 03 | 2006-09-29 | 19:45:00 | Hurricane C | V.M.S. B | 12-4</code></li>
* <li><code>04/016 | 04 | 2006-10-20 | 19:45:00 | Hurricane C | Essenbeek D | 13-3</code></li>
* <li>(...)</li>
* </ul>
*
* @param $Request GetMatchesRequest
* @return GetMatchesResponse
* @since Version 0.4
* @version 0.7.23
* @see GetMatchesRequest, GetMatchesResponse
* @ingroup TabTAPIfunctions
*/
function GetMatches(stdClass $Request) {
// Check permissions & quota
$permissions = _MethodAPI(5, isset($Request->Credentials) ? $Request->Credentials : (object)array());
// Extract function arguments
$DivisionId = isset($Request->DivisionId) ? $Request->DivisionId : '';
$Club = isset($Request->Club) ? trim($Request->Club) : '';
$Team = isset($Request->Team) ? trim(strtoupper($Request->Team)) : '';
$DivisionCategory = isset($Request->DivisionCategory) ? $Request->DivisionCategory : '';
$Season = isset($Request->Season) ? trim($Request->Season) : '';
$WeekName = isset($Request->WeekName) ? trim($Request->WeekName) : '';
$LevelId = isset($Request->Level) ? $Request->Level : '';
$ShowDivisionName = isset($Request->ShowDivisionName) ? strtolower(trim($Request->ShowDivisionName)) : '';
if (isset($Request->YearDateFrom)) $YearDateFrom = strtotime($Request->YearDateFrom);
if (isset($Request->YearDateTo)) $YearDateTo = strtotime($Request->YearDateTo);
$WithDetails = isset($Request->WithDetails) && $Request->WithDetails ? true : false;
$MatchId = isset($Request->MatchId) ? mysql_real_escape_string(trim($Request->MatchId)) : '';
$MatchUniqueId = isset($Request->MatchUniqueId) && is_numeric($Request->MatchUniqueId) && $Request->MatchUniqueId > 0 ? intval(trim($Request->MatchUniqueId)) : 0;
// Create database session
$db = new DB_Session();
$db->Halt_On_Error = 'no';
// Check club & division
$Club = str_replace(array('-','/',' '), '', strtoupper($Club));
if (trim($DivisionId) == '' && $Club == '' && $WeekName == '' && $MatchUniqueId == 0) {
throw new SoapFault('13', "DivisionId, Club, WeekName or MatchUniqueId must be given.");
}
// Check division
if ($DivisionId != '' && !is_numeric($DivisionId)) {
throw new SoapFault('2', "DivisionId [{$DivisionId}] is not valid, must be numeric.");
}
if (is_numeric($DivisionId) && $db->select_one("SELECT COUNT(*) FROM divisioninfo WHERE id={$DivisionId};")==0) {
throw new SoapFault('3', "DivisionId [{$DivisionId}] is not valid.");
}
// Check season
if (!isset($Season) || '' == $Season) {
unset($Season);
if (is_numeric($DivisionId)) {
$Season = $db->select_one("SELECT season FROM divisioninfo WHERE id={$DivisionId};");
} elseif (is_numeric($MatchUniqueId) && $MatchUniqueId > 0) {
$Season = $db->select_one("SELECT di.season FROM divisionresults divr, divisioninfo di WHERE divr.match_id={$MatchUniqueId} AND di.id=divr.div_id;");
if ($Season == -1) {
unset($Season);
}
} elseif (isset($YearDateFrom)) {
$Season = $db->select_one("SELECT id FROM seasoninfo WHERE start_date < FROM_UNIXTIME({$YearDateFrom}) AND stop_date > FROM_UNIXTIME({$YearDateFrom});");
if ($Season == -1) {
unset($Season);
}
}
if (!isset($Season)) {
$Season = $db->select_one("SELECT MAX(id) FROM seasoninfo;");
}
}
if (!is_numeric($Season)) {
throw new SoapFault('6', "Season [{$Season}] is not valid, must be numeric.");
}
$Season = intval($Season);
if ($db->select_one("SELECT COUNT(*) FROM seasoninfo WHERE id={$Season}") == 0) {
throw new SoapFault('7', "Season [{$Season}] is not valid.");
}
// Check club
if ($Club != '') {
list($ClubId, $ClubName) = _GetClubInfo($Season, $Club);
if (!is_numeric($ClubId) || $ClubId < 0) {
throw new SoapFault('9', "Club [{$Club}] is not valid.");
}
if (is_numeric($DivisionId)) {
if ($db->select_one("SELECT COUNT(*) FROM divisionteaminfo AS dti WHERE dti.div_id={$DivisionId} AND dti.club_id={$ClubId};") == 0) {
throw new SoapFault('10', "Club [{$Club}] has no team in division [{$DivisionId}]");
}
}
}
// Check team
if ($Team != '' && $Club == '') {
throw new SoapFault('12', "Parameter 'Club' has to be given if parameter 'Team' is set.");
}
if ($Team != '') {
$Team = mysql_real_escape_string($Team);
if (is_numeric($DivisionId)) {
if ($db->select_one("SELECT COUNT(*) FROM divisionteaminfo AS dti WHERE dti.div_id={$DivisionId} AND dti.club_id={$ClubId} AND dti.indice='{$Team}';") == 0) {
throw new SoapFault('11', "Club [{$Club}] has no team [{$Team}] in division [{$DivisionId}]");
}
} else {
if ($db->select_one("SELECT COUNT(*) FROM divisionteaminfo AS dti WHERE dti.club_id={$ClubId} AND dti.indice='{$Team}';") == 0) {
throw new SoapFault('14', "Club [{$Club}] has no team [{$Team}]");
}
}
}
// Check division category
if ($DivisionCategory != '' && !is_numeric($DivisionCategory)) {
throw new SoapFault('15', "DivisionCategory must be a number ([{$DivisionCategory}]).");
}
if ($DivisionCategory != '') {
if ($db->select_one("SELECT COUNT(*) FROM divisioncategories WHERE id={$DivisionCategory};") == 0) {
throw new SoapFault('16', "DivisionCategory [{$DivisionCategory}] does not exists.");
}
}
// Check week name
if ($WeekName != '') {
$WeekName = mysql_real_escape_string(ltrim($WeekName, '0'));
$q = "SELECT week, name FROM calendarweekname WHERE TRIM(LEADING '0' FROM name) LIKE '{$WeekName}';";
list($week, $DatabaseWeekName) = $db->select_one_array($q);
if (!is_numeric($week) || !($week > -1)) {
throw new SoapFault('20', "WeekName [{$WeekName}] is not valid.");
}
}
// Check level
if ($LevelId != '' && !is_numeric($LevelId)) {
throw new SoapFault('18', "Level must be a number ([{$LevelId}]).");
}
if ($LevelId != '') {
$LevelId = intval($LevelId);
if ($db->select_one("SELECT COUNT(*) FROM levelinfo WHERE id={$LevelId};") == 0) {
throw new SoapFault('19', "LevelId [{$LevelId}] does not exists.");
}
}
// Check 'ShowDivisionName' option
if ($ShowDivisionName != '' && !in_array($ShowDivisionName, array('yes', 'no', 'short'))) {
throw new SoapFault('21', "ShowDivisionName [{$ShowDivisionName}] is not valid.");
}
// Check dates
if (isset($YearDateFrom) && $YearDateFrom === false) {
throw new SoapFault('32', "YearDateFrom is not a valid date, please use format YYYY-MM-DD.");
}
if (isset($YearDateTo) && $YearDateTo === false) {
throw new SoapFault('33', "YearDateTo is not a valid date, please use format YYYY-MM-DD.");
}
// More helper functions
include_once($GLOBALS['site_info']['path'].'public/calendar_fct.php');
$matchnum_select = get_select_matchnum('wname', 'di', 'cali', false, '', false);
$date_select = get_date_select('cd', 'team_home', 'team_away', 'cc', -1, '', '%Y-%m-%d');
$hour_select = get_hour_select('team_home', 'cc', true);
$withdraw_select = get_withdraw_select('divr', ' ');
$division_where_clause = is_numeric($DivisionId) ? " di.id={$DivisionId}" : '1';
$club_where_clause = $Club!='' ? "(team_home.club_id={$ClubId} OR team_away.club_id={$ClubId})" : '1';
$team_where_clause = $Team!='' ? "((team_home.club_id={$ClubId} and team_home.indice='{$Team}') OR (team_away.club_id={$ClubId} AND team_away.indice='{$Team}'))" : '1';
$divcat_where_clause = is_numeric($DivisionCategory) ? "di.category={$DivisionCategory}" : '1';
$wname_where_clause = $WeekName!='' ? "wname.name='{$DatabaseWeekName}'" : '1';
$level_where_clause = is_numeric($LevelId) ? "di.level={$LevelId}" : '1';
if (isset($YearDateFrom) || isset($YearDateTo)) {
$date_field = 'UNIX_TIMESTAMP(IFNULL(cc.date, DATE_ADD(cd.date, INTERVAL team_home.day_in_week DAY)))';
if ($YearDateFrom && $YearDateTo) {
$date_where_clause = "({$date_field} BETWEEN {$YearDateFrom} AND {$YearDateTo})";
} elseif ($YearDateFrom) {
$date_where_clause = "({$date_field} >= {$YearDateFrom})";
} elseif ($YearDateTo) {
$date_where_clause = "({$date_field} <= {$YearDateTo})";
}
} else {
$date_where_clause = '1';
}
// Select on a particular match id
// by name
$match_where_clause = '1';
if ($MatchId != '') {
// First try to get match number from the cache (if any)
$MatchUniqueId = get_match_id_from_match_number($Season, $MatchId);
if ($MatchUniqueId <= 0) {
$match_where_clause = "{$matchnum_select} LIKE '{$MatchId}'";
}
}
// by internal id
$uniquematch_where_clause = '1';
if ($MatchUniqueId > 0) {
$uniquematch_where_clause = "divr.match_id={$MatchUniqueId}";
}
// Defines some escape separators
$escape_separators = array(
'§' => '%£+|!1',
'µ' => '%£+|!2'
);
// More additional clauses if details are required
$details_select_clause = '';
$details_from_clause = '';
$groupby_clause = '';
if ($WithDetails) {
$details_select_clause = ",di.match_type_id as `MatchTypeId`";
$details_select_clause .= ",mti.nb_single as `PlayerCount`";
$details_select_clause .= ",mti.nb_double as `DoubleTeamCount`";
$details_select_clause .= ",pi_hc.vttl_index as `HomeCaptain`";
$details_select_clause .= ",pi_ac.vttl_index as `AwayCaptain`";
$details_select_clause .= ",pi_ref.vttl_index as `Referee`";
$details_select_clause .= ",pi_rr.vttl_index as `HallCommissioner`";
if ($MatchUniqueId > 0) {
$details_select_clause .= ",IF(mc.id IS NULL, '', GROUP_CONCAT(DISTINCT CONCAT(mc.id, '§', mc.date, '§', mc.modification_type, '§', pi_authors.vttl_index, '§', pi_authors.first_name, '§', pi_authors.last_name, '§', REPLACE(REPLACE(mc.message, '§', '{$escape_separators['§']}'), 'µ', '{$escape_separators['µ']}')) ORDER BY mc.date DESC SEPARATOR 'µ')) as `MatchComments`";
}
$details_from_clause = " LEFT JOIN matchinfo as mi ON mi.id=divr.match_id";
$details_from_clause .= " LEFT JOIN playerinfo as pi_hc ON mi.home_captain_player_id=pi_hc.id";
$details_from_clause .= " LEFT JOIN playerinfo as pi_ac ON mi.away_captain_player_id=pi_ac.id";
$details_from_clause .= " LEFT JOIN playerinfo as pi_ref ON mi.referee_player_id=pi_ref.id";
$details_from_clause .= " LEFT JOIN playerinfo as pi_rr ON mi.room_responsible_player_id=pi_rr.id";
$details_from_clause .= " LEFT JOIN matchtypeinfo as mti ON mti.id=mi.match_type_id";
$details_from_clause .= " LEFT JOIN matchplayer as mp ON mp.match_id=mi.id";
if ($MatchUniqueId > 0) {
$match_comment_table = get_match_comment_table_query($MatchUniqueId);
$details_from_clause .= " LEFT JOIN {$match_comment_table} as mc ON mc.match_id=mi.id";
$details_from_clause .= " LEFT JOIN auth_user as mc_authors ON mc_authors.user_id=mc.user_id";
$details_from_clause .= " LEFT JOIN playerinfo as pi_authors ON pi_authors.id=mc_authors.player_id";
}
foreach (array('home', 'away') as $homeaway) {
$classement_select_clause = get_classement_select_clause($homeaway . '_ci');
$details_select_clause .= ",IF(mi.id IS NULL, '', GROUP_CONCAT(DISTINCT CONCAT(mp.player_nb, '|', IF(mp.player_nb<=mti.nb_single, {$homeaway}_pi.vttl_index, mp.{$homeaway}_player_id), '|', IF(mp.player_nb<=mti.nb_single, {$homeaway}_pi.first_name, ''), '|', IF(mp.player_nb<=mti.nb_single, {$homeaway}_pi.last_name, ''), '|', IF(mp.player_nb<=mti.nb_single, {$classement_select_clause}, ''), '|', mp.{$homeaway}_vict, '|', mp.{$homeaway}_wo) ORDER BY mp.player_nb)) as `" . ucfirst($homeaway) . "Players`";
$details_from_clause .= " LEFT JOIN playerinfo as {$homeaway}_pi ON {$homeaway}_pi.id=mp.{$homeaway}_player_id LEFT JOIN playerclassement as {$homeaway}_pcl ON {$homeaway}_pcl.season=di.season AND {$homeaway}_pcl.player_id={$homeaway}_pi.id AND {$homeaway}_pcl.category=divc.classementcategory LEFT JOIN classementinfo as {$homeaway}_ci ON {$homeaway}_ci.id={$homeaway}_pcl.classement_id AND {$homeaway}_ci.category=divc.classementcategory";
}
$groupby_clause = 'GROUP BY `MatchId`';
}
// How should we sort the results ?
// By default, use a generic sort order (somehow same as on the website)
$orderby_clause = "di.category, li.order, di.div_id, di.serie, di.order, cali.week, cali.match_nb";
if ($Club != '') {
// If a club has been given, change order so it looks more "logical" for the club (sorted by team letter)
$orderby_clause = "di.category, li.order, IF(team_home.club_id={$ClubId}, team_home.indice, IF(team_away.club_id={$ClubId}, team_away.indice, '')), cali.week, cali.match_nb";
}
// Remember lock time limit (from preferences)
$lock_limit_time = intval(get_pref('locktimelimit', 60*60*6));
$q = <<<EOQ
SELECT
di.id as `DivisionId`,
di.category as `DivisionCategory`,
{$matchnum_select} as `MatchId`,
wname.name as `WeekName`,
{$date_select} as `Date`,
{$hour_select} as `Time`,
IFNULL(club_home.indice, '-') as `HomeClub`,
IF(ISNULL(club_home.name),
IF(team_home.is_bye,
CONCAT('{$GLOBALS['str_Bye']} ', team_home.indice),
'{$GLOBALS['str_UnknownTeam']}'),
CONCAT(IFNULL(club_home.short_name, club_home.name), ' ', team_home.indice)
) as `HomeTeam`,
IFNULL(club_away.indice, '-') as `AwayClub`,
IF(ISNULL(club_away.name),
IF(team_away.is_bye,
CONCAT('{$GLOBALS['str_Bye']} ', team_away.indice),
'{$GLOBALS['str_UnknownTeam']}'),
CONCAT(IFNULL(club_away.short_name, club_away.name), ' ', team_away.indice)
) as `AwayTeam`,
IF(ISNULL(club_home.name), 0, cai.address_id) as `Venue`,
cai_club.indice as `VenueClub`,
cai.name as `VenueEntryName`,
cai.address as `VenueEntryStreet`,
CONCAT(cai.zip, ' ', cai.town) as `VenueEntryTown`,
cai.phone as `VenueEntryPhone`,
cai.comment as `VenueEntryComment`,
IF(team_home.is_bye OR team_away.is_bye OR
IFNULL(divr.home=0 AND divr.away=0 AND divr.home_wo<>'Y' AND divr.away_wo<>'Y' AND divr.score_modified<>'Y' AND team_home.is_withdraw='N' AND team_away.is_withdraw='N', 1),
'-',
CONCAT(IFNULL(divr.home,'...'), '-', IFNULL(divr.away,'...'), {$withdraw_select}, IF(divr.home_wo<>'Y' AND divr.away_wo<>'Y' AND team_home.is_withdraw<>'N' OR team_away.is_withdraw<>'N', ' ({$GLOBALS['str_GW']})', ''))
) as `Score`,
divr.match_id as `MatchUniqueId`,
next_wname.name as `NextWeekName`,
prev_wname.name as `PrevWeekName`,
divr.home_wo='Y' OR team_home.is_withdraw<>'N' as `HomeFF`,
divr.away_wo='Y' OR team_away.is_withdraw<>'N' as `AwayFF`,
team_home.is_withdraw as `HomeWithdrawn`,
team_away.is_withdraw as `AwayWithdrawn`,
NOT divr.validated_by IS NULL as `IsValidated`,
divr.lock_timestamp as `LockTime`,
NOT divr.locked_by IS NULL as `IsLocked`
{$details_select_clause}
FROM
(divisioninfo as di,
calendarinfo as cali,
calendardates as cd,
divisionteaminfo as team_home,
divisionteaminfo as team_away)
LEFT JOIN divisioncategories as divc
ON divc.id=di.category
LEFT JOIN calendarweekname as wname ON 1
and wname.calendar_id=di.calendar_id
and wname.week=cd.week
LEFT JOIN calendarchanges as cc ON 1
and cc.div_id=di.id
and cc.week=cali.week
and cc.match_nb=cali.match_nb
LEFT JOIN calendarweekname as next_wname ON 1
and next_wname.calendar_id=di.calendar_id
and next_wname.week=cd.week+1
LEFT JOIN calendarweekname as prev_wname ON 1
and prev_wname.calendar_id=di.calendar_id
and prev_wname.week=cd.week-1
LEFT JOIN clubs as club_home
ON club_home.id=team_home.club_id
LEFT JOIN clubs as club_away
ON club_away.id=team_away.club_id
LEFT JOIN divisionresults as divr
ON divr.div_id=di.id and
divr.season=di.season and
divr.week=cali.week and
divr.match_nb=cali.match_nb
LEFT JOIN clubaddressinfo as cai
ON cai.club_id=IFNULL(cc.address_club_id, team_home.club_id) and
cai.address_id=IFNULL(cc.address_id, team_home.address_id)
LEFT JOIN clubs as cai_club
ON cai_club.id=cai.club_id
LEFT JOIN levelinfo as li
ON li.id=di.level
{$details_from_clause}
WHERE 1
and di.season={$Season}
and {$division_where_clause}
and cali.calendar_id=di.calendar_id
and cd.calendardate_id=di.calendardate_id
and cd.week=cali.week
and team_home.div_id=di.id
and IF(ISNULL(cc.home), team_home.team_id=cali.home, team_home.team_id=cc.home)
and team_away.div_id=di.id
and IF(ISNULL(cc.away), team_away.team_id=cali.away, team_away.team_id=cc.away)
and {$club_where_clause}
and {$team_where_clause}
and {$divcat_where_clause}
and {$wname_where_clause}
and {$level_where_clause}
and {$date_where_clause}
and {$match_where_clause}
and {$uniquematch_where_clause}
{$groupby_clause}
ORDER BY
{$orderby_clause}
;
EOQ;
$res = array();
$db->query($q);
while ($db->next_record()) {
$divisionname = _GetDivisionName($ShowDivisionName, $Season, $db->Record['DivisionId']);
if ($WithDetails) {
$resDetails = array(
'DetailsCreated' => $db->Record['MatchUniqueId']>0,
'MatchSystem' => $db->Record['MatchTypeId']
);
if ($db->Record['HomeCaptain']) {
$resDetails['HomeCaptain'] = intval($db->Record['HomeCaptain']);
}
if ($db->Record['AwayCaptain']) {
$resDetails['AwayCaptain'] = intval($db->Record['AwayCaptain']);
}
if ($db->Record['Referee']) {
$resDetails['Referee'] = intval($db->Record['Referee']);
}
if ($db->Record['HallCommissioner']) {
$resDetails['HallCommissioner'] = intval($db->Record['HallCommissioner']);
}
$resDetails['CommentCount'] = 0;
if (isset($db->Record['MatchComments']) && strlen(trim($db->Record['MatchComments']))>0) {
$comments = explode('µ', $db->Record['MatchComments']);
if (!isset($resDetails['MatchComments'])) {
$resDetails['CommentCount'] = count($comments);
$resDetails['CommentEntries'] = array();
}
foreach ($comments as $comment_str) {
list($comment_id, $timestamp, $type, $author_id, $author_first_name, $author_last_name, $comment) = explode('§', $comment_str);
$comment = str_replace(array_keys($escape_separators), array_values($escape_separators), $comment);
$resDetails['CommentEntries'][] = array(
'Timestamp' => $timestamp,
'Author' => array(
'UniqueIndex' => $author_id,
'FirstName' => $author_first_name,
'LastName' => $author_last_name
),
'Comment' => $comment,
'Code' => $type
);
}
}
}
if ($WithDetails && $db->Record['MatchUniqueId']>0) {
// We will need a sub-query for scores
$db2 = new DB_Session();
// Players information
foreach (array('Home', 'Away') as $HomeAway) {
$player_list = preg_split('/,/', $db->Record["{$HomeAway}Players"]);
$resDetails["{$HomeAway}Players"] = array(
'PlayerCount' => $db->Record['PlayerCount'],
'DoubleTeamCount' => $db->Record['DoubleTeamCount']
);
foreach ($player_list as $player) {
$player_info = preg_split('/\|/', $player);
if ($player_info[0] <= $db->Record['PlayerCount']) {
if (!isset($resDetails["{$HomeAway}Players"]['Players'])) {
$resDetails["{$HomeAway}Players"]['Players'] = array();
}
${"{$HomeAway}Players"}[$player_info[0]] = $resDetails["{$HomeAway}Players"]['Players'][] = array_merge(
array(
'Position' => $player_info[0],
'UniqueIndex' => $player_info[1],
'FirstName' => $player_info[2],
'LastName' => $player_info[3],
'Ranking' => $player_info[4]
),
$player_info[6] == 0 ? array('VictoryCount' => $player_info[5]) : array(),
$player_info[6] > 0 ? array('IsForfeited' => true) : array()
);
} else {
if (!isset($resDetails["{$HomeAway}Players"]['DoubleTeams'])) {
$resDetails["{$HomeAway}Players"]['DoubleTeams'] = array();
}
$resDetails["{$HomeAway}Players"]['DoubleTeams'][] = array(
'Position' => $player_info[0],
'Team' => $player_info[1]
);
}
}
}
// Get scores
$match_scores_query = <<<EOQ
SELECT
mr.match_id,
mr.game_id as game_id,
IFNULL(mpe.home_player_nb, mtp.home_player) as home_position,
IF(mtp.player_nb=1, home_pi.vttl_index, home_mp.home_player_id) as home_index,
IFNULL(mpe.away_player_nb, mtp.away_player) as away_position,
IF(mtp.player_nb=1, away_pi.vttl_index, away_mp.away_player_id) as away_index,
GROUP_CONCAT(CONCAT(mr.set_id, '|', IF(mr.points={$GLOBALS['zero_for_set']}, '0', IF(mr.points=-{$GLOBALS['zero_for_set']}, '-0', mr.points))) ORDER BY mr.set_id) as scores,
SUM(mr.points>0) as home_sets,
SUM(mr.points<0) as away_sets,
MAX(mr.home_wo) as home_wo,
MAX(mr.away_wo) as away_wo,
(SELECT COUNT(*) FROM matchresults WHERE match_id=mr.match_id AND points<>{$GLOBALS['zero_for_set']} AND points<>-{$GLOBALS['zero_for_set']})=0 as set_only,
mtp.player_nb as player_nb
FROM
matchresults as mr
LEFT JOIN matchinfo as mi ON mi.id=mr.match_id
LEFT JOIN matchtypeplayer as mtp ON mtp.match_type_id=mi.match_type_id AND mtp.game_nb=mr.game_id
LEFT JOIN matchplayerexception mpe ON mpe.match_id=mi.id AND mpe.game_nb=mtp.game_nb
LEFT JOIN matchplayer as home_mp ON home_mp.match_id=mr.match_id AND home_mp.player_nb=IFNULL(mpe.home_player_nb, mtp.home_player) LEFT JOIN playerinfo as home_pi ON home_pi.id=home_mp.home_player_id
LEFT JOIN matchplayer as away_mp ON away_mp.match_id=mr.match_id AND away_mp.player_nb=IFNULL(mpe.away_player_nb, mtp.away_player) LEFT JOIN playerinfo as away_pi ON away_pi.id=away_mp.away_player_id
WHERE mr.match_id={$db->Record['MatchUniqueId']}
GROUP BY mr.game_id
EOQ;
// Get double teams
$count = 0;
$DoubleTeams = array();
for ($i=1; $i<=$db->Record['PlayerCount']; $i++) {
for ($j=$i+1; $j<=$db->Record['PlayerCount']; $j++) {
$DoubleTeams[++$count] = array($i, $j);
}
}
$db2->query($match_scores_query);
$HomeScore = 0;
$AwayScore = 0;
while ($db2->next_record()) {
// Prepare
switch ($db2->Record['player_nb']) {
case 1:
default:
$HomePlayerMatchIndex = $db2->Record['home_position'];
$HomePlayerUniqueIndex = $db2->Record['home_index'];
$AwayPlayerMatchIndex = $db2->Record['away_position'];
$AwayPlayerUniqueIndex = $db2->Record['away_index'];
break;
case 2:
$HomePlayerMatchIndex = $DoubleTeams[$db2->Record['home_index']];
$AwayPlayerMatchIndex = $DoubleTeams[$db2->Record['away_index']];
$HomePlayerUniqueIndex = array($HomePlayers[$HomePlayerMatchIndex[0]]['UniqueIndex'], $HomePlayers[$HomePlayerMatchIndex[1]]['UniqueIndex']);
$AwayPlayerUniqueIndex = array($AwayPlayers[$AwayPlayerMatchIndex[0]]['UniqueIndex'], $AwayPlayers[$AwayPlayerMatchIndex[1]]['UniqueIndex']);
break;
}
// Build individual match results
$IndividualMatchResult = array_merge(
array(
'Position' => $db2->Record['game_id'],
'HomePlayerMatchIndex' => $HomePlayerMatchIndex,
'HomePlayerUniqueIndex' => $HomePlayerUniqueIndex,
'AwayPlayerMatchIndex' => $AwayPlayerMatchIndex,
'AwayPlayerUniqueIndex' => $AwayPlayerUniqueIndex
),
$db2->Record['home_wo'] > 0 ? array('IsHomeForfeited' => true) : array('HomeSetCount' => $db2->Record['home_sets']),
$db2->Record['away_wo'] > 0 ? array('IsAwayForfeited' => true) : array('AwaySetCount' => $db2->Record['away_sets'])
);
if ($db2->Record['home_wo'] == 0 && $db2->Record['away_wo'] == 0 && !$db2->Record['set_only']) {
$IndividualMatchResult['Scores'] = $db2->Record['scores'];
}
$resDetails['IndividualMatchResults'][] = $IndividualMatchResult;
// Calculate score
if ($db2->Record['home_sets'] > $db2->Record['away_sets']) {
$HomeScore++;
}
if ($db2->Record['away_sets'] > $db2->Record['home_sets']) {
$AwayScore++;
}
}
$db2->free();
// Add match score
$resDetails['HomeScore'] = $HomeScore;
$resDetails['AwayScore'] = $AwayScore;
}
unset($db2);
// Build response
$res[] = array_merge(
$divisionname=='' ?
array() :
array('DivisionName' => $divisionname),
array(
'DivisionId' => $db->Record['DivisionId'],
'DivisionCategory' => $db->Record['DivisionCategory'],
'MatchId' => $db->Record['MatchId'],
'WeekName' => $db->Record['WeekName']
),
$db->Record['Date'] == '-' ?
array() :
array(
'Date' => $db->Record['Date'],
'Time' => $db->Record['Time']
),
$db->Record['Date'] != '-' && is_numeric($db->Record['Venue']) && $db->Record['Venue']>=1 ?
array(
'Venue' => $db->Record['Venue'],
'VenueClub' => $db->Record['VenueClub'],
'VenueEntry' => array(
'Name' => $db->Record['VenueEntryName'],
'Street' => $db->Record['VenueEntryStreet'],
'Town' => $db->Record['VenueEntryTown'],
'Phone' => $db->Record['VenueEntryPhone'],
'Comment' => $db->Record['VenueEntryComment']
)
) :
array(),
array(
'HomeClub' => $db->Record['HomeClub'],
'HomeTeam' => $db->Record['HomeTeam'],
'AwayClub' => $db->Record['AwayClub'],
'AwayTeam' => $db->Record['AwayTeam']
),
$db->Record['Score'] == '-' ?
array() :
array('Score' => $db->Record['Score']),
is_numeric($db->Record['MatchUniqueId']) && $db->Record['MatchUniqueId']>0 ?
array('MatchUniqueId' => $db->Record['MatchUniqueId']) :
array(),
$db->Record['NextWeekName'] != '' ?
array('NextWeekName' => $db->Record['NextWeekName']) :
array(),
$db->Record['PrevWeekName'] != '' ?
array('PreviousWeekName' => $db->Record['PrevWeekName']) :
array(),
array(
'IsHomeForfeited' => $db->Record['HomeFF'],
'IsAwayForfeited' => $db->Record['AwayFF'],
'IsHomeWithdrawn' => $db->Record['HomeWithdrawn'],
'IsAwayWithdrawn' => $db->Record['AwayWithdrawn'],
'IsValidated' => $db->Record['IsValidated'],
'IsLocked' => $db->Record['IsValidated'] || ($db->Record['IsLocked'] && ($lock_limit_time < 0 ? true : strtotime($db->Record['LockTime']) + $lock_limit_time < time()))
),
$WithDetails ?
array('MatchDetails' => $resDetails) :
array()
);
}
// Release database connection
$db->free();
unset($db);
return array('MatchCount' => count($res), 'TeamMatchesEntries' => $res);
}
/**
* @brief Returns list of members according to a search criteria (club, index or name)
*
* Each player belongs to a club. ::GetMembers can return the list of all players of a given club.
*
* As an example, here is the member list of club VLB-225 (Hurricane TTW) for season 2007-2008:
* <ul>
* <li><code>1 | 505304 | 5 | MARC | DE DONCKER | B6</code></li>
* <li><code>2 | 505292 | 5 | DAVID | WAEFELAER | B6</code></li>
* <li>(...)</li>
* <li><code>7 | 505384 | 8 | MICHEL | THAUVOYE | C2</code></li>
* <li><code>8 | 505783 | 8 | PASCAL | TIMMERMANS | C2</code></li>
* <li>(...)</li>
* <li><code>17 | 505290 | 20 | GAËTAN | FRENOY | C6</code></li>
* <li><code>18 | 505275 | 20 | CHRISTIAN | HOLTYZER | C6</code></li>
* <li>(...)</li>
* </ul>
*
* You can also query information about a specific player. A player is identified by a unique index.
*
* You can also search players based on their name (first name or last name).
*
* If "WithResults" is set, player results will be returned along with player details.
*
* @param $Request GetMembersRequest
* @return GetMembersResponse