From 975adbb340fd53f6edc4af8648cb0a80726c9b61 Mon Sep 17 00:00:00 2001 From: Kayn Ty Date: Thu, 24 May 2018 15:01:18 +0200 Subject: [PATCH] list crud translated --- app/Resources/views/festival/index.html.twig | 18 +++------- app/Resources/views/product/index.html.twig | 24 ++++++------- .../views/productcategory/index.html.twig | 34 ++++++++----------- .../Controller/DefaultController.php | 10 +++--- .../Controller/ProductController.php | 16 +++++---- src/AppBundle/Form/ProductType.php | 10 +++--- 6 files changed, 52 insertions(+), 60 deletions(-) diff --git a/app/Resources/views/festival/index.html.twig b/app/Resources/views/festival/index.html.twig index 3ecb5828..cc981f36 100755 --- a/app/Resources/views/festival/index.html.twig +++ b/app/Resources/views/festival/index.html.twig @@ -76,21 +76,13 @@ {% else %}
- pas d'owner. + pas d'owner.
{% endif %} - + + + Modifier + {% endfor %} diff --git a/app/Resources/views/product/index.html.twig b/app/Resources/views/product/index.html.twig index ea728dea..aa5e1f46 100755 --- a/app/Resources/views/product/index.html.twig +++ b/app/Resources/views/product/index.html.twig @@ -1,7 +1,14 @@ {% extends 'base.html.twig' %} {% block body %} -

Products list

+
+
+

Produits

+ +
+ @@ -30,16 +37,9 @@ {% endfor %} @@ -48,7 +48,7 @@ {% endblock %} diff --git a/app/Resources/views/productcategory/index.html.twig b/app/Resources/views/productcategory/index.html.twig index aa604c17..59a9e182 100755 --- a/app/Resources/views/productcategory/index.html.twig +++ b/app/Resources/views/productcategory/index.html.twig @@ -1,7 +1,14 @@ {% extends 'base.html.twig' %} {% block body %} -

Productcategories list

+
+
+

Catégorie de produit

+ +
+
{{ product.stockCount }} {{ product.comment }} - + + +
@@ -22,29 +29,16 @@ {% endfor %}
{{ productCategory.name }} {{ productCategory.products|length }} - + + + edit +
- + Nouvelle catégorie {% endblock %} diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index e99e1de5..5d356379 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -424,6 +424,7 @@ class DefaultController extends Controller } /** + * import lots of products at once * @Route("/mass-create", name="mass_create") */ public function massCreateAction(Request $request) @@ -456,7 +457,6 @@ class DefaultController extends Controller $boom = explode(':', trim($line)); $firstPart = $boom[0]; $value = $boom[1]; - echo "gérer une catégorie nommée: $value"; if ($firstPart === 'catégorie' && $value) { // look for category by name if (!isset($myCategoriesByName[$value])) { @@ -468,25 +468,25 @@ class DefaultController extends Controller $m->persist($newCateg); $currentCategory = $newCateg; // associate further categories with the newly created one } else { - echo " la catégorie existe déjà"; +// echo " la catégorie existe déjà"; } } } else { // manage product - echo "
$line"; $boom = explode(';', $line); $productName = $boom[0]; $price = 0; if ($boom[1]) { - $price = intval(str_replace('€', '', $boom[1])); + $price = intval(str_replace('€', '', $boom[1]));// removing euro symbol } // or create new product if ($productName && !isset($myProductsByName[$productName])) { $newProduct = new Product(); $newProduct->setCategory($currentCategory) ->setName($productName) + ->setStockCount(500) ->setUser($currentUser) - ->setPrice($price) // removing euro symbol + ->setPrice($price) ; $currentUser->addProduct($newProduct); $m->persist($newProduct); diff --git a/src/AppBundle/Controller/ProductController.php b/src/AppBundle/Controller/ProductController.php index ae6163a2..cb062af9 100755 --- a/src/AppBundle/Controller/ProductController.php +++ b/src/AppBundle/Controller/ProductController.php @@ -37,13 +37,17 @@ class ProductController extends Controller { * @Method({"GET", "POST"}) */ public function newAction( Request $request ) { + $user = $this->getUser(); $product = new Product(); - $product->setUser( $this->getUser() ); + $product->setUser( $user ); $product->setPrice( 1 ); - $product->setStockCount( 10 ); + $product->setStockCount( 500 ); $form = $this->createForm( 'AppBundle\Form\ProductType', $product ); $form->handleRequest( $request ); - + $user = $this->getUser(); + if ( $user && $user->getCategories() ) { + $product->setCategory( $user->getCategories()[ 0 ] ); + } if ( $form->isSubmitted() && $form->isValid() ) { $em = $this->getDoctrine()->getManager(); $em->persist( $product ); @@ -66,9 +70,9 @@ class ProductController extends Controller { * @Method("GET") */ public function showAction( Product $product ) { - if ( $product->getUser()->getId() !== $this->getUser()->getId() ) { - $this->denyAccessUnlessGranted( 'ROLE_ADMIN' ); - } + if ( $product->getUser()->getId() !== $this->getUser()->getId() ) { + $this->denyAccessUnlessGranted( 'ROLE_ADMIN' ); + } $deleteForm = $this->createDeleteForm( $product ); if ( $product->getUser()->getId() !== $this->getUser()->getId() ) { diff --git a/src/AppBundle/Form/ProductType.php b/src/AppBundle/Form/ProductType.php index 89c391f9..5b5ddc7a 100755 --- a/src/AppBundle/Form/ProductType.php +++ b/src/AppBundle/Form/ProductType.php @@ -23,19 +23,20 @@ class ProductType extends AbstractType { * {@inheritdoc} */ public function buildForm( FormBuilderInterface $builder, array $options ) { - $builder->add( 'name' ) + $builder->add( 'name' , null, ['label'=>'Nom']) ->add( 'image', null, [ 'label' => 'URL pour image' ] ) - ->add( 'stockCount' ) - ->add( 'price') - ->add( 'comment' ); + ->add( 'stockCount', null, ['label'=>'En stock'] ) + ->add( 'price', null, ['label'=>'Prix en euros']) + ->add( 'comment', null, ['label'=>'Commentaire']); $user = $this->security->getUser(); if ( ! $user ) { throw new \LogicException( 'The SellRecordType cannot be used without an authenticated user!' ); } + $builder->addEventListener( FormEvents::PRE_SET_DATA, function ( FormEvent $event ) { $form = $event->getForm(); @@ -48,6 +49,7 @@ class ProductType extends AbstractType { 'class' => 'AppBundle:ProductCategory', 'placeholder' => '--- catégories ---', 'choices' => $categories, + 'label' => 'Catégorie', ] ); } );