Article.php 2.0 KB

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