1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: oomelche |
5
|
|
|
* Date: 29.07.2016 |
6
|
|
|
* Time: 13:18 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace V2Unit; |
10
|
|
|
|
11
|
|
|
use Common\ContainerPlus; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class V2UnitModel |
15
|
|
|
* |
16
|
|
|
* Second iteration of revised Unit |
17
|
|
|
* |
18
|
|
|
* @property int $playerOwnerId |
19
|
|
|
* @property int $locationType |
20
|
|
|
* @property int $locationId |
21
|
|
|
* @property int $type |
22
|
|
|
* @property int $snId |
23
|
|
|
* @property int $dbLevel - level of unit for DB: $count for stackable units, $level - fon unstackable units |
24
|
|
|
* @property int $level // TODO |
25
|
|
|
* property int $count // TODO |
26
|
|
|
* property \DateTime $timeStart // TODO |
27
|
|
|
* property \DateTime $timeFinish // TODO |
28
|
|
|
* |
29
|
|
|
* @package V2Unit |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
class V2UnitModel extends \Entity { |
33
|
|
|
|
34
|
|
|
protected static $tableName = 'unit'; |
35
|
|
|
protected static $idField = 'unit_id'; |
36
|
|
|
|
37
|
|
|
protected static $_properties = array( |
38
|
|
|
'dbId' => array( |
39
|
|
|
P_DB_FIELD => 'unit_id', |
40
|
|
|
), |
41
|
|
|
'playerOwnerId' => array( |
42
|
|
|
P_DB_FIELD => 'unit_player_id', |
43
|
|
|
), |
44
|
|
|
'locationType' => array( |
45
|
|
|
P_DB_FIELD => 'unit_location_type', |
46
|
|
|
), |
47
|
|
|
'locationId' => array( |
48
|
|
|
P_DB_FIELD => 'unit_location_id', |
49
|
|
|
), |
50
|
|
|
'type' => array( |
51
|
|
|
P_DB_FIELD => 'unit_type', |
52
|
|
|
), |
53
|
|
|
'snId' => array( |
54
|
|
|
P_DB_FIELD => 'unit_snid', |
55
|
|
|
), |
56
|
|
|
// Order is important! |
57
|
|
|
'dbLevel' => array( |
58
|
|
|
// TODO - aggregate function from Level/Count |
59
|
|
|
P_DB_FIELD => 'unit_level', |
60
|
|
|
), |
61
|
|
|
|
62
|
|
|
// TODO - split dbLevel to level and count |
63
|
|
|
'level' => array(), |
64
|
|
|
'count' => array(), |
65
|
|
|
|
66
|
|
|
// TODO - move to child class |
67
|
|
|
'timeStart' => array( |
68
|
|
|
P_DB_FIELD => 'unit_time_start', |
69
|
|
|
), |
70
|
|
|
'timeFinish' => array( |
71
|
|
|
P_DB_FIELD => 'unit_time_finish', |
72
|
|
|
), |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
public function __construct(\Common\GlobalContainer $gc) { |
76
|
|
|
parent::__construct($gc); |
77
|
|
|
|
78
|
|
|
$this->_container = new static::$_containerName(); |
79
|
|
|
$this->_container->setProperties(static::$_properties); |
80
|
|
|
|
81
|
|
|
$that = $this; |
82
|
|
|
$this->_container->assignAccessor( |
83
|
|
|
'type', |
84
|
|
|
P_CONTAINER_SETTER, |
85
|
|
|
function ($value) use ($that) { |
86
|
|
|
$that->type = $value; |
87
|
|
|
} |
88
|
|
|
); |
89
|
|
|
$this->_container->assignAccessor( |
90
|
|
|
'level', |
91
|
|
|
P_CONTAINER_IMPORTER, |
92
|
|
|
function (&$row) use ($that) { |
93
|
|
|
//pdump('level setter is launched'); |
|
|
|
|
94
|
|
|
//pdump($row, '$row'); |
95
|
|
|
//var_dump($that); |
96
|
|
|
$that->level = $row['unit_level']; |
97
|
|
|
//var_dump($that); |
|
|
|
|
98
|
|
|
//pdie(); |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
|
102
|
|
|
//pdump($row['unit_level'], '$row[\'unit_level\']'); |
|
|
|
|
103
|
|
|
//pdump($that->level, '$that->level'); |
104
|
|
|
//pdump($that->_container, '$that->_container'); |
105
|
|
|
// pdump($that); |
106
|
|
|
//pdie('importer launched'); |
107
|
|
|
} |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$this->_container->assignAccessor( |
111
|
|
|
'dbLevel', |
112
|
|
|
P_CONTAINER_EXPORTER, |
113
|
|
|
function (&$row) use ($that) { |
114
|
|
|
//pdump('level setter is launched'); |
|
|
|
|
115
|
|
|
//pdump($row, '$row'); |
116
|
|
|
//var_dump($that); |
117
|
|
|
$row['unit_level'] = $that->dbLevel; |
118
|
|
|
//var_dump($that); |
|
|
|
|
119
|
|
|
//pdie(); |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
|
//pdump($row['unit_level'], '$row[\'unit_level\']'); |
|
|
|
|
124
|
|
|
//pdump($that->level, '$that->level'); |
125
|
|
|
//pdump($that->_container, '$that->_container'); |
126
|
|
|
// pdump($that); |
127
|
|
|
//pdie('importer launched'); |
128
|
|
|
} |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
// $this->_container->importRow(array('unit_level' => 5, 'unit_type' => 10,)); |
|
|
|
|
133
|
|
|
// |
134
|
|
|
// pdump($this->_container->level); |
135
|
|
|
// pdump($this->level); |
136
|
|
|
//// pdump($this->type); |
137
|
|
|
// |
138
|
|
|
// pdie(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param static $that |
143
|
|
|
* @param array $row |
144
|
|
|
*/ |
145
|
|
|
protected function importLevel($that, &$row) { |
146
|
|
|
$that->level = $row['unit_level']; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param static $that |
151
|
|
|
* @param array $row |
152
|
|
|
*/ |
153
|
|
|
protected function exportLevel($that, &$row) { |
|
|
|
|
154
|
|
|
// $row['unit_level'] = $that->level; |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param ContainerPlus $cUnit |
159
|
|
|
*/ |
160
|
|
|
public function test($unitId, $cUnit = null) { |
|
|
|
|
161
|
|
|
$this->dbId = $unitId; |
162
|
|
|
static::$rowOperator->getById($this); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
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.