Element.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. use Doctrine\ORM\EntityManager;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Muzich\CoreBundle\Validator as MuzichAssert;
  9. /**
  10. * L'Element est l'Element central de l'application. C'est cet
  11. * entité qui stocke le media partagé sur le réseau.
  12. *
  13. * @ORM\Entity
  14. * @ORM\Table(name="element")
  15. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\ElementRepository")
  16. *
  17. */
  18. class Element
  19. {
  20. /**
  21. * @ORM\Id
  22. * @ORM\Column(type="integer")
  23. * @ORM\GeneratedValue(strategy="AUTO")
  24. * @var type int
  25. */
  26. protected $id;
  27. /**
  28. * Cet attribut stocke le type d'élément.
  29. *
  30. * @ORM\ManyToOne(targetEntity="ElementType", inversedBy="elements")
  31. * @ORM\JoinColumn(name="element_type_id", referencedColumnName="id")
  32. */
  33. protected $type;
  34. /**
  35. * Cet attribut stocke la liste des tags liés a cet élément.
  36. *
  37. * @ORM\ManyToMany(targetEntity="Tag", inversedBy="elements")
  38. * @ORM\JoinTable(name="elements_tag")
  39. * @MuzichAssert\Tags()
  40. */
  41. private $tags;
  42. /**
  43. * Propriétaire de l'élément
  44. *
  45. * @ORM\ManyToOne(targetEntity="User", inversedBy="elements")
  46. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  47. */
  48. protected $owner;
  49. /**
  50. * Groupe de l'élément
  51. *
  52. * @ORM\ManyToOne(targetEntity="Group", inversedBy="elements")
  53. * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
  54. * @MuzichAssert\GroupOwnedOrPublic()
  55. */
  56. protected $group = null;
  57. /**
  58. * Cet attribu stocke les enregistrements UsersElementsFavorites liés
  59. * a ce Tag dans le cadre des Elements favoris.
  60. *
  61. * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="element")
  62. */
  63. protected $elements_favorites;
  64. /**
  65. * L'url est l'url du media.
  66. *
  67. * @ORM\Column(type="string", length=1024)
  68. * @Assert\NotBlank()
  69. * @Assert\MaxLength(1024)
  70. * @var type string
  71. */
  72. protected $url;
  73. /**
  74. * Libellé du media
  75. *
  76. * @ORM\Column(type="string", length=128)
  77. * @Assert\NotBlank()
  78. * @Assert\MinLength(limit=3)
  79. * @Assert\MaxLength(64)
  80. * @var type string
  81. */
  82. protected $name;
  83. /**
  84. * Code d'embed
  85. *
  86. * @ORM\Column(type="text", nullable=true)
  87. * @var type string
  88. */
  89. protected $embed;
  90. /**
  91. * @var datetime $created
  92. *
  93. * @Gedmo\Timestampable(on="create")
  94. * @ORM\Column(type="datetime")
  95. */
  96. private $created;
  97. /**
  98. * @var datetime $updated
  99. *
  100. * @ORM\Column(type="datetime")
  101. * @Gedmo\Timestampable(on="update")
  102. */
  103. private $updated;
  104. /**
  105. * Get id
  106. *
  107. * @return integer
  108. */
  109. public function getId()
  110. {
  111. return $this->id;
  112. }
  113. /**
  114. * Set url
  115. *
  116. * @param string $url
  117. */
  118. public function setUrl($url)
  119. {
  120. $this->url = $url;
  121. }
  122. /**
  123. * Get url
  124. *
  125. * @return string
  126. */
  127. public function getUrl()
  128. {
  129. return $this->url;
  130. }
  131. /**
  132. * Set name
  133. *
  134. * @param string $name
  135. */
  136. public function setName($name)
  137. {
  138. $this->name = $name;
  139. }
  140. /**
  141. * Get name
  142. *
  143. * @return string
  144. */
  145. public function getName()
  146. {
  147. return $this->name;
  148. }
  149. /**
  150. * Set type
  151. *
  152. * @param ElementType $type
  153. */
  154. public function setType(ElementType $type = null)
  155. {
  156. $this->type = $type;
  157. }
  158. /**
  159. * Get type
  160. *
  161. * @return ElementType
  162. */
  163. public function getType()
  164. {
  165. return $this->type;
  166. }
  167. public function __construct($url = null)
  168. {
  169. //$this->tags = new ArrayCollection();
  170. $this->url = $url;
  171. }
  172. public function __toString()
  173. {
  174. return $this->name;
  175. }
  176. /**
  177. * Add tags
  178. *
  179. * @param Tag $tags
  180. */
  181. public function addTag(Tag $tags)
  182. {
  183. $this->tags[] = $tags;
  184. }
  185. /**
  186. * Get tags
  187. *
  188. * @return Doctrine\Common\Collections\Collection
  189. */
  190. public function getTags()
  191. {
  192. return $this->tags;
  193. }
  194. public function setTags($tags)
  195. {
  196. $this->tags = $tags;
  197. }
  198. /**
  199. * Set owner
  200. *
  201. * @param User $owner
  202. */
  203. public function setOwner(User $owner)
  204. {
  205. $this->owner = $owner;
  206. }
  207. /**
  208. * Get owner
  209. *
  210. * @return User
  211. */
  212. public function getOwner()
  213. {
  214. return $this->owner;
  215. }
  216. /**
  217. * Add elements_favorites
  218. *
  219. * @param UsersElementsFavorites $elementsFavorites
  220. */
  221. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  222. {
  223. $this->elements_favorites[] = $elementsFavorites;
  224. }
  225. /**
  226. * Get elements_favorites
  227. *
  228. * @return Doctrine\Common\Collections\Collection
  229. */
  230. public function getElementsFavorites()
  231. {
  232. return $this->elements_favorites;
  233. }
  234. /**
  235. * Set group
  236. *
  237. * @param Group $group
  238. */
  239. public function setGroup($group)
  240. {
  241. $this->group = $group;
  242. }
  243. /**
  244. * Get group
  245. *
  246. * @return Group
  247. */
  248. public function getGroup()
  249. {
  250. return $this->group;
  251. }
  252. /**
  253. * Set embed
  254. *
  255. * @param string $code
  256. */
  257. public function setEmbed($code)
  258. {
  259. $this->embed = $code;
  260. }
  261. /**
  262. * Get embed
  263. *
  264. * @return string
  265. */
  266. public function getEmbed()
  267. {
  268. return $this->embed;
  269. }
  270. /**
  271. * Set created
  272. *
  273. * @param date $created
  274. */
  275. public function setCreated($created)
  276. {
  277. $this->created = $created;
  278. }
  279. /**
  280. * Get created
  281. *
  282. * @return date
  283. */
  284. public function getCreated()
  285. {
  286. return $this->created;
  287. }
  288. /**
  289. * Set updated
  290. *
  291. * @param datetime $updated
  292. */
  293. public function setUpdated($updated)
  294. {
  295. $this->updated = $updated;
  296. }
  297. /**
  298. * Get updated
  299. *
  300. * @return datetime
  301. */
  302. public function getUpdated()
  303. {
  304. return $this->updated;
  305. }
  306. /**
  307. * Etablie des relation vers des tags.
  308. * (Supprime les anciens tags, au niveau de l'objet seulement)
  309. *
  310. * @param array $ids
  311. */
  312. public function setTagsWithIds(EntityManager $em, $ids)
  313. {
  314. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
  315. $this->tags = null;
  316. // Pour les nouveaux ids restants
  317. foreach ($tags as $tag)
  318. {
  319. $this->addTag($tag);
  320. }
  321. }
  322. public function getCountFavorite()
  323. {
  324. return count($this->elements_favorites);
  325. }
  326. public function setGroupToId()
  327. {
  328. $this->group = $this->group->getId();
  329. }
  330. }