5 use Domain\Entities\StepMania\ISimfile
;
6 use Domain\Entities\StepMania\IPack
;
10 private static $_countryCodes =
12 'AF' => 'Afghanistan',
13 'AX' => 'Åland Islands',
16 'AS' => 'American Samoa',
21 'AG' => 'Antigua and Barbuda',
37 'BA' => 'Bosnia and Herzegovina',
39 'BV' => 'Bouvet Island',
41 'IO' => 'British Indian Ocean Territory',
42 'BN' => 'Brunei Darussalam',
44 'BF' => 'Burkina Faso',
50 'KY' => 'Cayman Islands',
51 'CF' => 'Central African Republic',
55 'CX' => 'Christmas Island',
56 'CC' => 'Cocos (Keeling) Islands',
61 'CK' => 'Cook Islands',
63 'CI' => 'Côte D\'Ivoire',
67 'CZ' => 'Czech Republic',
71 'DO' => 'Dominican Republic',
74 'SV' => 'El Salvador',
75 'GQ' => 'Equatorial Guinea',
79 'FK' => 'Falkland Islands (Malvinas)',
80 'FO' => 'Faroe Islands',
84 'GF' => 'French Guiana',
85 'PF' => 'French Polynesia',
86 'TF' => 'French Southern Territories',
101 'GW' => 'Guinea-Bissau',
104 'HM' => 'Heard Island and Mcdonald Islands',
105 'VA' => 'Vatican City State',
112 'IR' => 'Iran, Islamic Republic of',
115 'IM' => 'Isle of Man',
122 'KZ' => 'Kazakhstan',
125 'KP' => 'Korea, Democratic People\'s Republic of',
126 'KR' => 'Korea, Republic of',
128 'KG' => 'Kyrgyzstan',
129 'LA' => 'Lao People\'s Democratic Republic',
134 'LY' => 'Libyan Arab Jamahiriya',
135 'LI' => 'Liechtenstein',
137 'LU' => 'Luxembourg',
139 'MK' => 'Macedonia, the Former Yugoslav Republic of',
140 'MG' => 'Madagascar',
146 'MH' => 'Marshall Islands',
147 'MQ' => 'Martinique',
148 'MR' => 'Mauritania',
152 'FM' => 'Micronesia, Federated States of',
153 'MD' => 'Moldova, Republic of',
156 'ME' => 'Montenegro',
157 'MS' => 'Montserrat',
159 'MZ' => 'Mozambique',
164 'NL' => 'Netherlands',
165 'AN' => 'Netherlands Antilles',
166 'NC' => 'New Caledonia',
167 'NZ' => 'New Zealand',
172 'NF' => 'Norfolk Island',
173 'MP' => 'Northern Mariana Islands',
178 'PS' => 'Palestinian Territory, Occupied',
180 'PG' => 'Papua New Guinea',
183 'PH' => 'Philippines',
187 'PR' => 'Puerto Rico',
191 'RU' => 'Russian Federation',
193 'SH' => 'Saint Helena',
194 'KN' => 'Saint Kitts and Nevis',
195 'LC' => 'Saint Lucia',
196 'PM' => 'Saint Pierre and Miquelon',
197 'VC' => 'Saint Vincent and the Grenadines',
199 'SM' => 'San Marino',
200 'ST' => 'Sao Tome and Principe',
201 'SA' => 'Saudi Arabia',
204 'SC' => 'Seychelles',
205 'SL' => 'Sierra Leone',
209 'SB' => 'Solomon Islands',
211 'ZA' => 'South Africa',
212 'GS' => 'South Georgia and the South Sandwich Islands',
217 'SJ' => 'Svalbard and Jan Mayen',
220 'CH' => 'Switzerland',
221 'SY' => 'Syrian Arab Republic',
222 'TW' => 'Taiwan, Province of China',
223 'TJ' => 'Tajikistan',
224 'TZ' => 'Tanzania, United Republic of',
226 'TL' => 'Timor-Leste',
230 'TT' => 'Trinidad and Tobago',
233 'TM' => 'Turkmenistan',
234 'TC' => 'Turks and Caicos Islands',
238 'AE' => 'United Arab Emirates',
239 'GB' => 'United Kingdom',
240 'US' => 'United States',
241 'UM' => 'United States Minor Outlying Islands',
243 'UZ' => 'Uzbekistan',
247 'VG' => 'Virgin Islands, British',
248 'VI' => 'Virgin Islands, U.S.',
249 'WF' => 'Wallis and Futuna',
250 'EH' => 'Western Sahara',
256 public static function countryNameToCode($name)
258 return array_search($name, self
::$_countryCodes);
261 public static function countryNameFromLatLong($lat, $long)
263 $url = 'http://maps.google.com/maps/api/geocode/json?address=' . $lat .',' . $long .'&sensor=false';
264 $get = file_get_contents($url);
265 $geoData = json_decode($get);
266 if (json_last_error() !== JSON_ERROR_NONE
) {
267 throw new \
InvalidArgumentException('Invalid geocoding results');
270 if(isset($geoData->results
[0])) {
271 foreach($geoData->results
[0]->address_components
as $addressComponent) {
272 if(in_array('country', $addressComponent->types
)) {
273 return $addressComponent->long_name
;
280 public static function bytesToHumanReadable($bytes, $dec = 2)
282 if(!is_int($bytes)) throw new \
Exception('Bytes must be an int.' . var_dump($bytes));
284 //Shamelessly stolen from stackoverflow: http://stackoverflow.com/questions/15188033/human-readable-file-size
285 $size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
286 $factor = floor((strlen($bytes) - 1) / 3);
288 return sprintf("%.{$dec}f", $bytes / pow(1000, $factor)) . @$size[$factor];
291 public static function packToArray(IPack
$pack)
294 'title'=> $pack->getTitle(),
295 'contributors' => $pack->getContributors(),
296 'simfiles' => self
::getPackSimfilesArray($pack),
297 'banner' => $pack->getBanner() ?
'files/banner/' . $pack->getBanner()->getHash() : 'files/banner/default',
298 'mirrors' => self
::getPackMirrorsArray($pack),
299 'size' => $pack->getFile() ? self
::bytesToHumanReadable($pack->getFile()->getSize()) : null
,
300 'uploaded' => $pack->getFile() ?
date('F jS, Y', $pack->getFile()->getUploadDate()) : null
,
301 'hash' => $pack->getFile() ?
$pack->getFile()->getHash() : null
305 public static function getPackMirrorsArray(IPack
$pack)
307 $packMirrors = array();
311 $packMirrors[] = array('source' => 'DivinElegy', 'uri' => 'files/pack/' . $pack->getFile()->getHash());
314 if($pack->getFile()->getMirrors())
316 foreach($pack->getFile()->getMirrors() as $mirror)
318 $packMirrors[] = array('source' => $mirror->getSource(), 'uri' => $mirror->getUri());
325 public static function getPackSimfilesArray(IPack
$pack)
327 $packSimfiles = array();
328 foreach($pack->getSimfiles() as $simfile)
330 $packSimfiles[] = self
::simfileToArray($simfile);
333 return $packSimfiles;
336 public static function simfileToArray(Entities\StepMania\ISimfile
$simfile)
338 $singleSteps = array();
339 $doubleSteps = array();
341 foreach($simfile->getSteps() as $steps)
343 $stepDetails = array(
344 'artist' => $steps->getArtist()->getTag(),
345 'difficulty' => $steps->getDifficulty()->getITGName(),
346 'rating' => $steps->getRating()
349 if($steps->getMode()->getPrettyName() == 'Single')
351 $singleSteps[] = $stepDetails;
353 $doubleSteps[] = $stepDetails;
358 'title' => $simfile->getTitle(),
359 'artist' => $simfile->getArtist()->getName(),
361 'single' => $singleSteps,
362 'double' => $doubleSteps
364 'bgChanges' => $simfile->hasBgChanges() ?
'Yes' : 'No',
365 'fgChanges' => $simfile->hasFgChanges() ?
'Yes' : 'No',
366 'bpmChanges' => $simfile->hasBPMChanges() ?
'Yes' : 'No',
367 'banner' => $simfile->getBanner() ?
'files/banner/' . $simfile->getBanner()->getHash() : 'files/banner/default',
368 'download' => $simfile->getSimfile() ?
'files/simfile/' . $simfile->getSimfile()->getHash() : null
,
369 'size' => $simfile->getSimfile() ? Util
::bytesToHumanReadable($simfile->getSimfile()->getSize()) : null
,
370 'uploaded' => $simfile->getSimfile() ?
date('F jS, Y', $simfile->getSimfile()->getUploadDate()) : null
,
371 'hash' => $simfile->getSimfile() ?
$simfile->getSimfile()->getHash() : null