Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. class User{
  2.     /**
  3.      * @var ArrayCollection
  4.      *
  5.      * @ORM\OneToMany(targetEntity="Shop\Product\ProductBundle\Entity\Product", mappedBy="author")
  6.      */
  7.     private $categories;
  8.  
  9.  
  10.     public function __construct()
  11.     {
  12.         $this->salt = bin2hex(random_bytes(10));
  13.         $this->categories = new ArrayCollection();
  14.     }
  15.  
  16.     /**
  17.      * @return \Doctrine\Common\Collections\Collection
  18.      */
  19.     public function getCategories()
  20.     {
  21.         return $this->categories;
  22.     }
  23.  
  24.     /**
  25.      * @param Category $category
  26.      * @return User
  27.      */
  28.     public function addCategories(Category $category)
  29.     {
  30.         $this->categories[] = $category;
  31.  
  32.         return $this;
  33.     }
  34. }
  35. }
  36.  
  37. class Product
  38. {
  39. /**
  40.      * @var int
  41.      *
  42.      * @ORM\Column(name="author_id", type="integer")
  43.      */
  44.     private $authorId;
  45.  
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\ManyToOne(targetEntity="Customers\User\UserBundle\Entity\User", inversedBy="categories")
  50.      * @ORM\JoinColumn(name="author_id", referencedColumnName="id")
  51.      */
  52.     private $author;
  53.  
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="createdOn", type="datetime", length=255)
  58.      */
  59.     private $createdOn;
  60.  
  61.     function __construct()
  62.     {
  63.         $this->createdOn = new \DateTime('now', new \DateTimeZone('Europe/Sofia'));
  64.     }
  65.  
  66.     /**
  67.      * @return int
  68.      */
  69.     public function getAuthorId()
  70.     {
  71.         return $this->authorId;
  72.     }
  73.  
  74.     /**
  75.      * @param int $authorId
  76.      *
  77.      * @return Product
  78.      */
  79.     public function setAuthorId($authorId)
  80.     {
  81.         $this->authorId = $authorId;
  82.  
  83.         return $this;
  84.     }
  85.  
  86.     /**
  87.      * Set author
  88.      *
  89.      * @param User $author
  90.      *
  91.      * @return Product
  92.      */
  93.     public function setAuthor(User $author = null)
  94.     {
  95.         $this->author = $author;
  96.  
  97.         return $this;
  98.     }
  99.  
  100.     /**
  101.      * Get author
  102.      *
  103.      * @return User
  104.      */
  105.     public function getAuthor()
  106.     {
  107.         return $this->author;
  108.     }
  109. }
  110.    
  111. //new product controller
  112.  
  113. $product->setAuthor($this->getUser());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement