1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains functionality relating to the countries players are allowed to set in their profiles as their location |
4
|
|
|
* |
5
|
|
|
* @package BZiON\Models |
6
|
|
|
* @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A country |
11
|
|
|
*/ |
12
|
|
|
class Country extends Model implements NamedModel |
13
|
|
|
{ |
14
|
|
|
/** @var string The name of the country */ |
15
|
|
|
protected $name; |
16
|
|
|
|
17
|
|
|
/** @var string The ISO code of the country */ |
18
|
|
|
protected $iso; |
19
|
|
|
|
20
|
|
|
const DELETED_COLUMN = 'is_deleted'; |
21
|
|
|
const TABLE = 'countries'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
protected function assignResult($country) |
27
|
|
|
{ |
28
|
|
|
$this->name = $country['name']; |
29
|
|
|
$this->iso = $country['iso']; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the name of the country in the default language |
34
|
|
|
* |
35
|
1 |
|
* @return string The name of the country |
36
|
|
|
*/ |
37
|
1 |
|
public function getName() |
38
|
1 |
|
{ |
39
|
1 |
|
return $this->name; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the ISO code of a country |
44
|
|
|
* |
45
|
|
|
* @return string The ISO code of the country |
46
|
1 |
|
*/ |
47
|
|
|
public function getISO() |
48
|
1 |
|
{ |
49
|
|
|
return $this->iso; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the HTML to display a specific flag |
54
|
|
|
* |
55
|
|
|
* @return string HTML to generate a flag |
56
|
1 |
|
*/ |
57
|
|
|
public function getFlagLiteral() |
58
|
1 |
|
{ |
59
|
|
|
return '<div class="c-flag ' . $this->getFlagCssClass() . '" aria-hidden="true" title="' . $this->getName() . '"></div>'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the country's flag's CSS class |
64
|
|
|
* |
65
|
|
|
* @return string The URL to the country's flag |
66
|
1 |
|
*/ |
67
|
|
|
private function getFlagCssClass() |
68
|
1 |
|
{ |
69
|
|
|
return "c-flag--" . strtolower($this->getISO()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get a query builder for countries |
74
|
|
|
* |
75
|
|
|
* @throws Exception When no database is configured for BZiON |
76
|
|
|
* |
77
|
|
|
* @return QueryBuilderFlex |
78
|
|
|
*/ |
79
|
|
|
public static function getQueryBuilder() |
80
|
|
|
{ |
81
|
|
|
return QueryBuilderFlex::createForModel(Country::class) |
|
|
|
|
82
|
|
|
->setNameColumn('name') |
83
|
|
|
; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.