Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User{
- /**
- * @var ArrayCollection
- *
- * @ORM\OneToMany(targetEntity="Shop\Product\ProductBundle\Entity\Product", mappedBy="author")
- */
- private $categories;
- public function __construct()
- {
- $this->salt = bin2hex(random_bytes(10));
- $this->categories = new ArrayCollection();
- }
- /**
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getCategories()
- {
- return $this->categories;
- }
- /**
- * @param Category $category
- * @return User
- */
- public function addCategories(Category $category)
- {
- $this->categories[] = $category;
- return $this;
- }
- }
- }
- class Product
- {
- /**
- * @var int
- *
- * @ORM\Column(name="author_id", type="integer")
- */
- private $authorId;
- /**
- * @var string
- *
- * @ORM\ManyToOne(targetEntity="Customers\User\UserBundle\Entity\User", inversedBy="categories")
- * @ORM\JoinColumn(name="author_id", referencedColumnName="id")
- */
- private $author;
- /**
- * @var string
- *
- * @ORM\Column(name="createdOn", type="datetime", length=255)
- */
- private $createdOn;
- function __construct()
- {
- $this->createdOn = new \DateTime('now', new \DateTimeZone('Europe/Sofia'));
- }
- /**
- * @return int
- */
- public function getAuthorId()
- {
- return $this->authorId;
- }
- /**
- * @param int $authorId
- *
- * @return Product
- */
- public function setAuthorId($authorId)
- {
- $this->authorId = $authorId;
- return $this;
- }
- /**
- * Set author
- *
- * @param User $author
- *
- * @return Product
- */
- public function setAuthor(User $author = null)
- {
- $this->author = $author;
- return $this;
- }
- /**
- * Get author
- *
- * @return User
- */
- public function getAuthor()
- {
- return $this->author;
- }
- }
- //new product controller
- $product->setAuthor($this->getUser());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement