-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTestController.php
More file actions
executable file
·125 lines (100 loc) · 3.11 KB
/
TestController.php
File metadata and controls
executable file
·125 lines (100 loc) · 3.11 KB
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
<?php
namespace EUFTest;
use EUFTest\Controller\EUFFetcher;
/**
* Class for the exercise.
*/
class TestController extends EUFFetcher
{
public function RetrieveCountries()
{
$json = $this->api->apiGetRequest("getCountries", null);
$array = json_decode($json, true);
return $array['CountryName'];
}
public function RetrieveCountryRecords()
{
$json = $this->api->apiGetRequest("getCountries", null);
$array = json_decode($json, true);
return $array;
}
public function RetrieveUniversities($countryID)
{
$params['CountryID'] = $countryID;
$json = $this->api->apiGetRequest("getInstitutions", $params);
$array = json_decode($json, true);
return array_column($array, 'NameInLatinCharacterSet');
}
private function NationalFlag($cid)
{
$flagmap['2'] = "aw";
$flagmap['1'] = "at";
$flagmap['3'] = "be";
$flagmap['4'] = "bg";
$flagmap['18'] = "hr";
$flagmap['6'] = "cy";
$flagmap['39'] = "cw";
$flagmap['7'] = "cz";
$flagmap['9'] = "dk";
$flagmap['10'] = "ee";
$flagmap['12'] = "fi";
$flagmap['27'] = "mk";
$flagmap['13'] = "fr";
$flagmap['15'] = "gi";
$flagmap['17'] = "gr";
$flagmap['16'] = "gl";
$flagmap['19'] = "hu";
$flagmap['21'] = "is";
$flagmap['20'] = "ir";
$flagmap['22'] = "it";
$flagmap['26'] = "lv";
$flagmap['23'] = "li";
$flagmap['24'] = "lt";
$flagmap['25'] = "lu";
$flagmap['28'] = "mt";
$flagmap['30'] = "nl";
$flagmap['29'] = "nc";
$flagmap['31'] = "no";
$flagmap['32'] = "pl";
$flagmap['33'] = "pt";
$flagmap['34'] = "ro";
$flagmap['40'] = "sb";
$flagmap['37'] = "sk";
$flagmap['36'] = "si";
$flagmap['11'] = "es";
$flagmap['35'] = "se";
$flagmap['5'] = "ch";
$flagmap['38'] = "tr";
$flagmap['14'] = "gb";
$flagmap['8'] = "de";
return $flagmap[$cid] ?? 'xx';
}
public function render()
{
$html = '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">';
$crecords = $this->RetrieveCountryRecords();
foreach($crecords as $record)
{
$country = $record['CountryName'];
$cid = $record['ID'];
$universities = $this->RetrieveUniversities($cid);
$flag = $this->NationalFlag($cid);
$html .= '<div class="panel panel-default">';
$html .= '<div class="panel-heading" role="tab" id="heading'.$cid.'">';
$html .= '<h4 class="panel-title">';
$html .= '<span class="flag-icon flag-icon-'.$flag.'"></span>';
$html .= '<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$cid.'" aria-expanded="false" aria-controls="collapse'.$cid.'">';
$html .= $country.' ('.count($universities).' Universities)';
$html .= '</a></h4></div>';
foreach($universities as $univ)
{
$html .= '<div id="collapse'.$cid.'" class="panel-collapse collapse " role="tabpanel" aria-labelledby="heading'.$cid.'">';
$html .= '<div class="panel-body">';
$html .= $univ;
$html .='</div></div></div>';
}
}
$html .= '</div>';
return $html;
}
}