list crud translated
This commit is contained in:
parent
b386d886e6
commit
975adbb340
@ -76,21 +76,13 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
|
|
||||||
pas d'owner.
|
pas d'owner.
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul>
|
<a class="btn btn-primary" href="{{ path('festival_edit', { 'id': festival.id }) }}">
|
||||||
<li class="pull-left">
|
<i class="fa fa-pencil"></i>
|
||||||
<a class="btn btn-primary" href="{{ path('festival_show', { 'id': festival.id }) }}">voir
|
Modifier
|
||||||
</a>
|
</a>
|
||||||
</li>
|
|
||||||
<li class="pull-left">
|
|
||||||
<a class="btn btn-primary" href="{{ path('festival_edit', { 'id': festival.id }) }}">
|
|
||||||
<i class="fa fa-pencil"></i>
|
|
||||||
Modifier
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
{% extends 'base.html.twig' %}
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Products list</h1>
|
<div class="row">
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<h1>Produits</h1></div>
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<a class="btn btn-primary" href="{{ path('product_new') }}">Nouveau produit</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<table class="table-responsive table-striped table table-bordered table-light">
|
<table class="table-responsive table-striped table table-bordered table-light">
|
||||||
<thead class="bg-dark">
|
<thead class="bg-dark">
|
||||||
@ -30,16 +37,9 @@
|
|||||||
<td>{{ product.stockCount }}</td>
|
<td>{{ product.stockCount }}</td>
|
||||||
<td>{{ product.comment }}</td>
|
<td>{{ product.comment }}</td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<a class="btn btn-default" href="{{ path('product_edit', { 'id': product.id }) }}">
|
||||||
<li>
|
<i class="fa fa-pencil"></i>
|
||||||
<a class="btn btn-default" href="{{ path('product_show', { 'id': product.id }) }}">voir</a>
|
</a>
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="btn btn-default" href="{{ path('product_edit', { 'id': product.id }) }}">
|
|
||||||
<i class="fa fa-pencil"></i>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a class="btn btn-primary" href="{{ path('product_new') }}">Nouveau product</a>
|
<a class="btn btn-primary" href="{{ path('product_new') }}">Nouveau produit</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
{% extends 'base.html.twig' %}
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Productcategories list</h1>
|
<div class="row">
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<h1>Catégorie de produit</h1></div>
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<a class="btn btn-primary" href="{{ path('productcategory_new') }}">Nouvelle catégorie</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<table class="table-responsive table-striped table table-bordered table-light">
|
<table class="table-responsive table-striped table table-bordered table-light">
|
||||||
<thead>
|
<thead>
|
||||||
@ -22,29 +29,16 @@
|
|||||||
<td>{{ productCategory.name }}</td>
|
<td>{{ productCategory.name }}</td>
|
||||||
<td>{{ productCategory.products|length }}</td>
|
<td>{{ productCategory.products|length }}</td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<a class="btn btn-primary"
|
||||||
<li>
|
href="{{ path('productcategory_edit', { 'id': productCategory.id }) }}">
|
||||||
<a class="btn btn-primary"
|
<i class="fa fa-pencil"></i>
|
||||||
href="{{ path('productcategory_show', { 'id': productCategory.id }) }}">voir
|
edit
|
||||||
</a>
|
</a>
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="btn btn-primary"
|
|
||||||
href="{{ path('productcategory_edit', { 'id': productCategory.id }) }}">
|
|
||||||
<i class="fa fa-pencil"></i>
|
|
||||||
edit
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<ul>
|
<a class="btn btn-primary" href="{{ path('productcategory_new') }}">Nouvelle catégorie</a>
|
||||||
<li>
|
|
||||||
<a class="btn btn-primary" href="{{ path('productcategory_new') }}">Nouveau productCategory</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -424,6 +424,7 @@ class DefaultController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* import lots of products at once
|
||||||
* @Route("/mass-create", name="mass_create")
|
* @Route("/mass-create", name="mass_create")
|
||||||
*/
|
*/
|
||||||
public function massCreateAction(Request $request)
|
public function massCreateAction(Request $request)
|
||||||
@ -456,7 +457,6 @@ class DefaultController extends Controller
|
|||||||
$boom = explode(':', trim($line));
|
$boom = explode(':', trim($line));
|
||||||
$firstPart = $boom[0];
|
$firstPart = $boom[0];
|
||||||
$value = $boom[1];
|
$value = $boom[1];
|
||||||
echo "gérer une catégorie nommée: $value";
|
|
||||||
if ($firstPart === 'catégorie' && $value) {
|
if ($firstPart === 'catégorie' && $value) {
|
||||||
// look for category by name
|
// look for category by name
|
||||||
if (!isset($myCategoriesByName[$value])) {
|
if (!isset($myCategoriesByName[$value])) {
|
||||||
@ -468,25 +468,25 @@ class DefaultController extends Controller
|
|||||||
$m->persist($newCateg);
|
$m->persist($newCateg);
|
||||||
$currentCategory = $newCateg; // associate further categories with the newly created one
|
$currentCategory = $newCateg; // associate further categories with the newly created one
|
||||||
} else {
|
} else {
|
||||||
echo " la catégorie existe déjà";
|
// echo " la catégorie existe déjà";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// manage product
|
// manage product
|
||||||
echo "<br/> $line";
|
|
||||||
$boom = explode(';', $line);
|
$boom = explode(';', $line);
|
||||||
$productName = $boom[0];
|
$productName = $boom[0];
|
||||||
$price = 0;
|
$price = 0;
|
||||||
if ($boom[1]) {
|
if ($boom[1]) {
|
||||||
$price = intval(str_replace('€', '', $boom[1]));
|
$price = intval(str_replace('€', '', $boom[1]));// removing euro symbol
|
||||||
}
|
}
|
||||||
// or create new product
|
// or create new product
|
||||||
if ($productName && !isset($myProductsByName[$productName])) {
|
if ($productName && !isset($myProductsByName[$productName])) {
|
||||||
$newProduct = new Product();
|
$newProduct = new Product();
|
||||||
$newProduct->setCategory($currentCategory)
|
$newProduct->setCategory($currentCategory)
|
||||||
->setName($productName)
|
->setName($productName)
|
||||||
|
->setStockCount(500)
|
||||||
->setUser($currentUser)
|
->setUser($currentUser)
|
||||||
->setPrice($price) // removing euro symbol
|
->setPrice($price)
|
||||||
;
|
;
|
||||||
$currentUser->addProduct($newProduct);
|
$currentUser->addProduct($newProduct);
|
||||||
$m->persist($newProduct);
|
$m->persist($newProduct);
|
||||||
|
@ -37,13 +37,17 @@ class ProductController extends Controller {
|
|||||||
* @Method({"GET", "POST"})
|
* @Method({"GET", "POST"})
|
||||||
*/
|
*/
|
||||||
public function newAction( Request $request ) {
|
public function newAction( Request $request ) {
|
||||||
|
$user = $this->getUser();
|
||||||
$product = new Product();
|
$product = new Product();
|
||||||
$product->setUser( $this->getUser() );
|
$product->setUser( $user );
|
||||||
$product->setPrice( 1 );
|
$product->setPrice( 1 );
|
||||||
$product->setStockCount( 10 );
|
$product->setStockCount( 500 );
|
||||||
$form = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
$form = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
||||||
$form->handleRequest( $request );
|
$form->handleRequest( $request );
|
||||||
|
$user = $this->getUser();
|
||||||
|
if ( $user && $user->getCategories() ) {
|
||||||
|
$product->setCategory( $user->getCategories()[ 0 ] );
|
||||||
|
}
|
||||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$em->persist( $product );
|
$em->persist( $product );
|
||||||
@ -66,9 +70,9 @@ class ProductController extends Controller {
|
|||||||
* @Method("GET")
|
* @Method("GET")
|
||||||
*/
|
*/
|
||||||
public function showAction( Product $product ) {
|
public function showAction( Product $product ) {
|
||||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||||
}
|
}
|
||||||
$deleteForm = $this->createDeleteForm( $product );
|
$deleteForm = $this->createDeleteForm( $product );
|
||||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||||
|
|
||||||
|
@ -23,19 +23,20 @@ class ProductType extends AbstractType {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildForm( FormBuilderInterface $builder, array $options ) {
|
public function buildForm( FormBuilderInterface $builder, array $options ) {
|
||||||
$builder->add( 'name' )
|
$builder->add( 'name' , null, ['label'=>'Nom'])
|
||||||
->add( 'image',
|
->add( 'image',
|
||||||
null,
|
null,
|
||||||
[ 'label' => 'URL pour image' ] )
|
[ 'label' => 'URL pour image' ] )
|
||||||
->add( 'stockCount' )
|
->add( 'stockCount', null, ['label'=>'En stock'] )
|
||||||
->add( 'price')
|
->add( 'price', null, ['label'=>'Prix en euros'])
|
||||||
->add( 'comment' );
|
->add( 'comment', null, ['label'=>'Commentaire']);
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
if ( ! $user ) {
|
if ( ! $user ) {
|
||||||
throw new \LogicException(
|
throw new \LogicException(
|
||||||
'The SellRecordType cannot be used without an authenticated user!'
|
'The SellRecordType cannot be used without an authenticated user!'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->addEventListener( FormEvents::PRE_SET_DATA,
|
$builder->addEventListener( FormEvents::PRE_SET_DATA,
|
||||||
function ( FormEvent $event ) {
|
function ( FormEvent $event ) {
|
||||||
$form = $event->getForm();
|
$form = $event->getForm();
|
||||||
@ -48,6 +49,7 @@ class ProductType extends AbstractType {
|
|||||||
'class' => 'AppBundle:ProductCategory',
|
'class' => 'AppBundle:ProductCategory',
|
||||||
'placeholder' => '--- catégories ---',
|
'placeholder' => '--- catégories ---',
|
||||||
'choices' => $categories,
|
'choices' => $categories,
|
||||||
|
'label' => 'Catégorie',
|
||||||
] );
|
] );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user