-
Notifications
You must be signed in to change notification settings - Fork 2
/
Country.php
160 lines (142 loc) · 3.37 KB
/
Country.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
<?php
/*
* This file is part of the OrkestraApplicationBundle package.
*
* Copyright (c) Orkestra Community
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
namespace Orkestra\Bundle\ApplicationBundle\Entity\Contact;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Orkestra\Bundle\ApplicationBundle\Model\Contact\CountryInterface;
use Orkestra\Bundle\ApplicationBundle\Model\Contact\RegionInterface;
use Orkestra\Common\Entity\AbstractEntity;
/**
* A country
*
* @ORM\Entity
* @ORM\Table(name="orkestra_countries")
*/
class Country extends AbstractEntity implements CountryInterface
{
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=30)
*/
protected $name;
/**
* @var string $code The ISO 3166-1 2 letter code
*
* @ORM\Column(name="code", type="string", length=10)
*/
protected $code;
/**
* @var string $longCode The ISO 3166-2 3 letter code
*
* @ORM\Column(name="long_code", type="string", length=10)
*/
protected $longCode;
/**
* @var \Doctrine\Common\Collections\Collection Collection of region entities
*
* @ORM\OneToMany(targetEntity="Orkestra\Bundle\ApplicationBundle\Model\Contact\RegionInterface", mappedBy="country", cascade={"persist"})
*/
protected $regions;
/**
* Constructor
*
* @param string $name The name of the country
* @param string $code The 2-letter ISO abbreviation
* @param string $longCode The 3-letter ISO abbreviation
*/
public function __construct($name = '', $code = '', $longCode = '')
{
$this->regions = new ArrayCollection();
if (!empty($name)) { $this->name = $name; }
if (!empty($code)) { $this->code = $code; }
if (!empty($longCode)) { $this->longCode = $longCode; }
}
/**
* @return string The name of the country
*/
public function __toString()
{
return sprintf('%s', $this->getName());
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set code
*
* @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* Get code
*
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set longCode
*
* @param string $longCode
*/
public function setLongCode($longCode)
{
$this->longCode = $longCode;
}
/**
* Get longCode
*
* @return string
*/
public function getLongCode()
{
return $this->longCode;
}
/**
* Add a region to this country
*
* @param \Orkestra\Bundle\ApplicationBundle\Model\Contact\RegionInterface $region
*/
public function addRegion(RegionInterface $region)
{
$region->setCountry($this);
$this->regions->add($region);
}
/**
* Get regions
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRegions()
{
return $this->regions;
}
}