initial commit
[namibia] / module / Stock / src / Stock / Entity / StockDamage.php
1 <?php
2 namespace Stock\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * @ORM\Entity
10  * @ORM\Table(name="stock_damages")
11  */
12 class StockDamage
13 {
14
15         /**
16          * Can archive records.
17          */
18         const ARCHIVE = true;
19         /**
20          * Pull Synchronization Strategy for this table.
21          */
22         const PULL_SYNCH_STRATEGY = 'Build';
23         /**
24          * Push Synchronization Strategy for this table.
25          */
26         const PUSH_SYNCH_STRATEGY = 'Build';
27
28
29         /**
30          * @ORM\Id
31          * @ORM\Column(type="integer");
32          * @ORM\GeneratedValue(strategy="AUTO")
33          */
34         protected $id;
35
36         /**
37          * @ORM\ManyToOne(targetEntity="Stock", inversedBy="damages")
38          * @ORM\JoinColumn(name="stock_id", referencedColumnName="id")
39          **/
40         protected $stock;
41
42         /**
43          * @ORM\ManyToOne(targetEntity="Damage")
44          * @ORM\JoinColumn(name="vehicle_damage_id", referencedColumnName="id")
45          **/
46         protected $damage;
47
48         /**
49          * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, options={"unsigned"=true});
50          */
51         protected $amount = 0.0;
52
53         /**
54          * @ORM\Column(type="boolean");
55          */
56         protected $archived = false;
57
58
59
60         /**
61          * Magic getter to expose protected properties.
62          * @param string $property
63          * @return mixed
64          */
65         public function __get($property)
66         {
67                 return $this->$property;
68         }
69
70         /**
71          * Magic setter to save protected properties.
72          * @param string $property
73          * @param mixed $value
74          */
75         public function __set($property, $value)
76         {
77                 $this->$property = $value;
78         }
79
80         /**
81          * Convert the object to an array.
82          * @param array $expand
83          * @param array $intersect
84          * @return array
85          */
86         public function toArray(
87                         array $expand = array(), array $intersect = array(), $showIdentifiers = false
88                         )
89         {
90                 $includeAll = empty($intersect);
91                 $data = array();
92                 ($includeAll || isset($intersect['id']))
93                         && $data['id'] = $this->id;
94                 ($includeAll || isset($intersect['damage']))
95                         && $data['damage'] = $showIdentifiers
96                                                                         ? $this->damage->id
97                                                                         : $this->damage->toArray();
98                 ($includeAll || isset($intersect['amount']))
99                         && $data['amount'] = $this->amount;
100                 return $data;
101         }
102
103         /**
104          * Convert the object to an array for synchronization.
105          * @return array
106          */
107         public function toSynchArray()
108         {
109                 return array(
110                                 'id'   => $this->id,
111                                 'name' => $this->name
112                 );
113         }
114
115         /**
116          * Populate from an array.
117          * @param array $data
118          */
119         public function fromArray($data = array())
120         {
121                 isset($data['id'])
122                         && $this->id = $data['id'];
123                 isset($data['stock'])
124                         && $this->stock  = $data['stock'];
125                 isset($data['damage'])
126                         && $this->damage  = $data['damage'];
127                 isset($data['amount'])
128                         && $this->amount  = $data['amount'];
129         }
130
131 }