1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
11
|
|
|
use Doctrine\ORM\Mapping\Index; |
12
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
13
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
14
|
|
|
use Doctrine\ORM\Mapping\Table; |
15
|
|
|
use Stu\Orm\Repository\BuildingCostRepository; |
16
|
|
|
|
17
|
|
|
#[Table(name: 'stu_buildings_cost')] |
18
|
|
|
#[Index(name: 'building_cost_building_idx', columns: ['buildings_id'])] |
19
|
|
|
#[Entity(repositoryClass: BuildingCostRepository::class)] |
20
|
|
|
class BuildingCost |
21
|
|
|
{ |
22
|
|
|
#[Id] |
23
|
|
|
#[Column(type: 'integer')] |
24
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
25
|
|
|
private int $id; |
26
|
|
|
|
27
|
|
|
#[Column(type: 'integer')] |
28
|
|
|
private int $buildings_id = 0; |
29
|
|
|
|
30
|
|
|
#[Column(type: 'integer')] |
31
|
|
|
private int $commodity_id = 0; |
32
|
|
|
|
33
|
|
|
#[Column(type: 'integer')] |
34
|
|
|
private int $count = 0; |
35
|
|
|
|
36
|
|
|
#[ManyToOne(targetEntity: Commodity::class)] |
37
|
|
|
#[JoinColumn(name: 'commodity_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
38
|
|
|
private Commodity $commodity; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Building |
42
|
|
|
*/ |
43
|
|
|
#[ManyToOne(targetEntity: Building::class, inversedBy: 'buildingCosts')] |
44
|
|
|
#[JoinColumn(name: 'buildings_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
45
|
|
|
private $building; |
|
|
|
|
46
|
|
|
|
47
|
|
|
public function getId(): int |
48
|
|
|
{ |
49
|
|
|
return $this->id; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getBuildingId(): int |
53
|
|
|
{ |
54
|
|
|
return $this->buildings_id; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setBuildingId(int $buildingId): BuildingCost |
58
|
|
|
{ |
59
|
|
|
$this->buildings_id = $buildingId; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getCommodityId(): int |
65
|
|
|
{ |
66
|
|
|
return $this->commodity_id; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setCommodityId(int $commodityId): BuildingCost |
70
|
|
|
{ |
71
|
|
|
$this->commodity_id = $commodityId; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getAmount(): int |
77
|
|
|
{ |
78
|
|
|
return $this->count; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setAmount(int $amount): BuildingCost |
82
|
|
|
{ |
83
|
|
|
$this->count = $amount; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getCommodity(): Commodity |
89
|
|
|
{ |
90
|
|
|
return $this->commodity; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getHalfAmount(): int |
94
|
|
|
{ |
95
|
|
|
return (int) ceil($this->getAmount() / 2); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|