cruds for products, categories, festivals

This commit is contained in:
Kayn Ty 2018-04-05 17:09:06 +02:00
parent 0b49351588
commit d5ef71f734
13 changed files with 755 additions and 75 deletions

View File

@ -1,79 +1,45 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}Hello !{% endblock %}
{% block body %} {% block body %}
<div class="container"> <h1>Products list</h1>
<div class="example-wrapper">
<h1>Caisse de convention Qzine</h1>
<fieldset>
<div class="row"> <table>
<div class="col-xs-6"> <thead>
<h2> <tr>
Catégories <th>Id</th>
</h2> <th>Name</th>
{% for c in categories %} <th>Image</th>
<h3>{{ c.name }}</h3> <th>Price</th>
<div class="row-fluid"> <th>Comment</th>
{% for p in c.products %} <th>Actions</th>
<div class="col-xs-6"> </tr>
</thead>
<button class="btn btn-default btn-block"> <tbody>
{{ p.name }} {% for product in products %}
<input type="number" value="{{ p.price }}"> <tr>
€ x <td><a href="{{ path('product_show', { 'id': product.id }) }}">{{ product.id }}</a></td>
<td>{{ product.name }}</td>
<span class="badge badge-info">0</span> <td>{{ product.image }}</td>
</button> <td>{{ product.price }}</td>
<td>{{ product.comment }}</td>
</div> <td>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="col-xs-6">
<fieldset class="sell">
<div class="event-name">
<strong>évènement:</strong>
<input type="text" value="le salon du livre">
</div>
<div class="well">
<h2>Commentaire</h2>
<input type="text" value="le comm">
</div>
<h2>Prix</h2>
<strong>
<span class="price"></span>
€</strong>
<button class="btn btn-primary">
Enregistrer
</button>
</fieldset>
<fieldset>
<h2>Historique</h2>
<ul> <ul>
<li class="one-sell"> <li>
12€ - commentaire <a href="{{ path('product_show', { 'id': product.id }) }}">show</a>
<button> </li>
<i class="fa fa-pencil"></i> <li>
</button> <a href="{{ path('product_edit', { 'id': product.id }) }}">edit</a>
</li> </li>
</ul> </ul>
</fieldset> </td>
</div> </tr>
</div> {% endfor %}
</tbody>
</table>
<ul>
</fieldset> <li>
<footer> <a href="{{ path('product_new') }}">Create a new product</a>
made by Tykayn - </li>
<a href="www.cipherbliss.com"> </ul>
Cipher Bliss
</a>
</footer>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -1,3 +1,15 @@
app_festival:
resource: "@AppBundle/Controller/FestivalController.php"
type: annotation
app_product_category:
resource: "@AppBundle/Controller/ProductCategoryController.php"
type: annotation
app_product:
resource: "@AppBundle/Controller/ProductController.php"
type: annotation
app_sell_record: app_sell_record:
resource: "@AppBundle/Controller/SellRecordController.php" resource: "@AppBundle/Controller/SellRecordController.php"
type: annotation type: annotation

View File

@ -118,11 +118,12 @@ class DefaultController extends Controller {
* @return JsonResponse * @return JsonResponse
*/ */
public function addSellingAction( Request $request ) { public function addSellingAction( Request $request ) {
var_dump( $request->request ); // var_dump( $request->request );
// die();
// link selling record with user, festival // link selling record with user, festival
// setup dates // setup dates
// persist all // persist all
// fetch back history of selling // fetch back history of selling
return new JsonResponse( [ "message" => "ok" ] ); return new JsonResponse( [ "message" => "ok", "dump" => $request->request ] );
} }
} }

View File

@ -0,0 +1,136 @@
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Festival;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
/**
* Festival controller.
*
* @Route("festival")
*/
class FestivalController extends Controller
{
/**
* Lists all festival entities.
*
* @Route("/", name="festival_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$festivals = $em->getRepository('AppBundle:Festival')->findAll();
return $this->render('festival/index.html.twig', array(
'festivals' => $festivals,
));
}
/**
* Creates a new festival entity.
*
* @Route("/new", name="festival_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$festival = new Festival();
$form = $this->createForm('AppBundle\Form\FestivalType', $festival);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($festival);
$em->flush();
return $this->redirectToRoute('festival_show', array('id' => $festival->getId()));
}
return $this->render('festival/new.html.twig', array(
'festival' => $festival,
'form' => $form->createView(),
));
}
/**
* Finds and displays a festival entity.
*
* @Route("/{id}", name="festival_show")
* @Method("GET")
*/
public function showAction(Festival $festival)
{
$deleteForm = $this->createDeleteForm($festival);
return $this->render('festival/show.html.twig', array(
'festival' => $festival,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing festival entity.
*
* @Route("/{id}/edit", name="festival_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Festival $festival)
{
$deleteForm = $this->createDeleteForm($festival);
$editForm = $this->createForm('AppBundle\Form\FestivalType', $festival);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('festival_edit', array('id' => $festival->getId()));
}
return $this->render('festival/edit.html.twig', array(
'festival' => $festival,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a festival entity.
*
* @Route("/{id}", name="festival_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, Festival $festival)
{
$form = $this->createDeleteForm($festival);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($festival);
$em->flush();
}
return $this->redirectToRoute('festival_index');
}
/**
* Creates a form to delete a festival entity.
*
* @param Festival $festival The festival entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Festival $festival)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('festival_delete', array('id' => $festival->getId())))
->setMethod('DELETE')
->getForm()
;
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\ProductCategory;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
/**
* Productcategory controller.
*
* @Route("productcategory")
*/
class ProductCategoryController extends Controller
{
/**
* Lists all productCategory entities.
*
* @Route("/", name="productcategory_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$productCategories = $em->getRepository('AppBundle:ProductCategory')->findAll();
return $this->render('productcategory/index.html.twig', array(
'productCategories' => $productCategories,
));
}
/**
* Creates a new productCategory entity.
*
* @Route("/new", name="productcategory_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$productCategory = new Productcategory();
$form = $this->createForm('AppBundle\Form\ProductCategoryType', $productCategory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($productCategory);
$em->flush();
return $this->redirectToRoute('productcategory_show', array('id' => $productCategory->getId()));
}
return $this->render('productcategory/new.html.twig', array(
'productCategory' => $productCategory,
'form' => $form->createView(),
));
}
/**
* Finds and displays a productCategory entity.
*
* @Route("/{id}", name="productcategory_show")
* @Method("GET")
*/
public function showAction(ProductCategory $productCategory)
{
$deleteForm = $this->createDeleteForm($productCategory);
return $this->render('productcategory/show.html.twig', array(
'productCategory' => $productCategory,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing productCategory entity.
*
* @Route("/{id}/edit", name="productcategory_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, ProductCategory $productCategory)
{
$deleteForm = $this->createDeleteForm($productCategory);
$editForm = $this->createForm('AppBundle\Form\ProductCategoryType', $productCategory);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('productcategory_edit', array('id' => $productCategory->getId()));
}
return $this->render('productcategory/edit.html.twig', array(
'productCategory' => $productCategory,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a productCategory entity.
*
* @Route("/{id}", name="productcategory_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, ProductCategory $productCategory)
{
$form = $this->createDeleteForm($productCategory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($productCategory);
$em->flush();
}
return $this->redirectToRoute('productcategory_index');
}
/**
* Creates a form to delete a productCategory entity.
*
* @param ProductCategory $productCategory The productCategory entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(ProductCategory $productCategory)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('productcategory_delete', array('id' => $productCategory->getId())))
->setMethod('DELETE')
->getForm()
;
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Product;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
/**
* Product controller.
*
* @Route("product")
*/
class ProductController extends Controller
{
/**
* Lists all product entities.
*
* @Route("/", name="product_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$products = $em->getRepository('AppBundle:Product')->findAll();
return $this->render('product/index.html.twig', array(
'products' => $products,
));
}
/**
* Creates a new product entity.
*
* @Route("/new", name="product_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$product = new Product();
$form = $this->createForm('AppBundle\Form\ProductType', $product);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
return $this->redirectToRoute('product_show', array('id' => $product->getId()));
}
return $this->render('product/new.html.twig', array(
'product' => $product,
'form' => $form->createView(),
));
}
/**
* Finds and displays a product entity.
*
* @Route("/{id}", name="product_show")
* @Method("GET")
*/
public function showAction(Product $product)
{
$deleteForm = $this->createDeleteForm($product);
return $this->render('product/show.html.twig', array(
'product' => $product,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing product entity.
*
* @Route("/{id}/edit", name="product_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Product $product)
{
$deleteForm = $this->createDeleteForm($product);
$editForm = $this->createForm('AppBundle\Form\ProductType', $product);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('product_edit', array('id' => $product->getId()));
}
return $this->render('product/edit.html.twig', array(
'product' => $product,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a product entity.
*
* @Route("/{id}", name="product_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, Product $product)
{
$form = $this->createDeleteForm($product);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($product);
$em->flush();
}
return $this->redirectToRoute('product_index');
}
/**
* Creates a form to delete a product entity.
*
* @param Product $product The product entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Product $product)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('product_delete', array('id' => $product->getId())))
->setMethod('DELETE')
->getForm()
;
}
}

View File

@ -22,6 +22,12 @@ class Product {
*/ */
private $name; private $name;
/**
* @ORM\Column(type="string", length=256)
*/
private $image;
/** /**
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products") * @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
*/ */
@ -34,6 +40,20 @@ class Product {
use Sellable; use Sellable;
use Commentable; use Commentable;
/**
* @return mixed
*/
public function getImage() {
return $this->image;
}
/**
* @param mixed $image
*/
public function setImage( $image ) {
$this->image = $image;
}
/** /**
* @return mixed * @return mixed
*/ */

View File

@ -0,0 +1,36 @@
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FestivalType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')->add('dateCreation');
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Festival'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_festival';
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ProductCategoryType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')->add('users');
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\ProductCategory'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_productcategory';
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ProductType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')->add('image')->add('price')->add('comment')->add('category')->add('user');
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Product'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_product';
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FestivalControllerTest extends WebTestCase
{
/*
public function testCompleteScenario()
{
// Create a new client to browse the application
$client = static::createClient();
// Create a new entry in the database
$crawler = $client->request('GET', '/festival/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /festival/");
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Create')->form(array(
'appbundle_festival[field_name]' => 'Test',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check data in the show view
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
// Edit the entity
$crawler = $client->click($crawler->selectLink('Edit')->link());
$form = $crawler->selectButton('Update')->form(array(
'appbundle_festival[field_name]' => 'Foo',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check the element contains an attribute with value equals "Foo"
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
// Delete the entity
$client->submit($crawler->selectButton('Delete')->form());
$crawler = $client->followRedirect();
// Check the entity has been delete on the list
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ProductCategoryControllerTest extends WebTestCase
{
/*
public function testCompleteScenario()
{
// Create a new client to browse the application
$client = static::createClient();
// Create a new entry in the database
$crawler = $client->request('GET', '/productcategory/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /productcategory/");
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Create')->form(array(
'appbundle_productcategory[field_name]' => 'Test',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check data in the show view
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
// Edit the entity
$crawler = $client->click($crawler->selectLink('Edit')->link());
$form = $crawler->selectButton('Update')->form(array(
'appbundle_productcategory[field_name]' => 'Foo',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check the element contains an attribute with value equals "Foo"
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
// Delete the entity
$client->submit($crawler->selectButton('Delete')->form());
$crawler = $client->followRedirect();
// Check the entity has been delete on the list
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ProductControllerTest extends WebTestCase
{
/*
public function testCompleteScenario()
{
// Create a new client to browse the application
$client = static::createClient();
// Create a new entry in the database
$crawler = $client->request('GET', '/product/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /product/");
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Create')->form(array(
'appbundle_product[field_name]' => 'Test',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check data in the show view
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
// Edit the entity
$crawler = $client->click($crawler->selectLink('Edit')->link());
$form = $crawler->selectButton('Update')->form(array(
'appbundle_product[field_name]' => 'Foo',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check the element contains an attribute with value equals "Foo"
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
// Delete the entity
$client->submit($crawler->selectButton('Delete')->form());
$crawler = $client->followRedirect();
// Check the entity has been delete on the list
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
}
*/
}