Element.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. use Muzich\CoreBundle\Entity\Tag;
  10. use Muzich\CoreBundle\Managers\CommentsManager;
  11. /**
  12. * L'Element est l'Element central de l'application. C'est cet
  13. * entité qui stocke le media partagé sur le réseau.
  14. *
  15. * @ORM\Entity
  16. * @ORM\Table(name="element")
  17. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\ElementRepository")
  18. *
  19. */
  20. class Element
  21. {
  22. /**
  23. * Identifiant de l'objet externe
  24. * @var string
  25. */
  26. const DATA_REF_ID = "data_ref_id";
  27. /**
  28. * Identifiant de l'objet externe
  29. * @var string
  30. */
  31. const DATA_NORMALIZED_URL = "data_normalized_url";
  32. /**
  33. * Adresse HTTP(S) de la jaquette
  34. * @var string
  35. */
  36. const DATA_THUMB_URL = "data_thumb_url";
  37. /**
  38. * Titre de l'objet externe
  39. * @var string
  40. */
  41. const DATA_TITLE = "data_title";
  42. /**
  43. * Nom de l'artiste
  44. * @var string
  45. */
  46. const DATA_ARTIST = "data_artist";
  47. /**
  48. * Tags de l'objets externe array("tag1", "tag2", [...])
  49. * @var string
  50. */
  51. const DATA_TAGS = "data_tags";
  52. /**
  53. * Type de l'objet track|album|
  54. * @var string
  55. */
  56. const DATA_TYPE = "data_type";
  57. /**
  58. * Contenu téléchargeable ?
  59. * @var string
  60. */
  61. const DATA_DOWNLOAD = "data_download";
  62. /**
  63. * Adresse du contenu téléchargeable
  64. * @var string
  65. */
  66. const DATA_DOWNLOAD_URL = "data_download_url";
  67. /**
  68. * Don possible ?
  69. * @var string
  70. */
  71. const DATA_GIFT = "data_gift";
  72. /**
  73. * Adresse pour effectuer un don
  74. * @var string
  75. */
  76. const DATA_GIFT_URL = "data_gift_url";
  77. const DATA_PLAYLIST_AUTHOR = "data_playlist_author";
  78. const TYPE_TRACK = 'track';
  79. const TYPE_ALBUM = 'album';
  80. const TYPE_PLAYLIST = 'playlist';
  81. const TYPE_OTHER = 'other';
  82. /**
  83. * @ORM\Id
  84. * @ORM\Column(type="integer")
  85. * @ORM\GeneratedValue(strategy="AUTO")
  86. * @var type int
  87. */
  88. protected $id;
  89. /**
  90. * Cet attribut stocke le type d'élément.
  91. *
  92. * @ORM\Column(type="string", length=64)
  93. * @Assert\NotBlank()
  94. * @Assert\Length(max = 255)
  95. */
  96. protected $type;
  97. /**
  98. * Cet attribut stocke la liste des tags liés a cet élément.
  99. *
  100. * @ORM\ManyToMany(targetEntity="Tag", inversedBy="elements")
  101. * @ORM\JoinTable(name="elements_tag")
  102. */
  103. private $tags;
  104. /**
  105. * Propriétaire de l'élément
  106. *
  107. * @ORM\ManyToOne(targetEntity="User", inversedBy="elements")
  108. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  109. */
  110. protected $owner;
  111. /**
  112. * Objet parent (si a été repartagé)
  113. *
  114. * @ORM\ManyToOne(targetEntity="Element", inversedBy="childs")
  115. * @ORM\JoinColumn(name="element_parent_id", referencedColumnName="id")
  116. */
  117. protected $parent;
  118. /**
  119. * Liste des Elements qui on reshare cet element
  120. *
  121. * @ORM\OneToMany(targetEntity="Element", mappedBy="parent")
  122. */
  123. protected $childs;
  124. /**
  125. * Groupe de l'élément
  126. *
  127. * @ORM\ManyToOne(targetEntity="Group", inversedBy="elements")
  128. * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
  129. * @MuzichAssert\GroupOwnedOrPublic()
  130. */
  131. protected $group = null;
  132. /**
  133. * Cet attribu stocke les enregistrements UsersElementsFavorites liés
  134. * a ce Tag dans le cadre des Elements favoris.
  135. *
  136. * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="element")
  137. */
  138. protected $elements_favorites;
  139. /**
  140. * Propositions de tags
  141. *
  142. * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="element", cascade={"remove"})
  143. */
  144. protected $tags_propositions;
  145. /**
  146. * Permet de savoir sans faire de gros calculs en base si il y a des
  147. * propositions de tags en cours sur cet élément.
  148. *
  149. * @ORM\Column(type="boolean", nullable = true)
  150. * @var type string
  151. */
  152. protected $has_tags_proposition = false;
  153. /**
  154. * L'url est l'url du media.
  155. *
  156. * @ORM\Column(type="string", length=1024)
  157. * @Assert\NotBlank(message = "error.element.url.notblank")
  158. * @Assert\Length(max = 1024, maxMessage="error.element.url.tolong")
  159. * @Assert\Url(message = "error.element.url.invalid")
  160. * @var type string
  161. */
  162. protected $url;
  163. /**
  164. * Libellé du media
  165. *
  166. * @ORM\Column(type = "string", length = 128)
  167. * @Assert\NotBlank(message = "error.element.name.notblank")
  168. * @Assert\Length(min = 3, max = 84, minMessage = "error.element.name.toshort", maxMessage = "error.element.name.tolong")
  169. * @var type string
  170. */
  171. protected $name;
  172. /**
  173. * Code d'embed
  174. *
  175. * @ORM\Column(type="text", nullable=true)
  176. * @var type string
  177. */
  178. protected $embed;
  179. /**
  180. * @var datetime $created
  181. *
  182. * @Gedmo\Timestampable(on="create")
  183. * @ORM\Column(type="datetime")
  184. */
  185. private $created;
  186. /**
  187. * @var datetime $updated
  188. *
  189. * @ORM\Column(type="datetime")
  190. * @Gedmo\Timestampable(on="update")
  191. */
  192. private $updated;
  193. /**
  194. * @var string $thumbnail_url
  195. *
  196. * @ORM\Column(type="string", length=512, nullable=true)
  197. */
  198. protected $thumbnail_url;
  199. /**
  200. * Commentaires stocké au format json
  201. *
  202. * array(
  203. * array(
  204. * "u" => array( // Des infos sur l'utilisateur auteur du commentaire
  205. * "i" => "IdDuUser", // l'id
  206. * "s" => "LeSlugDuUser", // le slug
  207. * "n" => "NameDuUser" // le name
  208. * ),
  209. * "d" => "LaDate", // Date au format Y-m-d H:i:s
  210. * "c" => "Comment" // Le commentaire
  211. * ),
  212. * [...]
  213. * );
  214. *
  215. * @ORM\Column(type="text", nullable=true)
  216. * @var type string
  217. */
  218. protected $comments;
  219. /**
  220. * Compteur de signalements
  221. *
  222. * @ORM\Column(type="integer", nullable=true)
  223. * @var int
  224. */
  225. protected $count_report;
  226. /**
  227. * @ORM\Column(type="boolean", nullable=false)
  228. * @var int
  229. */
  230. protected $reported = false;
  231. /**
  232. * array json des id users ayant reporté l'élément
  233. *
  234. * @ORM\Column(type="text", nullable=true)
  235. * @var string
  236. */
  237. protected $report_ids;
  238. /**
  239. * array json des id users ayant voté +1
  240. *
  241. * @ORM\Column(type="text", nullable=true)
  242. * @var string
  243. */
  244. protected $vote_good_ids;
  245. /**
  246. * Compteur de points
  247. *
  248. * @ORM\Column(type="integer", nullable=true)
  249. * @var int
  250. */
  251. protected $points;
  252. /**
  253. * Booléen permettant de savoir si un des commentaires de cet élément
  254. * a été signalé a la modération.
  255. *
  256. * @ORM\Column(type="integer", nullable=true)
  257. * @var int
  258. */
  259. protected $count_comment_report = false;
  260. /**
  261. * Données de l'objet chez le service externe
  262. *
  263. * @ORM\Column(type="text", nullable=true)
  264. * @var type string
  265. */
  266. protected $datas;
  267. /**
  268. *
  269. * @ORM\Column(type="boolean", nullable=true)
  270. * @var boolean
  271. */
  272. protected $need_tags = false;
  273. /**
  274. * Get id
  275. *
  276. * @return integer
  277. */
  278. public function getId()
  279. {
  280. return $this->id;
  281. }
  282. /**
  283. * Set url
  284. *
  285. * @param string $url
  286. */
  287. public function setUrl($url)
  288. {
  289. $this->url = $url;
  290. }
  291. /**
  292. * Get url
  293. *
  294. * @return string
  295. */
  296. public function getUrl()
  297. {
  298. return $this->url;
  299. }
  300. /**
  301. * Set name
  302. *
  303. * @param string $name
  304. */
  305. public function setName($name)
  306. {
  307. $this->name = $name;
  308. }
  309. /**
  310. * Get name
  311. *
  312. * @return string
  313. */
  314. public function getName()
  315. {
  316. return $this->name;
  317. }
  318. /**
  319. * Set type
  320. *
  321. * @param string $type
  322. */
  323. public function setType($type)
  324. {
  325. $this->type = $type;
  326. }
  327. /**
  328. * Get type
  329. *
  330. * @return string
  331. */
  332. public function getType()
  333. {
  334. return $this->type;
  335. }
  336. public function __construct($url = null)
  337. {
  338. //$this->tags = new ArrayCollection();
  339. $this->url = $url;
  340. }
  341. public function __toString()
  342. {
  343. return $this->name;
  344. }
  345. /**
  346. * Add tags
  347. *
  348. * @param Tag $tags
  349. */
  350. public function addTag(Tag $tags)
  351. {
  352. $this->tags[] = $tags;
  353. }
  354. /**
  355. * Get tags
  356. *
  357. * @return Doctrine\Common\Collections\Collection
  358. */
  359. public function getTags()
  360. {
  361. return $this->tags;
  362. }
  363. public function getTagsIdsJson()
  364. {
  365. $ids = array();
  366. if (count($this->getTags()))
  367. {
  368. foreach ($this->getTags() as $tag)
  369. {
  370. $ids[] = $tag->getId();
  371. }
  372. }
  373. return json_encode($ids);
  374. }
  375. public function setTags($tags)
  376. {
  377. $this->tags = $tags;
  378. }
  379. /**
  380. *
  381. * @param Collection|Array $tags
  382. */
  383. public function addTags($tags)
  384. {
  385. foreach ($tags as $tag)
  386. {
  387. $this->addTag($tag);
  388. }
  389. }
  390. /**
  391. * Set owner
  392. *
  393. * @param User $owner
  394. */
  395. public function setOwner(User $owner)
  396. {
  397. $this->owner = $owner;
  398. }
  399. /**
  400. * Get owner
  401. *
  402. * @return User
  403. */
  404. public function getOwner()
  405. {
  406. return $this->owner;
  407. }
  408. /**
  409. * Add elements_favorites
  410. *
  411. * @param UsersElementsFavorites $elementsFavorites
  412. */
  413. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  414. {
  415. $this->elements_favorites[] = $elementsFavorites;
  416. }
  417. /**
  418. * Get elements_favorites
  419. *
  420. * @return Doctrine\Common\Collections\Collection
  421. */
  422. public function getElementsFavorites()
  423. {
  424. return $this->elements_favorites;
  425. }
  426. /**
  427. * Set group
  428. *
  429. * @param Group $group
  430. */
  431. public function setGroup($group)
  432. {
  433. $this->group = $group;
  434. }
  435. /**
  436. * Get group
  437. *
  438. * @return Group
  439. */
  440. public function getGroup()
  441. {
  442. return $this->group;
  443. }
  444. /**
  445. * Set embed
  446. *
  447. * @param string $code
  448. */
  449. public function setEmbed($code)
  450. {
  451. $this->embed = $code;
  452. }
  453. /**
  454. * Get embed
  455. *
  456. * @return string
  457. */
  458. public function getEmbed()
  459. {
  460. return $this->embed;
  461. }
  462. /**
  463. * Set created
  464. *
  465. * @param date $created
  466. */
  467. public function setCreated($created)
  468. {
  469. $this->created = $created;
  470. }
  471. /**
  472. * Get created
  473. *
  474. * @return date
  475. */
  476. public function getCreated()
  477. {
  478. return $this->created;
  479. }
  480. /**
  481. * Set updated
  482. *
  483. * @param datetime $updated
  484. */
  485. public function setUpdated($updated)
  486. {
  487. $this->updated = $updated;
  488. }
  489. /**
  490. * Get updated
  491. *
  492. * @return datetime
  493. */
  494. public function getUpdated()
  495. {
  496. return $this->updated;
  497. }
  498. /**
  499. * Set thumbnail url
  500. *
  501. * @param string $thumbnail_url
  502. */
  503. public function setThumbnailUrl($thumbnail_url)
  504. {
  505. $this->thumbnail_url = $thumbnail_url;
  506. }
  507. /**
  508. * Get thumbnail url
  509. *
  510. * @return datetime
  511. */
  512. public function getThumbnailUrl()
  513. {
  514. return $this->thumbnail_url;
  515. }
  516. /**
  517. *
  518. * @return type array
  519. */
  520. public function getComments()
  521. {
  522. return json_decode($this->comments, true);
  523. }
  524. public function getCountReport()
  525. {
  526. return $this->count_report;
  527. }
  528. public function setCountReport($count)
  529. {
  530. $this->count_report = $count;
  531. if ($count)
  532. {
  533. $this->setReported(true);
  534. }
  535. else
  536. {
  537. $this->setReported(false);
  538. }
  539. }
  540. public function setReported($reported)
  541. {
  542. $this->reported = $reported;
  543. }
  544. public function getReported()
  545. {
  546. return $this->reported;
  547. }
  548. public function getReportIds()
  549. {
  550. return json_decode($this->report_ids, true);
  551. }
  552. public function setReportIds($report_ids)
  553. {
  554. $this->report_ids = json_encode($report_ids);
  555. }
  556. /**
  557. *
  558. * @param array $comments
  559. */
  560. public function setComments($comments)
  561. {
  562. $this->comments = json_encode($comments);
  563. }
  564. /**
  565. *
  566. * @return type array
  567. */
  568. public function getDatas()
  569. {
  570. if ($this->datas === null)
  571. {
  572. return array();
  573. }
  574. return json_decode($this->datas, true);
  575. }
  576. /**
  577. *
  578. * @param string $data_id
  579. * @return all
  580. */
  581. public function getData($data_id)
  582. {
  583. $datas = $this->getDatas();
  584. if (array_key_exists($data_id, $datas))
  585. {
  586. return $datas[$data_id];
  587. }
  588. return null;
  589. }
  590. /**
  591. *
  592. * @param array $datas
  593. */
  594. public function setDatas($datas)
  595. {
  596. $this->datas = json_encode($datas);
  597. }
  598. /**
  599. *
  600. * @param string $data_id
  601. * @param all $data_value
  602. */
  603. public function setData($data_id, $data_value)
  604. {
  605. $datas = $this->getDatas();
  606. $datas[$data_id] = $data_value;
  607. $this->setDatas($datas);
  608. }
  609. public function setHasTagProposition($has_prop)
  610. {
  611. $this->has_tags_proposition = $has_prop;
  612. }
  613. public function hasTagProposition()
  614. {
  615. if ($this->has_tags_proposition === null)
  616. {
  617. return false;
  618. }
  619. return $this->has_tags_proposition;
  620. }
  621. public function getTagsProposition()
  622. {
  623. return $this->tags_propositions;
  624. }
  625. public function setTagsPRopositions($propositions)
  626. {
  627. $this->tags_propositions = $propositions;
  628. }
  629. public function getCountCommentReport()
  630. {
  631. return $this->count_comment_report;
  632. }
  633. public function setCountCommentReport($count)
  634. {
  635. $this->count_comment_report = $count;
  636. }
  637. /**
  638. * Etablie des relation vers des tags.
  639. * (Supprime les anciens tags, au niveau de l'objet seulement)
  640. *
  641. * @param array $ids
  642. */
  643. public function setTagsWithIds(EntityManager $em, $ids)
  644. {
  645. $this->tags = null;
  646. if (count($ids))
  647. {
  648. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
  649. // Pour les nouveaux ids restants
  650. foreach ($tags as $tag)
  651. {
  652. $this->addTag($tag);
  653. }
  654. }
  655. }
  656. // /**
  657. // * Retourne le nombre de fois que cet élément a été msi en favoris
  658. // *
  659. // * @return int
  660. // */
  661. // public function getCountFavorite()
  662. // {
  663. // return count($this->elements_favorites);
  664. // }
  665. public function hasFavoriteUser($user_id)
  666. {
  667. if (count($this->elements_favorites))
  668. {
  669. foreach ($this->elements_favorites as $favorite)
  670. {
  671. if ($favorite->getUser()->getId() == $user_id)
  672. {
  673. return true;
  674. }
  675. }
  676. }
  677. return false;
  678. }
  679. public function setGroupToId()
  680. {
  681. $this->group = $this->group->getId();
  682. }
  683. // public function deleteTag(Tag $tag)
  684. // {
  685. // $this->tags->removeElement($tag);
  686. // }
  687. /**
  688. * Répond vrai si le tag transmis fait partis des tags de l'élément
  689. *
  690. * @param Tag $tag_t
  691. * @return boolean
  692. */
  693. public function hasTag(Tag $tag_t)
  694. {
  695. foreach ($this->getTags() as $tag)
  696. {
  697. if ($tag_t->getId() == $tag->getId())
  698. {
  699. return true;
  700. }
  701. }
  702. return false;
  703. }
  704. public function getPoints()
  705. {
  706. if ($this->points === null)
  707. {
  708. return '0';
  709. }
  710. return $this->points;
  711. }
  712. public function setPoints($points)
  713. {
  714. $this->points = $points;
  715. }
  716. public function getVoteGoodIds()
  717. {
  718. return json_decode($this->vote_good_ids, true);
  719. }
  720. public function setVoteGoodIds($votes_ids)
  721. {
  722. $this->vote_good_ids = json_encode($votes_ids);
  723. }
  724. /**
  725. * ajoute le vote de l'user_id aux votes good
  726. *
  727. * @param int $user_id
  728. */
  729. public function addVoteGood($user_id)
  730. {
  731. $votes = $this->getVoteGoodIds();
  732. if (!count($votes))
  733. {
  734. $votes = array();
  735. }
  736. if (!$this->hasVoteGood($user_id))
  737. {
  738. $votes[] = (string)$user_id;
  739. $this->setPoints(count($votes));
  740. }
  741. $this->setVoteGoodIds($votes);
  742. }
  743. /**
  744. * Retire le vote_good de l'user_id
  745. *
  746. * @param int $user_id
  747. */
  748. public function removeVoteGood($user_id)
  749. {
  750. if (count($votes = $this->getVoteGoodIds()))
  751. {
  752. $votes_n = array();
  753. foreach ($votes as $id)
  754. {
  755. if ($id != $user_id)
  756. {
  757. $votes_n[] = (string)$id;
  758. }
  759. }
  760. $this->setPoints(count($votes_n));
  761. $this->setVoteGoodIds($votes_n);
  762. }
  763. }
  764. /**
  765. * Répond vrai si l'user_id a déjà voté good.
  766. *
  767. * @param int $user_id
  768. * @return boolean
  769. */
  770. public function hasVoteGood($user_id)
  771. {
  772. if (count($votes = $this->getVoteGoodIds()))
  773. {
  774. foreach ($votes as $id)
  775. {
  776. if ($id == $user_id)
  777. {
  778. return true;
  779. }
  780. }
  781. }
  782. return false;
  783. }
  784. /**
  785. * Retourne vrai si l'utilisateur a demandé qa suivre les commentaires
  786. *
  787. * @param int $user_id identifiant de l'utilisateur
  788. * @return boolean
  789. */
  790. public function userFollowComments($user_id)
  791. {
  792. $cm = new CommentsManager($this->getComments());
  793. return $cm->userFollow($user_id);
  794. }
  795. /**
  796. *
  797. * @param Element $element
  798. */
  799. public function setParent(Element $element = null)
  800. {
  801. $this->parent = $element;
  802. }
  803. /**
  804. *
  805. * @return Element
  806. */
  807. public function getParent()
  808. {
  809. return $this->parent;
  810. }
  811. public function setChilds($elements)
  812. {
  813. $this->childs = $elements;
  814. }
  815. public function getChilds()
  816. {
  817. return $this->childs;
  818. }
  819. /**
  820. *
  821. * @param boolean $need
  822. */
  823. public function setNeedTags($need)
  824. {
  825. if ($need)
  826. {
  827. $this->need_tags = true;
  828. }
  829. else
  830. {
  831. $this->need_tags = false;
  832. }
  833. }
  834. /**
  835. *
  836. * @return boolean
  837. */
  838. public function getNeedTags()
  839. {
  840. if ($this->need_tags)
  841. {
  842. return true;
  843. }
  844. return false;
  845. }
  846. public function getProposedName()
  847. {
  848. if (($title = $this->getData(self::DATA_TITLE)))
  849. {
  850. if (($artist = $this->getData(self::DATA_ARTIST)))
  851. {
  852. $artist = ' - '.$artist;
  853. }
  854. return $title.$artist;
  855. }
  856. return null;
  857. }
  858. /**
  859. *
  860. * @return type
  861. */
  862. public function getProposedTags()
  863. {
  864. if (count($tags = $this->getData(self::DATA_TAGS)))
  865. {
  866. return $tags;
  867. }
  868. return array();
  869. }
  870. public function getRefId($api_context = false)
  871. {
  872. if ($api_context && $this->getType() == 'soundcloud.com')
  873. {
  874. return $this->getData(self::DATA_NORMALIZED_URL);
  875. }
  876. return $this->getData(self::DATA_REF_ID);
  877. }
  878. public function hasTagsProposition()
  879. {
  880. if (count($this->tags_propositions))
  881. {
  882. return true;
  883. }
  884. return false;
  885. }
  886. public function getHasTagsProposition()
  887. {
  888. return $this->hasTagsProposition();
  889. }
  890. // TODO: Pas booo ! Ecrit comme ca pour le moment lors de la refacto de UrlAnalyzer
  891. public function getCleanedUrl()
  892. {
  893. // Procèdures de nettoyages après constat d'erreurs
  894. $url = $this->getUrl();
  895. if ($this->getType() == 'deezer.com')
  896. {
  897. $url = urldecode($url);
  898. }
  899. $base_url = $this->getType();
  900. if ($this->getType() == 'spotify.com')
  901. {
  902. $base_url = 'open.spotify.com';
  903. }
  904. $url = str_replace('www.', '', $url);
  905. $url = str_replace('http://'.$base_url, '', $url);
  906. $url = str_replace('https://'.$base_url, '', $url);
  907. if ($this->getType() == 'deezer.com')
  908. {
  909. $url = str_replace(' ', '-', $url);
  910. $url = strtolower($url);
  911. }
  912. return $url;
  913. }
  914. }