Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.19 KB | None | 0 0
  1. CategoryAdmin
  2.  protected function configureFormFields(FormMapper $form)
  3.     {
  4.         $form
  5.             ->add('name',TextType::class)
  6.             ->add('products',EntityType::class,
  7.                 [
  8.                     'class' => Product::class,
  9.                     'property' => 'name',
  10.                     'required' => false,
  11.                 ]);
  12.     }
  13.  
  14.  
  15. <?php
  16.  
  17. namespace AppBundle\Entity;
  18.  
  19. use Doctrine\ORM\Mapping as ORM;
  20.  
  21. /**
  22.  * Category
  23.  *
  24.  * @ORM\Table(name="category")
  25.  * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
  26.  */
  27. class Category
  28. {
  29.     /**
  30.      * @var int
  31.      *
  32.      * @ORM\Column(name="id", type="integer")
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      */
  36.     private $id;
  37.  
  38.     /**
  39.      * @var string
  40.      *
  41.      * @ORM\Column(name="name", type="string", length=255, unique=true)
  42.      */
  43.     private $name;
  44.  
  45.  
  46.     /**
  47.      * @ORM\OneToMany(targetEntity="Product", mappedBy="category")
  48.      */
  49.     private $products;
  50.  
  51.     /**
  52.      * @var \DateTime
  53.      *
  54.      * @ORM\Column(name="createdAt", type="datetime")
  55.      */
  56.     private $createdAt;
  57.  
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="updatedAt", type="string", length=255)
  62.      */
  63.     private $updatedAt;
  64.  
  65.     public function __toString()
  66.     {
  67.         return $this->name;
  68.     }
  69.  
  70.     /**
  71.      * @ORM\PrePersist()
  72.      */
  73.     public function setCreatedDate()
  74.     {
  75.  
  76.         $this->createdAt = new \DateTime();
  77.         $this->updatedAt = new \DateTime();
  78.     }
  79.  
  80.     /**
  81.      * @ORM\PreUpdate()
  82.      */
  83.     public function setUpdateDate()
  84.     {
  85.         $this->updatedAt = new \DateTime();
  86.     }
  87.     /**
  88.      * Constructor
  89.      */
  90.     public function __construct()
  91.     {
  92.         $this->products = new \Doctrine\Common\Collections\ArrayCollection();
  93.     }
  94.  
  95.     /**
  96.      * Get id
  97.      *
  98.      * @return integer
  99.      */
  100.     public function getId()
  101.     {
  102.         return $this->id;
  103.     }
  104.  
  105.     /**
  106.      * Set name
  107.      *
  108.      * @param string $name
  109.      *
  110.      * @return Category
  111.      */
  112.     public function setName($name)
  113.     {
  114.         $this->name = $name;
  115.  
  116.         return $this;
  117.     }
  118.  
  119.     /**
  120.      * Get name
  121.      *
  122.      * @return string
  123.      */
  124.     public function getName()
  125.     {
  126.         return $this->name;
  127.     }
  128.  
  129.     /**
  130.      * Set createdAt
  131.      *
  132.      * @param \DateTime $createdAt
  133.      *
  134.      * @return Category
  135.      */
  136.     public function setCreatedAt($createdAt)
  137.     {
  138.         $this->createdAt = $createdAt;
  139.  
  140.         return $this;
  141.     }
  142.  
  143.     /**
  144.      * Get createdAt
  145.      *
  146.      * @return \DateTime
  147.      */
  148.     public function getCreatedAt()
  149.     {
  150.         return $this->createdAt;
  151.     }
  152.  
  153.     /**
  154.      * Set updatedAt
  155.      *
  156.      * @param string $updatedAt
  157.      *
  158.      * @return Category
  159.      */
  160.     public function setUpdatedAt($updatedAt)
  161.     {
  162.         $this->updatedAt = $updatedAt;
  163.  
  164.         return $this;
  165.     }
  166.  
  167.     /**
  168.      * Get updatedAt
  169.      *
  170.      * @return string
  171.      */
  172.     public function getUpdatedAt()
  173.     {
  174.         return $this->updatedAt;
  175.     }
  176.  
  177.  
  178.     /**
  179.      * Add product
  180.      *
  181.      * @param \AppBundle\Entity\Product $product
  182.      *
  183.      * @return Category
  184.      */
  185.     public function addProduct(\AppBundle\Entity\Product $product = null)
  186.     {
  187.         $this->products[] = $product;
  188.  
  189.         return $this;
  190.     }
  191.  
  192.     /**
  193.      * Remove product
  194.      *
  195.      * @param \AppBundle\Entity\Product $product
  196.      */
  197.     public function removeProduct(\AppBundle\Entity\Product $product)
  198.     {
  199.         $this->products->removeElement($product);
  200.     }
  201.  
  202.     /**
  203.      * Get products
  204.      *
  205.      * @return \Doctrine\Common\Collections\Collection
  206.      */
  207.     public function getProducts()
  208.     {
  209.         return $this->products;
  210.     }
  211. }
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. <?php
  222.  
  223. namespace AppBundle\Entity;
  224.  
  225. use Doctrine\ORM\Mapping as ORM;
  226.  
  227. /**
  228.  * Product
  229.  *
  230.  * @ORM\Table(name="product")
  231.  * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
  232.  * @ORM\HasLifecycleCallbacks()
  233.  */
  234. class Product
  235. {
  236.     /**
  237.      * @var int
  238.      *
  239.      * @ORM\Column(name="id", type="integer")
  240.      * @ORM\Id
  241.      * @ORM\GeneratedValue(strategy="AUTO")
  242.      */
  243.     private $id;
  244.  
  245.     /**
  246.      * @var string
  247.      *
  248.      * @ORM\Column(name="name", type="string", length=255, unique=true)
  249.      */
  250.     private $name;
  251.  
  252.     /**
  253.      * @var \DateTime
  254.      *
  255.      * @ORM\Column(name="createdAt", type="datetime")
  256.      */
  257.     private $createdAt;
  258.  
  259.     /**
  260.      * @var \DateTime
  261.      *
  262.      * @ORM\Column(name="updatedAt", type="datetime")
  263.      */
  264.     private $updatedAt;
  265.  
  266.     /**
  267.      * @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
  268.      * @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
  269.      */
  270.     private $category;
  271.  
  272.     /**
  273.      * THIS ALLOW TO SHOW PRETTY NAME
  274.      *      Item "IPHONE" has been successfully created.
  275.      * INSTEAD OF :
  276.      *      Item "AppBundle\Entity\Product:00000000386cfe5f00000000bdb77d26" has been successfully created.
  277.      * @return string
  278.      */
  279.     public function __toString()
  280.     {
  281.         return $this->name;
  282.     }
  283.  
  284.     /**
  285.      * @ORM\PrePersist()
  286.      */
  287.     public function setCreatedDate()
  288.     {
  289.         $this->createdAt = new \DateTime();
  290.         $this->updatedAt = new \DateTime();
  291.     }
  292.  
  293.     /**
  294.      * @ORM\PreUpdate()
  295.      */
  296.     public function setUpdateDate()
  297.     {
  298.         $this->updatedAt = new \DateTime();
  299.     }
  300.  
  301.  
  302.     /**
  303.      * Get id
  304.      *
  305.      * @return integer
  306.      */
  307.     public function getId()
  308.     {
  309.         return $this->id;
  310.     }
  311.  
  312.     /**
  313.      * Set name
  314.      *
  315.      * @param string $name
  316.      *
  317.      * @return Product
  318.      */
  319.     public function setName($name)
  320.     {
  321.         $this->name = $name;
  322.  
  323.         return $this;
  324.     }
  325.  
  326.     /**
  327.      * Get name
  328.      *
  329.      * @return string
  330.      */
  331.     public function getName()
  332.     {
  333.         return $this->name;
  334.     }
  335.  
  336.     /**
  337.      * Set createdAt
  338.      *
  339.      * @param \DateTime $createdAt
  340.      *
  341.      * @return Product
  342.      */
  343.     public function setCreatedAt($createdAt)
  344.     {
  345.         $this->createdAt = $createdAt;
  346.  
  347.         return $this;
  348.     }
  349.  
  350.     /**
  351.      * Get createdAt
  352.      *
  353.      * @return \DateTime
  354.      */
  355.     public function getCreatedAt()
  356.     {
  357.         return $this->createdAt;
  358.     }
  359.  
  360.     /**
  361.      * Set updatedAt
  362.      *
  363.      * @param \DateTime $updatedAt
  364.      *
  365.      * @return Product
  366.      */
  367.     public function setUpdatedAt($updatedAt)
  368.     {
  369.         $this->updatedAt = $updatedAt;
  370.  
  371.         return $this;
  372.     }
  373.  
  374.     /**
  375.      * Get updatedAt
  376.      *
  377.      * @return \DateTime
  378.      */
  379.     public function getUpdatedAt()
  380.     {
  381.         return $this->updatedAt;
  382.     }
  383.  
  384.  
  385.     /**
  386.      * Set category
  387.      *
  388.      * @param \AppBundle\Entity\Category $category
  389.      *
  390.      * @return Product
  391.      */
  392.     public function setCategory(\AppBundle\Entity\Category $category = null)
  393.     {
  394.         $this->category = $category;
  395.  
  396.         return $this;
  397.     }
  398.  
  399.     /**
  400.      * Get category
  401.      *
  402.      * @return \AppBundle\Entity\Category
  403.      */
  404.     public function getCategory()
  405.     {
  406.         return $this->category;
  407.     }
  408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement