+
Produits
-
diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php
index 1d3e44d6..ca6f4e01 100644
--- a/src/AppBundle/Controller/DefaultController.php
+++ b/src/AppBundle/Controller/DefaultController.php
@@ -7,6 +7,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
+use Symfony\Component\Serializer\Encoder\JsonEncoder;
+use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
+use Symfony\Component\Serializer\Serializer;
class DefaultController extends Controller {
@@ -54,10 +57,26 @@ class DefaultController extends Controller {
}
public function getMyProductsAction() {
+ $m = $this->getDoctrine()->getManager();
+ $currentUser = $this->getUser();
+ if ( ! $currentUser ) {
+ return new JsonResponse( [
+ 'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
+ 'recentSells' => [['']],
+ ] );
+ }
+ $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
+ $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
+ $categories = $currentUser->getCategories();
+ if ( ! $categories ) {
+ $defaultCategories = $categRepo->find( [ 1, 2 ] );
+ $currentUser->setCategories( $defaultCategories );
+ }
+ $recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
+
return new JsonResponse( [
- [ 'id' => 1, "name" => 'truc', "category" => 1, "price" => 9 ],
-// [ 'id' => 2, name => 'truc2', category => 1, price => 4 ],
-// [ id => 3, name => 'truc3', category => 2, price => 1 ],
+ 'categories' => $categories,
+ 'recentSells' => $recentSells,
] );
}
diff --git a/src/AppBundle/Entity/Festival.php b/src/AppBundle/Entity/Festival.php
new file mode 100644
index 00000000..c15a7832
--- /dev/null
+++ b/src/AppBundle/Entity/Festival.php
@@ -0,0 +1,120 @@
+id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ *
+ * @return Festival
+ */
+ public function setName( $name ) {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * Set dateCreation
+ *
+ * @param \DateTime $dateCreation
+ *
+ * @return Festival
+ */
+ public function setDateCreation( $dateCreation ) {
+ $this->dateCreation = $dateCreation;
+
+ return $this;
+ }
+
+ /**
+ * Get dateCreation
+ *
+ * @return \DateTime
+ */
+ public function getDateCreation() {
+ return $this->dateCreation;
+ }
+
+ /**
+ * Set sellRecords
+ *
+ * @param \stdClass $sellRecords
+ *
+ * @return Festival
+ */
+ public function setSellRecords( $sellRecords ) {
+ $this->sellRecords = $sellRecords;
+
+ return $this;
+ }
+
+ /**
+ * Get sellRecords
+ *
+ * @return \stdClass
+ */
+ public function getSellRecords() {
+ return $this->sellRecords;
+ }
+}
+
diff --git a/src/AppBundle/Entity/Product.php b/src/AppBundle/Entity/Product.php
index 89ccaf3e..0ccc8413 100644
--- a/src/AppBundle/Entity/Product.php
+++ b/src/AppBundle/Entity/Product.php
@@ -2,6 +2,8 @@
namespace AppBundle\Entity;
+use AppBundle\Traits\Commentable;
+use AppBundle\Traits\Sellable;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -20,18 +22,31 @@ class Product {
*/
private $name;
- /**
- * @ORM\Column(type="decimal", scale=2, nullable=true)
- */
- private $price;
/**
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
*/
private $category;
/**
- * @ORM\OneToMany(targetEntity="SellRecord", mappedBy="products")
+ * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
*/
- private $sellRecords;
+ private $user;
+
+ use Sellable;
+ use Commentable;
+
+ /**
+ * @return mixed
+ */
+ public function getUser() {
+ return $this->user;
+ }
+
+ /**
+ * @param mixed $user
+ */
+ public function setUser( $user ) {
+ $this->user = $user;
+ }
/**
* @return mixed
@@ -88,45 +103,24 @@ class Product {
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;
+ /**
+ * Constructor
+ */
+ public function __construct() {
+ $this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection();
+ }
- return $this;
- }
+ /**
+ * Add sellRecord
+ *
+ * @param \AppBundle\Entity\SellRecord $sellRecord
+ *
+ * @return Product
+ */
+ public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
+ $this->sellRecords[] = $sellRecord;
- /**
- * Remove sellRecord
- *
- * @param \AppBundle\Entity\SellRecord $sellRecord
- */
- public function removeSellRecord(\AppBundle\Entity\SellRecord $sellRecord)
- {
- $this->sellRecords->removeElement($sellRecord);
- }
-
- /**
- * Get sellRecords
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getSellRecords()
- {
- return $this->sellRecords;
- }
+ return $this;
+ }
}
diff --git a/src/AppBundle/Entity/ProductCategory.php b/src/AppBundle/Entity/ProductCategory.php
index f3deb0d2..664c5a77 100644
--- a/src/AppBundle/Entity/ProductCategory.php
+++ b/src/AppBundle/Entity/ProductCategory.php
@@ -25,6 +25,25 @@ class ProductCategory {
*/
private $products;
+ /**
+ * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User", mappedBy="categories")
+ */
+ private $users;
+
+ /**
+ * @return mixed
+ */
+ public function getUsers() {
+ return $this->users;
+ }
+
+ /**
+ * @param mixed $users
+ */
+ public function setUsers( $users ) {
+ $this->users = $users;
+ }
+
/**
* @return mixed
*/
diff --git a/src/AppBundle/Entity/ProductSold.php b/src/AppBundle/Entity/ProductSold.php
new file mode 100644
index 00000000..70104343
--- /dev/null
+++ b/src/AppBundle/Entity/ProductSold.php
@@ -0,0 +1,17 @@
+festival;
+ }
+
+ /**
+ * @param mixed $festival
+ */
+ public function setFestival( $festival ) {
+ $this->festival = $festival;
+ }
+
+
+ /**
+ * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
+ */
+ private $user;
+
+ /**
+ * @return mixed
+ */
+ public function getUser() {
+ return $this->user;
+ }
+
+ /**
+ * @param mixed $user
+ */
+ public function setUser( $user ) {
+ $this->user = $user;
+ }
+
/**
* @return mixed
*/
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index bf42a330..96869db8 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -28,6 +28,80 @@ class User extends BaseUser {
private $googleAccessToken;
+ /**
+ * @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
+ */
+ private $products;
+ /**
+ * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
+ */
+ private $productsSold;
+ /**
+ * @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord", mappedBy="user")
+ */
+ private $sellRecords;
+
+ /**
+ * @return mixed
+ */
+ public function getSellRecords() {
+ return $this->sellRecords;
+ }
+
+ /**
+ * @param mixed $sellRecords
+ */
+ public function setSellRecords( $sellRecords ) {
+ $this->sellRecords = $sellRecords;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getGoogleAccessToken() {
+ return $this->googleAccessToken;
+ }
+
+ /**
+ * @param mixed $googleAccessToken
+ */
+ public function setGoogleAccessToken( $googleAccessToken ) {
+ $this->googleAccessToken = $googleAccessToken;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getProducts() {
+ return $this->products;
+ }
+
+ /**
+ * @param mixed $products
+ */
+ public function setProducts( $products ) {
+ $this->products = $products;
+ }
+
+ /**
+ * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", mappedBy="user")
+ */
+ private $categories;
+
+ /**
+ * @return mixed
+ */
+ public function getCategories() {
+ return $this->categories;
+ }
+
+ /**
+ * @param mixed $categories
+ */
+ public function setCategories( $categories ) {
+ $this->categories = $categories;
+ }
+
/**
* Get id
*
@@ -37,27 +111,25 @@ class User extends BaseUser {
return $this->id;
}
- /**
- * Set googleId
- *
- * @param string $googleId
- *
- * @return User
- */
- public function setGoogleId($googleId)
- {
- $this->googleId = $googleId;
+ /**
+ * Set googleId
+ *
+ * @param string $googleId
+ *
+ * @return User
+ */
+ public function setGoogleId( $googleId ) {
+ $this->googleId = $googleId;
- return $this;
- }
+ return $this;
+ }
- /**
- * Get googleId
- *
- * @return string
- */
- public function getGoogleId()
- {
- return $this->googleId;
- }
+ /**
+ * Get googleId
+ *
+ * @return string
+ */
+ public function getGoogleId() {
+ return $this->googleId;
+ }
}
diff --git a/src/AppBundle/Traits/Commentable.php b/src/AppBundle/Traits/Commentable.php
new file mode 100644
index 00000000..d9071dd2
--- /dev/null
+++ b/src/AppBundle/Traits/Commentable.php
@@ -0,0 +1,27 @@
+comment;
+ }
+
+ /**
+ * @param mixed $comment
+ */
+ public function setComment( $comment ) {
+ $this->comment = $comment;
+ }
+
+
+}
diff --git a/src/AppBundle/Traits/Sellable.php b/src/AppBundle/Traits/Sellable.php
new file mode 100644
index 00000000..b6b14b7b
--- /dev/null
+++ b/src/AppBundle/Traits/Sellable.php
@@ -0,0 +1,25 @@
+price;
+ }
+
+ /**
+ * @param mixed $price
+ */
+ public function setPrice( $price ) {
+ $this->price = $price;
+ }
+}