Element.php 19KB

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