set current user by default

This commit is contained in:
Kayn Ty 2018-04-17 15:41:00 +02:00
parent 0d7b46f5f1
commit 80b334cf85
19 changed files with 500 additions and 352 deletions

View File

@ -30,6 +30,13 @@
Produits
</a>
</li>
<li>
<a class="btn btn-default" href="{{ path('festival_index') }}"
data-toggle="tab">
<i class="fa fa-hat"></i>
Festivals
</a>
</li>
</ul>
</div>
</div>

View File

@ -5,7 +5,7 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
<input class="btn btn-primary btn-block" type="submit" value="Créer" />
{{ form_end(form) }}
<ul>

View File

@ -5,7 +5,7 @@
</h2>
<button ng-repeat="p in c.products track by p.id"
class="btn btn-default"
ng-class="{ 'btn-primary' : activeItemsSold.indexOf(p.id)}"
ng-class="{ 'btn-primary' : activeItemsSold.indexOf(p.id) !==-1}"
ng-click="addProduct( p )">
<span class="product-name">
{{ p.name }}

View File

@ -5,7 +5,7 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create"/>
<input type="submit" class="btn btn-primary btn-block" value="Créer"/>
{{ form_end(form) }}
<ul>

View File

@ -5,7 +5,7 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
<input type="submit" class="btn btn-primary btn-block" value="Créer" />
{{ form_end(form) }}
<ul>

View File

@ -5,12 +5,15 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
<input type="submit" class="btn btn-primary btn-block" value="Créer"/>
{{ form_end(form) }}
<ul>
<li>
<a class="btn btn-primary" href="{{ path('sellrecord_index') }}"> <i class="fa fa-arrow-left"></i>Retour à la liste</a>
<a class="btn btn-primary" href="{{ path('sellrecord_index') }}">
<i class="fa fa-arrow-left"></i>
Retour à la liste
</a>
</li>
</ul>
{% endblock %}

View File

@ -22,3 +22,8 @@ thead {
ul {
padding: 0;
}
label {
min-width: 20em;
display: inline-block;
}

View File

@ -3,32 +3,32 @@
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;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
/**
* Festival controller.
*
* @Route("festival")
*/
class FestivalController extends Controller
{
class FestivalController extends Controller {
/**
* Lists all festival entities.
*
* @Route("/", name="festival_index")
* @Method("GET")
*/
public function indexAction()
{
public function indexAction() {
$em = $this->getDoctrine()->getManager();
$festivals = $em->getRepository('AppBundle:Festival')->findAll();
$festivals = $em->getRepository( 'AppBundle:Festival' )->findByUser($this->getUser() );
return $this->render('festival/index.html.twig', array(
return $this->render( 'festival/index.html.twig',
[
'festivals' => $festivals,
));
] );
}
/**
@ -37,24 +37,26 @@ class FestivalController extends Controller
* @Route("/new", name="festival_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
public function newAction( Request $request ) {
$festival = new Festival();
$form = $this->createForm('AppBundle\Form\FestivalType', $festival);
$form->handleRequest($request);
$festival->setUser( $this->getUser() );
$festival->setDateCreation(new \DateTime());
$form = $this->createForm( 'AppBundle\Form\FestivalType', $festival );
$form->handleRequest( $request );
if ($form->isSubmitted() && $form->isValid()) {
if ( $form->isSubmitted() && $form->isValid() ) {
$em = $this->getDoctrine()->getManager();
$em->persist($festival);
$em->persist( $festival );
$em->flush();
return $this->redirectToRoute('festival_show', array('id' => $festival->getId()));
return $this->redirectToRoute( 'festival_show', [ 'id' => $festival->getId() ] );
}
return $this->render('festival/new.html.twig', array(
return $this->render( 'festival/new.html.twig',
[
'festival' => $festival,
'form' => $form->createView(),
));
] );
}
/**
@ -63,14 +65,14 @@ class FestivalController extends Controller
* @Route("/{id}", name="festival_show")
* @Method("GET")
*/
public function showAction(Festival $festival)
{
$deleteForm = $this->createDeleteForm($festival);
public function showAction( Festival $festival ) {
$deleteForm = $this->createDeleteForm( $festival );
return $this->render('festival/show.html.twig', array(
return $this->render( 'festival/show.html.twig',
[
'festival' => $festival,
'delete_form' => $deleteForm->createView(),
));
] );
}
/**
@ -79,23 +81,23 @@ class FestivalController extends Controller
* @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);
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()) {
if ( $editForm->isSubmitted() && $editForm->isValid() ) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('festival_edit', array('id' => $festival->getId()));
return $this->redirectToRoute( 'festival_edit', [ 'id' => $festival->getId() ] );
}
return $this->render('festival/edit.html.twig', array(
return $this->render( 'festival/edit.html.twig',
[
'festival' => $festival,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
] );
}
/**
@ -104,18 +106,17 @@ class FestivalController extends Controller
* @Route("/{id}", name="festival_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, Festival $festival)
{
$form = $this->createDeleteForm($festival);
$form->handleRequest($request);
public function deleteAction( Request $request, Festival $festival ) {
$form = $this->createDeleteForm( $festival );
$form->handleRequest( $request );
if ($form->isSubmitted() && $form->isValid()) {
if ( $form->isSubmitted() && $form->isValid() ) {
$em = $this->getDoctrine()->getManager();
$em->remove($festival);
$em->remove( $festival );
$em->flush();
}
return $this->redirectToRoute('festival_index');
return $this->redirectToRoute( 'festival_index' );
}
/**
@ -125,12 +126,10 @@ class FestivalController extends Controller
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Festival $festival)
{
private function createDeleteForm( Festival $festival ) {
return $this->createFormBuilder()
->setAction($this->generateUrl('festival_delete', array('id' => $festival->getId())))
->setMethod('DELETE')
->getForm()
;
->setAction( $this->generateUrl( 'festival_delete', [ 'id' => $festival->getId() ] ) )
->setMethod( 'DELETE' )
->getForm();
}
}

View File

@ -39,6 +39,7 @@ class ProductCategoryController extends Controller {
*/
public function newAction( Request $request ) {
$productCategory = new Productcategory();
$productCategory->setUsers($this->getUser());
$form = $this->createForm( 'AppBundle\Form\ProductCategoryType', $productCategory );
$form->handleRequest( $request );

View File

@ -24,7 +24,7 @@ class ProductController extends Controller
{
$em = $this->getDoctrine()->getManager();
$products = $em->getRepository('AppBundle:Product')->findAll();
$products = $em->getRepository('AppBundle:Product')->findByUser($this->getUser() );
return $this->render('product/index.html.twig', array(
'products' => $products,
@ -40,6 +40,7 @@ class ProductController extends Controller
public function newAction(Request $request)
{
$product = new Product();
$product->setUser($this->getUser());
$form = $this->createForm('AppBundle\Form\ProductType', $product);
$form->handleRequest($request);

View File

@ -24,7 +24,7 @@ class SellRecordController extends Controller
{
$em = $this->getDoctrine()->getManager();
$sellRecords = $em->getRepository('AppBundle:SellRecord')->findAll();
$sellRecords = $em->getRepository('AppBundle:SellRecord')->findByUser($this->getUser() );
return $this->render('sellrecord/index.html.twig', array(
'sellRecords' => $sellRecords,
@ -40,6 +40,7 @@ class SellRecordController extends Controller
public function newAction(Request $request)
{
$sellRecord = new Sellrecord();
$sellRecord->setUser($this->getUser());
$form = $this->createForm('AppBundle\Form\SellRecordType', $sellRecord);
$form->handleRequest($request);

View File

@ -41,6 +41,10 @@ class Festival {
*/
private $sellRecords;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals")
*/
private $user;
/**
* Get id
@ -116,11 +120,11 @@ class Festival {
public function getSellRecords() {
return $this->sellRecords;
}
/**
* Constructor
*/
public function __construct()
{
public function __construct() {
$this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection();
}
@ -131,8 +135,7 @@ class Festival {
*
* @return Festival
*/
public function addSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords[] = $sellRecord;
return $this;
@ -143,8 +146,29 @@ class Festival {
*
* @param \AppBundle\Entity\SellRecord $sellRecord
*/
public function removeSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
$this->sellRecords->removeElement($sellRecord);
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord );
}
/**
* Set user.
*
* @param \AppBundle\Entity\User|null $user
*
* @return Festival
*/
public function setUser( \AppBundle\Entity\User $user = null ) {
$this->user = $user;
return $this;
}
/**
* Get user.
*
* @return \AppBundle\Entity\User|null
*/
public function getUser() {
return $this->user;
}
}

View File

@ -41,6 +41,10 @@ class Festival {
*/
private $sellRecords;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals")
*/
private $user;
/**
* Get id
@ -116,11 +120,11 @@ class Festival {
public function getSellRecords() {
return $this->sellRecords;
}
/**
* Constructor
*/
public function __construct()
{
public function __construct() {
$this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection();
}
@ -131,8 +135,7 @@ class Festival {
*
* @return Festival
*/
public function addSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords[] = $sellRecord;
return $this;
@ -143,8 +146,7 @@ class Festival {
*
* @param \AppBundle\Entity\SellRecord $sellRecord
*/
public function removeSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
$this->sellRecords->removeElement($sellRecord);
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord );
}
}

View File

@ -126,8 +126,7 @@ class ProductCategory {
*
* @return ProductCategory
*/
public function addUser(\AppBundle\Entity\User $user)
{
public function addUser( \AppBundle\Entity\User $user ) {
$this->users[] = $user;
return $this;
@ -138,8 +137,7 @@ class ProductCategory {
*
* @param \AppBundle\Entity\User $user
*/
public function removeUser(\AppBundle\Entity\User $user)
{
$this->users->removeElement($user);
public function removeUser( \AppBundle\Entity\User $user ) {
$this->users->removeElement( $user );
}
}

View File

@ -22,14 +22,13 @@ class ProductSold {
*/
private $name;
/**
* @ORM\Column(type="string", length=256)
*/
private $image;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
*/
private $user;
@ -92,4 +91,79 @@ class ProductSold {
public function getProduct() {
return $this->product;
}
/**
* Get id.
*
* @return int
*/
public function getId() {
return $this->id;
}
/**
* Set name.
*
* @param string $name
*
* @return ProductSold
*/
public function setName( $name ) {
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName() {
return $this->name;
}
/**
* Set image.
*
* @param string $image
*
* @return ProductSold
*/
public function setImage( $image ) {
$this->image = $image;
return $this;
}
/**
* Get image.
*
* @return string
*/
public function getImage() {
return $this->image;
}
/**
* Set user.
*
* @param \AppBundle\Entity\User|null $user
*
* @return ProductSold
*/
public function setUser( \AppBundle\Entity\User $user = null ) {
$this->user = $user;
return $this;
}
/**
* Get user.
*
* @return \AppBundle\Entity\User|null
*/
public function getUser() {
return $this->user;
}
}

View File

@ -39,6 +39,11 @@ class User extends BaseUser {
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
*/
private $productsSold;
/**
* variabilised products sold
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
*/
private $festivals;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
@ -172,8 +177,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addProduct(\AppBundle\Entity\Product $product)
{
public function addProduct( \AppBundle\Entity\Product $product ) {
$this->products[] = $product;
return $this;
@ -184,9 +188,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\Product $product
*/
public function removeProduct(\AppBundle\Entity\Product $product)
{
$this->products->removeElement($product);
public function removeProduct( \AppBundle\Entity\Product $product ) {
$this->products->removeElement( $product );
}
/**
@ -194,9 +197,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\ProductSold $productsSold
*/
public function removeProductsSold(\AppBundle\Entity\ProductSold $productsSold)
{
$this->productsSold->removeElement($productsSold);
public function removeProductsSold( \AppBundle\Entity\ProductSold $productsSold ) {
$this->productsSold->removeElement( $productsSold );
}
/**
@ -206,8 +208,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addCategory(\AppBundle\Entity\ProductCategory $category)
{
public function addCategory( \AppBundle\Entity\ProductCategory $category ) {
$this->categories[] = $category;
return $this;
@ -218,9 +219,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\ProductCategory $category
*/
public function removeCategory(\AppBundle\Entity\ProductCategory $category)
{
$this->categories->removeElement($category);
public function removeCategory( \AppBundle\Entity\ProductCategory $category ) {
$this->categories->removeElement( $category );
}
/**
@ -230,8 +230,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords[] = $sellRecord;
return $this;
@ -242,8 +241,43 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\SellRecord $sellRecord
*/
public function removeSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord );
}
/**
* Add festival.
*
* @param \AppBundle\Entity\Festival $festival
*
* @return User
*/
public function addFestival(\AppBundle\Entity\Festival $festival)
{
$this->sellRecords->removeElement($sellRecord);
$this->festivals[] = $festival;
return $this;
}
/**
* Remove festival.
*
* @param \AppBundle\Entity\Festival $festival
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeFestival(\AppBundle\Entity\Festival $festival)
{
return $this->festivals->removeElement($festival);
}
/**
* Get festivals.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFestivals()
{
return $this->festivals;
}
}

View File

@ -39,6 +39,11 @@ class User extends BaseUser {
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
*/
private $productsSold;
/**
* variabilised products sold
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
*/
private $festivals;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
@ -172,8 +177,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addProduct(\AppBundle\Entity\Product $product)
{
public function addProduct( \AppBundle\Entity\Product $product ) {
$this->products[] = $product;
return $this;
@ -184,9 +188,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\Product $product
*/
public function removeProduct(\AppBundle\Entity\Product $product)
{
$this->products->removeElement($product);
public function removeProduct( \AppBundle\Entity\Product $product ) {
$this->products->removeElement( $product );
}
/**
@ -194,9 +197,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\ProductSold $productsSold
*/
public function removeProductsSold(\AppBundle\Entity\ProductSold $productsSold)
{
$this->productsSold->removeElement($productsSold);
public function removeProductsSold( \AppBundle\Entity\ProductSold $productsSold ) {
$this->productsSold->removeElement( $productsSold );
}
/**
@ -206,8 +208,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addCategory(\AppBundle\Entity\ProductCategory $category)
{
public function addCategory( \AppBundle\Entity\ProductCategory $category ) {
$this->categories[] = $category;
return $this;
@ -218,9 +219,8 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\ProductCategory $category
*/
public function removeCategory(\AppBundle\Entity\ProductCategory $category)
{
$this->categories->removeElement($category);
public function removeCategory( \AppBundle\Entity\ProductCategory $category ) {
$this->categories->removeElement( $category );
}
/**
@ -230,8 +230,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords[] = $sellRecord;
return $this;
@ -242,8 +241,7 @@ class User extends BaseUser {
*
* @param \AppBundle\Entity\SellRecord $sellRecord
*/
public function removeSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
{
$this->sellRecords->removeElement($sellRecord);
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord );
}
}

View File

@ -6,29 +6,28 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FestivalType extends AbstractType
{
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'
));
public function buildForm( FormBuilderInterface $builder, array $options ) {
$builder->add( 'name' )// ->add('dateCreation')
;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
public function configureOptions( OptionsResolver $resolver ) {
$resolver->setDefaults( [
'data_class' => 'AppBundle\Entity\Festival',
] );
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix() {
return 'appbundle_festival';
}

View File

@ -13,7 +13,9 @@ class ProductCategoryType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')->add('users');
$builder->add('name')
// ->add('users')
;
}/**
* {@inheritdoc}
*/