traits for entities

This commit is contained in:
Kayn Ty 2018-04-05 15:05:04 +02:00
parent d1ea133d76
commit 884faf23af
11 changed files with 426 additions and 77 deletions

View File

@ -4,22 +4,34 @@
<div id="wrapper"> <div id="wrapper">
<div id="container" class="container"> <div id="container" class="container">
<div id="menu-dashboard"> <div id="menu-dashboard">
<a href="#caisse-now">Caisse</a> <ul class="nav nav-pills">
<a href="#categories">Catégories</a> <li>
<a href="#products">Produits</a> <a href="#caisse-now" data-toggle="tab">Caisse</a>
<a href="#history">Historique</a> </li>
<li>
<a href="#categories" data-toggle="tab">Catégories</a>
</li>
<li>
<a href="#products" data-toggle="tab">Produits</a>
</li>
<li>
<a href="#history" data-toggle="tab">Historique</a>
</li>
</ul>
</div> </div>
<div id="caisse-now"> <div id="caisse-now" class="tab-pane fade in active">
<h2>Caisse</h2> <h2>Caisse</h2>
{% include 'logged/caisse-main.html.twig' %} {% include 'logged/caisse-main.html.twig' %}
</div> </div>
<div id="categories"> <div id="categories" class="tab-pane fade">
<h2>Catégories</h2> <h2>Catégories</h2>
</div> </div>
<div id="products"> <div id="products" class="tab-pane fade">
<h2>Produits</h2> <h2>Produits</h2>
</div> </div>
<div id="history"> <div id="history" class="tab-pane fade">
<h2>Historique</h2> <h2>Historique</h2>
</div> </div>
</div> </div>

View File

@ -7,6 +7,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; 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 { class DefaultController extends Controller {
@ -54,10 +57,26 @@ class DefaultController extends Controller {
} }
public function getMyProductsAction() { public function getMyProductsAction() {
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
if ( ! $currentUser ) {
return new JsonResponse( [ return new JsonResponse( [
[ 'id' => 1, "name" => 'truc', "category" => 1, "price" => 9 ], 'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
// [ 'id' => 2, name => 'truc2', category => 1, price => 4 ], 'recentSells' => [['']],
// [ id => 3, name => 'truc3', category => 2, price => 1 ], ] );
}
$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( [
'categories' => $categories,
'recentSells' => $recentSells,
] ); ] );
} }

View File

@ -0,0 +1,120 @@
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Festival
*
* @ORM\Table(name="festival")
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/
class Festival {
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var \DateTime
*
* @ORM\Column(name="dateCreation", type="datetime")
*/
private $dateCreation;
/**
* @var \stdClass
*
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord",mappedBy="festival")
*/
private $sellRecords;
/**
* Get id
*
* @return int
*/
public function getId() {
return $this->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;
}
}

View File

@ -2,6 +2,8 @@
namespace AppBundle\Entity; namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use AppBundle\Traits\Sellable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
@ -20,18 +22,31 @@ class Product {
*/ */
private $name; private $name;
/**
* @ORM\Column(type="decimal", scale=2, nullable=true)
*/
private $price;
/** /**
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products") * @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
*/ */
private $category; 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 * @return mixed
@ -88,11 +103,11 @@ class Product {
public function setCategory( ProductCategory $category ) { public function setCategory( ProductCategory $category ) {
$this->category = $category; $this->category = $category;
} }
/** /**
* Constructor * Constructor
*/ */
public function __construct() public function __construct() {
{
$this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection(); $this->sellRecords = new \Doctrine\Common\Collections\ArrayCollection();
} }
@ -103,30 +118,9 @@ class Product {
* *
* @return Product * @return Product
*/ */
public function addSellRecord(\AppBundle\Entity\SellRecord $sellRecord) public function addSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
{
$this->sellRecords[] = $sellRecord; $this->sellRecords[] = $sellRecord;
return $this; return $this;
} }
/**
* 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;
}
} }

View File

@ -25,6 +25,25 @@ class ProductCategory {
*/ */
private $products; 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 * @return mixed
*/ */

View File

@ -0,0 +1,17 @@
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
*/
class ProductSold extends Product {
/**
* @ORM\OneToMany(targetEntity="SellRecord", mappedBy="products")
*/
private $sellRecords;
}

View File

@ -2,6 +2,7 @@
namespace AppBundle\Entity; namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
@ -29,6 +30,49 @@ class SellRecord {
*/ */
private $amount; private $amount;
/**
* @var
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Festival",inversedBy="sellRecords")
*/
private $festival;
use Commentable;
/**
* @return mixed
*/
public function getFestival() {
return $this->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 * @return mixed
*/ */

View File

@ -28,6 +28,80 @@ class User extends BaseUser {
private $googleAccessToken; 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 * Get id
* *
@ -44,8 +118,7 @@ class User extends BaseUser {
* *
* @return User * @return User
*/ */
public function setGoogleId($googleId) public function setGoogleId( $googleId ) {
{
$this->googleId = $googleId; $this->googleId = $googleId;
return $this; return $this;
@ -56,8 +129,7 @@ class User extends BaseUser {
* *
* @return string * @return string
*/ */
public function getGoogleId() public function getGoogleId() {
{
return $this->googleId; return $this->googleId;
} }
} }

View File

@ -0,0 +1,27 @@
<?php
namespace AppBundle\Traits;
trait Commentable {
/**
* @ORM\Column(type="string", length=256 , nullable=true)
*/
private $comment;
/**
* @return mixed
*/
public function getComment() {
return $this->comment;
}
/**
* @param mixed $comment
*/
public function setComment( $comment ) {
$this->comment = $comment;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace AppBundle\Traits;
trait Sellable {
/**
* @ORM\Column(type="decimal", scale=2, nullable=true)
*/
private $price;
/**
* @return mixed
*/
public function getPrice() {
return $this->price;
}
/**
* @param mixed $price
*/
public function setPrice( $price ) {
$this->price = $price;
}
}