1 | <?php |
||
20 | class MatchFormCreator extends ModelFormCreator |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 1 | protected function build($builder) |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | * |
||
70 | * @param \Match $match |
||
71 | */ |
||
72 | public function fill($form, $match) |
||
73 | { |
||
74 | $form->get('first_team')->setData(array( |
||
75 | 'team' => $match->getTeamA(), |
||
76 | 'participants' => $match->getTeamAPlayers(), |
||
77 | 'score' => $match->getTeamAPoints() |
||
78 | )); |
||
79 | $form->get('second_team')->setData(array( |
||
80 | 'team' => $match->getTeamB(), |
||
81 | 'participants' => $match->getTeamBPlayers(), |
||
82 | 'score' => $match->getTeamBPoints() |
||
83 | )); |
||
84 | |||
85 | $form->get('duration')->setData($match->getDuration()); |
||
86 | $form->get('server_address')->setData($match->getServerAddress()); |
||
87 | $form->get('time')->setData($match->getTimestamp()); |
||
88 | $form->get('map')->setData($match->getMap()); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | * |
||
94 | * @param \Match $match |
||
95 | */ |
||
96 | public function update($form, $match) |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | 1 | public function enter($form) |
|
134 | { |
||
135 | 1 | $firstTeam = $form->get('first_team'); |
|
136 | 1 | $secondTeam = $form->get('second_team'); |
|
137 | |||
138 | 1 | $serverInfo = $this->getServerInfo($form->get('server_address')); |
|
139 | |||
140 | 1 | $match = \Match::enterMatch( |
|
141 | 1 | $firstTeam->get('team')->getData()->getId(), |
|
142 | 1 | $secondTeam->get('team')->getData()->getId(), |
|
143 | 1 | $firstTeam->get('score')->getData(), |
|
144 | 1 | $secondTeam->get('score')->getData(), |
|
145 | 1 | $form->get('duration')->getData(), |
|
146 | 1 | $this->me->getId(), |
|
147 | 1 | $form->get('time')->getData(), |
|
148 | 1 | $this->getPlayerList($firstTeam), |
|
149 | 1 | $this->getPlayerList($secondTeam), |
|
150 | 1 | $serverInfo[0], |
|
151 | 1 | $serverInfo[1], |
|
152 | 1 | null, |
|
153 | 1 | $form->get('map')->getData()->getId() |
|
154 | ); |
||
155 | |||
156 | return $match; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Get the player list of a team |
||
161 | * |
||
162 | * @param FormInterface $team A MatchTeamType form |
||
163 | * @return array |
||
164 | */ |
||
165 | 1 | private function getPlayerList(FormInterface $team) |
|
169 | |||
170 | /** |
||
171 | * Get the server address and port of a match |
||
172 | * |
||
173 | * @param FormInterface $server A text form representing the server |
||
174 | * @return array |
||
175 | */ |
||
176 | 1 | private function getServerInfo(FormInterface $server) |
|
185 | |||
186 | /** |
||
187 | * Get a function which converts models to their IDs |
||
188 | * |
||
189 | * Useful to store the match players into the database |
||
190 | */ |
||
191 | private static function getModelToID() |
||
197 | } |
||
198 |