Skip to content

Commit bfe4f21

Browse files
committed
update image profile and image base
1 parent 050d9bb commit bfe4f21

File tree

5 files changed

+111
-64
lines changed

5 files changed

+111
-64
lines changed

src/COC/COCBundle/Controller/PlayerController.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use COC\COCBundle\Form\Type\SeasonType;
1212
use Symfony\Component\HttpFoundation\Request;
1313
use COC\COCBundle\Form\Type\PlayerType;
14+
use COC\COCBundle\Form\Type\BaseType;
1415
use COC\COCBundle\Form\Type\ActivityType;
1516
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1617
use Symfony\Component\Validator\Constraints\DateTime;
@@ -222,12 +223,6 @@ public function editAction (Request $request, $id_clan)
222223

223224
if ($form->handleRequest($request)->isValid())
224225
{
225-
226-
227-
$player->getBase()->setIdclan($clan->getId());
228-
229-
// $player->getPicture()->preUpload();
230-
231226
$clan->setUpdated(new \Datetime());
232227
$em->persist($clan);
233228
$em->flush();
@@ -354,15 +349,41 @@ public function playerAction (Request $request, $id_clan, $id_player)
354349
$playerPreviousSeason = $em->getRepository('COCBundle:PlayerHistory')->findOneBy(array('player' => $player->getId(), 'season' => $previousSeason));
355350
$players = $em->getRepository('COCBundle:Player')->findBy(array('clan' => $clan), array('total'=> 'DESC'));
356351

357-
$form = $this->get('form.factory')->create(new ImageProfileType(), $player);
352+
$form = $this->get('form.factory')->create(new ImageProfileType(), null);
353+
$formBase = $this->get('form.factory')->create(new BaseType(), null);
358354

359355
if ($form->handleRequest($request)->isValid())
360356
{
361-
$player->getPicture()->setIdclan($clan->getId());
362-
$em->persist($player);
363-
$em->flush();
357+
if ($request->request->has('image_profile') )
358+
{
359+
$img = $form->get('picture')->getData();
360+
$img->setIdclan($clan->getId());
361+
362+
$em->persist($img);
363+
$em->flush();
364+
365+
$player->setPicture($img);
366+
$em->persist($player);
367+
$em->flush();
368+
}
369+
}
370+
if ($formBase->handleRequest($request)->isValid())
371+
{
372+
if ($request->request->has('image_base') )
373+
{
374+
$img = $formBase->get('picture')->getData();
375+
$img->setIdclan($clan->getId());
376+
377+
$em->persist($img);
378+
$em->flush();
379+
380+
$player->setBase($img);
381+
$em->persist($player);
382+
$em->flush();
383+
}
364384
}
365385

386+
366387
return $this->render('COCBundle:Player:myPlayer.html.twig', array(
367388
'playerPreviousSeason' => $playerPreviousSeason,
368389
'actualSeason' => $actualSeason,
@@ -372,6 +393,7 @@ public function playerAction (Request $request, $id_clan, $id_player)
372393
'player' => $player,
373394
'positions' => $this->getPositions($player, $clan, $previousSeason),
374395
'form' => $form->createView(),
396+
'formBase' => $formBase->createView(),
375397
'myGold' => $this->perDay($this->getMyGoldPerHour($player)),
376398
'myElixir' => $this->perDay($this->getMyElixirPerHour($player)),
377399
'myDarkElixir' => $this->perDay($this->getMyDarkElixirPerHour($player)),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace COC\COCBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\FormBuilderInterface;
7+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
8+
9+
10+
class BaseType extends AbstractType
11+
{
12+
public function buildForm(FormBuilderInterface $builder, array $options)
13+
{
14+
$builder
15+
->add('picture', new ImageType(), array('label' => 'form.my_picture', 'required' => false))
16+
->add('save', 'submit', array('label' => 'label.update'));
17+
}
18+
19+
20+
public function setDefaultOptions(OptionsResolverInterface $resolver)
21+
{
22+
$resolver->setDefaults(array(
23+
'data_class' => 'COC\COCBundle\Entity\Player',
24+
));
25+
}
26+
27+
28+
public function getName()
29+
{
30+
return 'image_base';
31+
}
32+
}

src/COC/COCBundle/Form/Type/PlayerType.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
1515
->add('hall_town', 'choice', array('label' => 'player.hall_town', 'choices' => array('1'=> '1','2'=> '2','3'=> '3','4'=> '4','5'=> '5','6'=> '6','7'=> '7','8'=> '8','9'=> '9','10'=> '10', )))
1616
->add('level', 'choice', array('label' => 'player.level', 'choices' => array( 0, 1, 2, 3, 4,5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100)))
1717

18-
19-
->add('base', new ImageType(), array('label' => 'form.my_base', 'required' => false))
20-
2118
->add('trophy', 'integer', array('label' => 'player.trophy'))
2219
->add('troopSent', 'integer', array('label' => 'player.troopSent'))
2320
->add('troopReceived', 'integer', array('label' => 'player.troopReceived'))

src/COC/COCBundle/Resources/views/Player/edit.html.twig

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="row">
2222
<div class="col-sm-4">
2323
<div class="form-group">
24-
{{ form_label(form.hall_town, null, {'label_attr': {'class': 'col-sm-3 control-label'}}) }}
24+
{{ form_label(form.hall_town, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
2525
{{ form_errors(form.hall_town) }}
2626
<div class="col-sm-8">
2727
{{ form_widget(form.hall_town, {'attr': {'class': 'form-control hall-town-level'}}) }}
@@ -33,7 +33,7 @@
3333

3434
<div class="col-sm-4">
3535
<div class="form-group">
36-
{{ form_label(form.level, null, {'label_attr': {'class': 'col-sm-3 control-label'}}) }}
36+
{{ form_label(form.level, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
3737
{{ form_errors(form.level) }}
3838
<div class="col-sm-8">
3939
{{ form_widget(form.level, {'attr': {'class': 'form-control'}}) }}
@@ -43,76 +43,56 @@
4343

4444
<div class="col-sm-4" >
4545
<div class="form-group">
46-
{{ form_label(form.base, null, {'label_attr': {'class': 'col-sm-4 control-label '}}) }}
47-
{{ form_errors(form.base) }}
48-
<div class="col-sm-4">
49-
{{ form_widget(form.base, {'attr': {'class': 'filestyle'}}) }}
50-
</div>
51-
<div class="col-sm-4 hidden-sm hidden-xs"> {{ form_widget(form.base, {'attr': {'class': 'filestyle test block'}}) }}
52-
{% if player.base.path is defined %}
53-
<img class="img-responsive" src="{{ asset(player.base.getWebPath(clan.id)) }}" />
54-
{% endif %}
46+
{{ form_label(form.trophy, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
47+
{{ form_errors(form.trophy) }}
48+
<div class="col-sm-8">
49+
{{ form_widget(form.trophy, {'attr': {'class': 'form-control'}}) }}
5550
</div>
5651
</div>
5752
</div>
5853

54+
55+
5956
</div>
6057

61-
</div>
62-
</div>
63-
</div>
6458

65-
<!-- PANEL Activity -->
66-
<div class="panel panel-info">
67-
<div class="panel-heading" role="tab" id="headingFour">
68-
<h4 class="panel-title">
69-
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
70-
{{ 'player.activity'|trans }}
71-
</a>
72-
</h4>
73-
</div>
74-
<div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFour">
75-
<div class="panel-body defences">
76-
<!-- ATTACK -->
7759
<div class="row">
78-
<div class="col-sm-6">
79-
<div class="form-group">
80-
{{ form_label(form.attackWon, null, {'label_attr': {'class': 'control-label'}}) }}
81-
{{ form_errors(form.attackWon) }}
82-
{{ form_widget(form.attackWon, {'attr': {'class': 'form-control'}}) }}
83-
</div>
84-
</div>
8560

86-
<div class="col-sm-6" >
87-
<div class="form-group">
88-
{{ form_label(form.trophy, null, {'label_attr': {'class': 'control-label'}}) }}
89-
{{ form_errors(form.trophy) }}
90-
{{ form_widget(form.trophy, {'attr': {'class': 'form-control'}}) }}
91-
</div>
92-
</div>
93-
</div>
94-
<div class="row">
95-
<div class="col-sm-6" >
61+
<div class="col-sm-4" >
9662
<div class="form-group">
97-
{{ form_label(form.troopReceived, null, {'label_attr': {'class': 'control-label'}}) }}
63+
{{ form_label(form.troopReceived, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
9864
{{ form_errors(form.troopReceived) }}
99-
{{ form_widget(form.troopReceived, {'attr': {'class': 'form-control'}}) }}
65+
<div class="col-sm-8">
66+
{{ form_widget(form.troopReceived, {'attr': {'class': 'form-control'}}) }}
67+
</div>
10068
</div>
10169
</div>
10270

10371

104-
<div class="col-sm-6">
72+
<div class="col-sm-4">
10573
<div class="form-group">
106-
{{ form_label(form.troopSent, null, {'label_attr': {'class': 'control-label'}}) }}
74+
{{ form_label(form.troopSent, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
10775
{{ form_errors(form.troopSent) }}
108-
{{ form_widget(form.troopSent, {'attr': {'class': 'form-control'}}) }}
76+
<div class="col-sm-8">
77+
{{ form_widget(form.troopSent, {'attr': {'class': 'form-control'}}) }}
78+
</div>
10979
</div>
11080
</div>
111-
<!-- ROW END -->
81+
82+
<div class="col-sm-4">
83+
<div class="form-group">
84+
{{ form_label(form.attackWon, null, {'label_attr': {'class': 'col-sm-4 control-label'}}) }}
85+
{{ form_errors(form.attackWon) }}
86+
<div class="col-sm-8">
87+
{{ form_widget(form.attackWon, {'attr': {'class': 'form-control'}}) }}
88+
</div>
89+
</div>
90+
</div>
91+
11292
</div>
93+
11394
</div>
11495
</div>
115-
11696
</div>
11797

11898
<!-- PANEL Defence -->

src/COC/COCBundle/Resources/views/Player/myPlayer.html.twig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,23 @@
173173
<div class="row">
174174
<div class="col-lg-8 col-lg-offset-2">
175175
{% if app.user.player.id is defined and app.user.player.id == player.id %}
176-
<a class="btn btn-success btn-block" href="{{ path('coc_player_edit', {'id': app.user.player.id ,'id_clan': clan.id }) }}"><b> {{ 'menu.edit_base'|trans }}</b></a>
176+
<div class="row">
177+
<div class="col-xs-6">
178+
<div class="previous">
179+
{{ form_start(formBase) }}
180+
{{ form_errors(formBase) }}
181+
{{ form_errors(formBase.picture) }}
182+
{{ form_widget(formBase.picture, {'attr': {'class': 'filestyle'}}) }}
183+
</div>
184+
</div>
185+
<div class="col-xs-6">
186+
<div class="next">
187+
{{ form_widget(formBase.save, {'attr': {'class': 'btn btn-primary'}}) }}
188+
{{ form_rest(formBase) }}
189+
{{ form_end(formBase) }}
190+
</div>
191+
</div>
192+
</div>
177193
{% endif %}
178194
</div>
179195
</div>

0 commit comments

Comments
 (0)