Article.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Translatable\Fixture\Issue75;
  3. /**
  4. * @Entity
  5. */
  6. class Article
  7. {
  8. /**
  9. * @Id
  10. * @GeneratedValue
  11. * @Column(type="integer")
  12. */
  13. private $id;
  14. /**
  15. * @gedmo:Translatable
  16. * @Column(name="title", type="string", length=128)
  17. */
  18. private $title;
  19. /**
  20. * @ManyToMany(targetEntity="Image", inversedBy="articles")
  21. * @JoinTable(name="article_images",
  22. * joinColumns={@JoinColumn(name="image_id", referencedColumnName="id")},
  23. * inverseJoinColumns={@JoinColumn(name="article_id", referencedColumnName="id")}
  24. * )
  25. */
  26. private $images;
  27. /**
  28. * @ManyToMany(targetEntity="File")
  29. */
  30. private $files;
  31. public function __construct()
  32. {
  33. // $images is not an array, its a collection
  34. // if you want to do such operations you have to cunstruct it
  35. $this->images = new \Doctrine\Common\Collections\ArrayCollection();
  36. }
  37. public function getId()
  38. {
  39. return $this->id;
  40. }
  41. public function addImage(Image $image)
  42. {
  43. $this->images[] = $image;
  44. }
  45. public function setImages(array $images)
  46. {
  47. foreach ($images as $img) {
  48. // first check if it does not contain it allready
  49. // because all entity objects are allready in memory
  50. // simply $em->find('Image', $id); and you will get it from this collection
  51. if (!$this->images->contains($img)) {
  52. $this->addImage($img);
  53. }
  54. }
  55. }
  56. public function getImages()
  57. {
  58. return $this->images;
  59. }
  60. public function addFile(File $file)
  61. {
  62. $this->files[] = $file;
  63. }
  64. public function getFiles()
  65. {
  66. return $this->files;
  67. }
  68. public function setTitle($title)
  69. {
  70. $this->title = $title;
  71. }
  72. public function getTitle()
  73. {
  74. return $this->title;
  75. }
  76. }