Event.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace Muzich\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use \Doctrine\Common\Collections\ArrayCollection;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. /**
  7. * L'Element est l'Element central de l'application. C'est cet
  8. * entité qui stocke le media partagé sur le réseau.
  9. *
  10. * @ORM\Entity
  11. * @ORM\Table(name="event")
  12. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\EventRepository")
  13. *
  14. */
  15. class Event
  16. {
  17. const TYPE_COMMENT_ADDED_ELEMENT = "com.adde.ele";
  18. const TYPE_FAV_ADDED_ELEMENT = "fav.adde.ele";
  19. const TYPE_USER_FOLLOW = "user.follow";
  20. const TYPE_TAGS_PROPOSED = "tags.prop.ad";
  21. /**
  22. * @ORM\Id
  23. * @ORM\Column(type="integer")
  24. * @ORM\GeneratedValue(strategy="AUTO")
  25. * @var type int
  26. */
  27. protected $id;
  28. /**
  29. * array json des id d'éléments/users/...
  30. *
  31. * @ORM\Column(type="text", nullable=true)
  32. * @var string
  33. */
  34. protected $ids;
  35. /**
  36. * Compteur d'élément/users concernés
  37. *
  38. * @ORM\Column(type="integer", nullable=true)
  39. * @var int
  40. */
  41. protected $count;
  42. /**
  43. * Type (constitué de la valeur d'une des
  44. *
  45. * @ORM\Column(type = "string", length = 12)
  46. * @var type string
  47. */
  48. protected $type;
  49. /**
  50. * Propriétaire de l'event
  51. *
  52. * @ORM\ManyToOne(targetEntity="User", inversedBy="events")
  53. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  54. */
  55. protected $user;
  56. /*
  57. *
  58. * getters / setters
  59. *
  60. */
  61. public function getId()
  62. {
  63. return $this->id;
  64. }
  65. public function getIds()
  66. {
  67. return json_decode($this->ids, true);
  68. }
  69. public function setIds($ids)
  70. {
  71. $this->ids = json_encode($ids);
  72. }
  73. public function getCount()
  74. {
  75. return $this->count;
  76. }
  77. public function setCount($count)
  78. {
  79. $this->count = $count;
  80. }
  81. public function getType()
  82. {
  83. return $this->type;
  84. }
  85. public function setType($type)
  86. {
  87. $this->type = $type;
  88. }
  89. public function getUser()
  90. {
  91. return $this->user;
  92. }
  93. public function setUser($user)
  94. {
  95. $this->user = $user;
  96. }
  97. /*
  98. * other methods
  99. *
  100. */
  101. /**
  102. * Ajoute l'identifiant a la liste d'identifiant
  103. *
  104. * @param int $id
  105. */
  106. public function addId($id)
  107. {
  108. $ids = $this->getIds();
  109. if (!count($ids))
  110. {
  111. $ids = array();
  112. }
  113. if (!$this->hasId($id))
  114. {
  115. $ids[] = (string)$id;
  116. $this->setCount(count($ids));
  117. }
  118. $this->setIds($ids);
  119. }
  120. /**
  121. * Répond vrai si l'id transmis fait partis des ids
  122. *
  123. * @param int $id_check
  124. * @return boolean
  125. */
  126. public function hasId($id_check)
  127. {
  128. if (count($ids = $this->getIds()))
  129. {
  130. foreach ($ids as $id)
  131. {
  132. if ($id == $id_check)
  133. {
  134. return true;
  135. }
  136. }
  137. }
  138. return false;
  139. }
  140. }