Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /**
  2. * Contacts
  3. *
  4. * @ORMTable(name="contacts")
  5. * @ORMEntity(repositoryClass="AppBundleRepositoryContactsRepository")
  6. */
  7. class Contacts
  8. {
  9. ....
  10.  
  11. /**
  12. * @var DoctrineCommonCollectionsCollection
  13. *
  14. * @ORMManyToMany(targetEntity="AppBundleEntityMedias", inversedBy="contact")
  15. * @ORMJoinTable(name="contacts_has_medias",
  16. * joinColumns={
  17. * @ORMJoinColumn(name="contact_id", referencedColumnName="id")
  18. * },
  19. * inverseJoinColumns={
  20. * @ORMJoinColumn(name="media_id", referencedColumnName="id")
  21. * }
  22. * )
  23. */
  24. private $media;
  25.  
  26. ....
  27.  
  28. class ContactsRepository extends EntityRepository
  29. {
  30.  
  31. public function getContacts()
  32. {
  33. return $this->getEntityManager()
  34. ->createQuery(
  35. 'SELECT c FROM AppBundle:Contact c ORDER BY c.Name ASC'
  36. )
  37. ->getResult();
  38. }
  39.  
  40. public function getContact($idContact)
  41. {
  42.  
  43. $qb = $this->createQueryBuilder('c')
  44. ->andWhere('c.id = :idContact')
  45. ->setParameter('idContact', $idContact);
  46.  
  47. $query = $qb->getQuery();
  48. return $query->execute();
  49.  
  50. }
  51. }
  52.  
  53. /**
  54. * Medias
  55. *
  56. * @ORMTable(name="medias")
  57. * @ORMEntity
  58. */
  59.  
  60. class Medias
  61. {
  62.  
  63. /**
  64. * @var integer
  65. *
  66. * @ORMColumn(name="id", type="integer")
  67. * @ORMId
  68. * @ORMGeneratedValue(strategy="IDENTITY")
  69. */
  70. private $id;
  71.  
  72. /**
  73. * @var string
  74. *
  75. * @ORMOneToMany(targetEntity="AppBundleEntityCharges", mappedBy="media", cascade={"ALL"}, indexBy="contact")
  76. */
  77. private $charge;
  78.  
  79. ....
  80.  
  81. /**
  82. * Charges
  83. *
  84. * @ORMTable(name="charges")
  85. * @ORMEntity
  86. * @UniqueEntity(fields={"contact_id", "media_id"})
  87. */
  88. class Charges
  89. {
  90. /**
  91. * @var string
  92. *
  93. * @ORMColumn(name="charge", type="string", length=255, nullable=true)
  94. */
  95. private $charge;
  96.  
  97. /**
  98. * @ORMId
  99. * @ORMManyToOne(targetEntity="AppBundleEntityContacts")
  100. * @ORMGeneratedValue(strategy="NONE")
  101. */
  102. private $contact;
  103.  
  104. /**
  105. * @ORMId
  106. * @ORMManyToOne(targetEntity="AppBundleEntityMedias", inversedBy="charge")
  107. * @ORMGeneratedValue(strategy="NONE")
  108. */
  109. private $media;
  110.  
  111. public function __construct(Contact $contact, Media $media, $charge)
  112. {
  113. $this->media = $media;
  114. $this->contact = $contact;
  115. $this->charge = $charge;
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement