1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 17.08.2016 22:07 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace V2Fleet; |
7
|
|
|
|
8
|
|
|
use V2Unit\V2UnitList; |
9
|
|
|
use Vector\Vector; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class V2FleetModel |
13
|
|
|
* |
14
|
|
|
* @method V2FleetContainer getContainer() |
15
|
|
|
* @method V2FleetContainer fromArray(array $array) |
16
|
|
|
* |
17
|
|
|
* @package V2Fleet |
18
|
|
|
*/ |
19
|
|
|
class V2FleetModel extends \EntityModel { |
20
|
|
|
/** |
21
|
|
|
* Name of table for this entity |
22
|
|
|
* |
23
|
|
|
* @var string $tableName |
24
|
|
|
*/ |
25
|
|
|
protected $tableName = 'fleets'; |
26
|
|
|
/** |
27
|
|
|
* Name of key field field in this table |
28
|
|
|
* |
29
|
|
|
* @var string $idField |
30
|
|
|
*/ |
31
|
|
|
protected $idField = 'fleet_id'; |
32
|
|
|
|
33
|
|
|
// protected $exceptionClass = 'EntityException'; |
|
|
|
|
34
|
|
|
protected $entityContainerClass = 'V2Fleet\V2FleetContainer'; |
35
|
|
|
|
36
|
|
|
protected $properties = array( |
37
|
|
|
'dbId' => array(P_DB_FIELD => 'fleet_id',), |
38
|
|
|
'ownerId' => array(P_DB_FIELD => 'fleet_owner',), |
39
|
|
|
'missionType' => array(P_DB_FIELD => 'fleet_mission'), |
40
|
|
|
|
41
|
|
|
'fleet_amount' => array(P_DB_FIELD => 'fleet_amount'), |
42
|
|
|
'fleet_start_planet_id' => array(P_DB_FIELD => 'fleet_start_planet_id'), |
43
|
|
|
|
44
|
|
|
// 'fleet_start_galaxy' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
|
|
|
45
|
|
|
// 'fleet_start_system' => array(P_DB_FIELD => 'fleet_start_system'), |
46
|
|
|
// 'fleet_start_planet' => array(P_DB_FIELD => 'fleet_start_planet'), |
47
|
|
|
// 'fleet_start_type' => array(P_DB_FIELD => 'fleet_start_type'), |
48
|
|
|
|
49
|
|
|
'fleet_end_planet_id' => array(P_DB_FIELD => 'fleet_end_planet_id'), |
50
|
|
|
|
51
|
|
|
// 'fleet_end_galaxy' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
|
|
|
|
52
|
|
|
// 'fleet_end_system' => array(P_DB_FIELD => 'fleet_end_system'), |
53
|
|
|
// 'fleet_end_planet' => array(P_DB_FIELD => 'fleet_end_planet'), |
54
|
|
|
// 'fleet_end_type' => array(P_DB_FIELD => 'fleet_end_type'), |
55
|
|
|
|
56
|
|
|
'fleet_resource_metal' => array(P_DB_FIELD => 'fleet_resource_metal'), |
57
|
|
|
'fleet_resource_crystal' => array(P_DB_FIELD => 'fleet_resource_crystal'), |
58
|
|
|
'fleet_resource_deuterium' => array(P_DB_FIELD => 'fleet_resource_deuterium'), |
59
|
|
|
'fleet_target_owner' => array(P_DB_FIELD => 'fleet_target_owner'), |
60
|
|
|
'fleet_group' => array(P_DB_FIELD => 'fleet_group'), |
61
|
|
|
'fleet_mess' => array(P_DB_FIELD => 'fleet_mess'), |
62
|
|
|
|
63
|
|
|
'vectorDeparture' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
64
|
|
|
'vectorArrive' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
65
|
|
|
|
66
|
|
|
'timeDeparture' => array(P_DB_FIELD => 'start_time'), |
67
|
|
|
'timeArrive' => array(P_DB_FIELD => 'fleet_start_time'), |
68
|
|
|
'timeComplete' => array(P_DB_FIELD => 'fleet_end_stay'), |
69
|
|
|
'timeReturn' => array(P_DB_FIELD => 'fleet_end_time'), |
70
|
|
|
|
71
|
|
|
'units' => array(), |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
public function __construct(\Common\GlobalContainer $gc) { |
75
|
|
|
parent::__construct($gc); |
76
|
|
|
|
77
|
|
|
$this->assignAccessor('vectorDeparture', P_CONTAINER_IMPORT, array($this, 'importVector')); |
78
|
|
|
$this->assignAccessor('vectorDeparture', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
79
|
|
|
$this->assignAccessor('vectorArrive', P_CONTAINER_IMPORT, array($this, 'importVector')); |
80
|
|
|
$this->assignAccessor('vectorArrive', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function importVector(V2FleetContainer $that, array &$row, $propertyName, $fieldName) { |
|
|
|
|
84
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
85
|
|
|
$that->$propertyName = new Vector( |
86
|
|
|
$row[$prefix . 'galaxy'], |
87
|
|
|
$row[$prefix . 'system'], |
88
|
|
|
$row[$prefix . 'planet'], |
89
|
|
|
$row[$prefix . 'type'] |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function exportVector(V2FleetContainer $that, array &$row, $propertyName, $fieldName) { |
|
|
|
|
94
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
95
|
|
|
$row[$prefix . 'galaxy'] = $that->$propertyName->galaxy; |
96
|
|
|
$row[$prefix . 'system'] = $that->$propertyName->system; |
97
|
|
|
$row[$prefix . 'planet'] = $that->$propertyName->planet; |
98
|
|
|
$row[$prefix . 'type'] = $that->$propertyName->type; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param int|string $dbId |
103
|
|
|
* |
104
|
|
|
* @return V2FleetContainer|false |
105
|
|
|
*/ |
106
|
|
|
public function loadById($dbId) { |
107
|
|
|
if ($fleet = parent::loadById($dbId)) { |
108
|
|
|
/** |
109
|
|
|
* @var V2FleetContainer $fleet |
110
|
|
|
*/ |
111
|
|
|
// Loading units |
112
|
|
|
$units = new V2UnitList(); |
113
|
|
|
$units->load(LOC_FLEET, $dbId); |
114
|
|
|
$fleet->units = $units; |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $fleet; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.