diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 92f9cca8..4ea21e68 100755 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -21,6 +21,7 @@ {% include 'default/header.html.twig' %} {% block body %} {% endblock %} + {% include 'default/footer.html.twig' %} {% block javascripts %} diff --git a/app/Resources/views/default/index.html.twig b/app/Resources/views/default/index.html.twig index f520e5c4..fe139d66 100755 --- a/app/Resources/views/default/index.html.twig +++ b/app/Resources/views/default/index.html.twig @@ -13,5 +13,4 @@ - {% include 'default/footer.html.twig' %} {% endblock %} diff --git a/app/Resources/views/default/login-choices.html.twig b/app/Resources/views/default/login-choices.html.twig index ca4a7642..06c89a44 100755 --- a/app/Resources/views/default/login-choices.html.twig +++ b/app/Resources/views/default/login-choices.html.twig @@ -74,7 +74,6 @@ Historique -
  • -

    - Création de produits en masse -

    - -
    - -
    - Vous pouvez copier et adapter cet exemple: -
    -    catégorie: livre
    -        mon livre 1;5€
    -        mon livre 2;6€
    -        mon livre 2;7€
    -    catégorie: poster
    -        super bannière A2;10€
    -    catégorie: dessin à la demande
    -        dessin;20€
    -
    -
    - - -
    + {% include 'logged/mass-register.html.twig' %}

    diff --git a/app/Resources/views/logged/mass-register.html.twig b/app/Resources/views/logged/mass-register.html.twig new file mode 100644 index 00000000..7ac4116b --- /dev/null +++ b/app/Resources/views/logged/mass-register.html.twig @@ -0,0 +1,32 @@ +
    + +

    + Création de produits en masse +

    + +
    + +
    + Vous pouvez copier et adapter cet exemple: +
    +    catégorie: livre
    +        mon livre 1;5€
    +        mon livre 2;6€
    +        mon livre 2;7€
    +    catégorie: poster
    +        super bannière A2;10€
    +    catégorie: dessin à la demande
    +        dessin;20€
    +
    +
    + + + +
    +
    diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index 556a1e6c..84727e9b 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -3,6 +3,8 @@ namespace AppBundle\Controller; use AppBundle\Entity\Festival; +use AppBundle\Entity\Product; +use AppBundle\Entity\ProductCategory; use AppBundle\Entity\ProductSold; use AppBundle\Entity\SellRecord; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -371,7 +373,6 @@ class DefaultController extends Controller { $currentUser = $this->getUser(); $m = $this->getDoctrine()->getManager(); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); - $mySellings = $sellingRepo->findByUser( $currentUser->getId() ); return $this->render( 'logged/import.html.twig', [ @@ -383,22 +384,85 @@ class DefaultController extends Controller { * @Route("/mass-create", name="mass_create") */ public function massCreateAction( Request $request ) { - $currentUser = $this->getUser(); - $m = $this->getDoctrine()->getManager(); - $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); - $myCategories = $sellingRepo->findByUser( $currentUser->getId() ); + $currentUser = $this->getUser(); + $m = $this->getDoctrine()->getManager(); + $myCategories = $currentUser->getCategories(); + $myCategoriesByName = []; + $myProductsByName = []; + $currentCategory = new ProductCategory(); + $currentCategory + ->addUser( $currentUser ) + ->setName( 'default category' ); + + foreach ( $myCategories as $my_category ) { + $myCategoriesByName [$my_category->getName()] = $my_category; + foreach ( $my_category->getProducts() as $product ) { + $myProductsByName[ $product->getName() ] = $product; + } + $currentCategory = $my_category; + } + $massLines = $request->request->get( 'produits' ); if ( $request->getMethod() == 'POST' ) { + var_dump( '
    ' . nl2br( $massLines . '
    ' ) ); + $lines = preg_split( '/$\R?^/m', trim( $massLines ) ); + var_dump( count( $lines ) ); + foreach ( $lines as $line ) { - var_dump( nl2br($request->request->get( 'produits' )) ); + if ( strpos( $line,':' ) ) { + // manage catgegories + $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 ] ) ) { + $newCateg = new ProductCategory(); + $newCateg + ->addUser( $currentUser ) + ->setName( $value ); + $currentUser->addCategory( $newCateg ); + $m->persist( $newCateg ); + $currentCategory = $newCateg; // associate further categories with the newly created one + }else{ + echo " la catégorie existe déjà"; + } + } + } else { + // manage product + echo "
    $line"; + $boom = explode( ';', $line ); + $productName = $boom[ 0 ]; + $price = intval( str_replace( '€', '', $boom[ 0 ] ) ); + var_dump( $productName ); + // or create new product + if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) { + $newProduct = new Product(); + $newProduct->setCategory( $currentCategory ) + ->setName( $productName ) + ->setUser( $currentUser ) + ->setPrice( $price ) // removing euro symbol + ; + $currentUser->addProduct( $newProduct ); + $m->persist( $newProduct ); + }// look for existing products + else { + $myProductsByName[ $productName ]->setPrice( $price ); + } + } + + $m->persist( $currentUser ); + } // check with existing categories and products, sort them by name. // save all + $m->flush(); + } else { + var_dump( "not post" ); } return $this->render( 'logged/import.html.twig', - [ - 'base_dir' => '', - ] ); + [] ); } } diff --git a/src/AppBundle/Entity/Product.php b/src/AppBundle/Entity/Product.php index 82baf74b..720f144d 100644 --- a/src/AppBundle/Entity/Product.php +++ b/src/AppBundle/Entity/Product.php @@ -40,107 +40,101 @@ class Product { use Sellable; use Commentable; - /** - * @return mixed - */ - public function getImage() { - return $this->image; - } /** - * @param mixed $image - */ - public function setImage( $image ) { - $this->image = $image; - } - - /** - * @return mixed - */ - public function getUser() { - return $this->user; - } - - /** - * @param mixed $user - */ - public function setUser( $user ) { - $this->user = $user; - } - - /** - * @return mixed + * Get id. + * + * @return int */ public function getId() { return $this->id; } /** - * @param mixed $id + * Set name. + * + * @param string $name + * + * @return Product */ - public function setId( $id ) { - $this->id = $id; + public function setName( $name ) { + $this->name = $name; + + return $this; } /** - * @return mixed + * Get name. + * + * @return string */ public function getName() { return $this->name; } /** - * @param mixed $name + * Set image. + * + * @param string|null $image + * + * @return Product */ - public function setName( $name ) { - $this->name = $name; + public function setImage( $image = null ) { + $this->image = $image; + + return $this; } /** - * @return mixed + * Get image. + * + * @return string|null */ - public function getPrice() { - return $this->price; + public function getImage() { + return $this->image; } /** - * @param mixed $price + * Set category. + * + * @param \AppBundle\Entity\ProductCategory|null $category + * + * @return Product */ - public function setPrice( $price ) { - $this->price = $price; + public function setCategory( \AppBundle\Entity\ProductCategory $category = null ) { + $this->category = $category; + + return $this; } /** - * @return mixed + * Get category. + * + * @return \AppBundle\Entity\ProductCategory|null */ public function getCategory() { return $this->category; } /** - * @param ProductCategory $category - */ - public function setCategory( ProductCategory $category ) { - $this->category = $category; - } - - /** - * Constructor - */ - public function __construct() { - $this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Add sellRecord + * Set user. * - * @param \AppBundle\Entity\SellRecord $sellRecord + * @param \AppBundle\Entity\User|null $user * * @return Product */ - public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) { - $this->sellRecords[] = $sellRecord; + 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; + } } diff --git a/src/AppBundle/Entity/Product.php~ b/src/AppBundle/Entity/Product.php~ index 82baf74b..38d86b62 100755 --- a/src/AppBundle/Entity/Product.php~ +++ b/src/AppBundle/Entity/Product.php~ @@ -40,107 +40,4 @@ class Product { use Sellable; use Commentable; - /** - * @return mixed - */ - public function getImage() { - return $this->image; - } - - /** - * @param mixed $image - */ - public function setImage( $image ) { - $this->image = $image; - } - - /** - * @return mixed - */ - public function getUser() { - return $this->user; - } - - /** - * @param mixed $user - */ - public function setUser( $user ) { - $this->user = $user; - } - - /** - * @return mixed - */ - public function getId() { - return $this->id; - } - - /** - * @param mixed $id - */ - public function setId( $id ) { - $this->id = $id; - } - - /** - * @return mixed - */ - public function getName() { - return $this->name; - } - - /** - * @param mixed $name - */ - public function setName( $name ) { - $this->name = $name; - } - - /** - * @return mixed - */ - public function getPrice() { - return $this->price; - } - - /** - * @param mixed $price - */ - public function setPrice( $price ) { - $this->price = $price; - } - - /** - * @return mixed - */ - public function getCategory() { - return $this->category; - } - - /** - * @param ProductCategory $category - */ - public function setCategory( ProductCategory $category ) { - $this->category = $category; - } - - /** - * Constructor - */ - public function __construct() { - $this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Add sellRecord - * - * @param \AppBundle\Entity\SellRecord $sellRecord - * - * @return Product - */ - public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) { - $this->sellRecords[] = $sellRecord; - - return $this; - } } diff --git a/src/AppBundle/Entity/SellRecord.php~ b/src/AppBundle/Entity/SellRecord.php~ index 97174107..6ebfa0d6 100755 --- a/src/AppBundle/Entity/SellRecord.php~ +++ b/src/AppBundle/Entity/SellRecord.php~ @@ -220,4 +220,28 @@ class SellRecord { public function getUser() { return $this->user; } + + /** + * Set gender. + * + * @param string|null $gender + * + * @return SellRecord + */ + public function setGender($gender = null) + { + $this->gender = $gender; + + return $this; + } + + /** + * Get gender. + * + * @return string|null + */ + public function getGender() + { + return $this->gender; + } }