ElementSearcher.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Muzich\CoreBundle\Searcher;
  3. class ElementSearcher extends Searcher implements SearcherInterface
  4. {
  5. /**
  6. * Constante définissant si la recherche porte sur le réseau public
  7. * ou sur le réseau personel de l'utilisateur.
  8. */
  9. const NETWORK_PUBLIC = 'network_public';
  10. const NETWORK_PERSONAL = 'network_personal';
  11. /**
  12. * Réseau sur lequel porte la recherche
  13. *
  14. * @var string
  15. */
  16. protected $network = self::NETWORK_PUBLIC;
  17. /**
  18. * Liste des tag_ids utilisés lors de la recherche.
  19. *
  20. * @var array
  21. */
  22. protected $tags = Array();
  23. /**
  24. * Nombre limite de résultats retournés.
  25. * TODO: Placer cette info dans la config.
  26. *
  27. * @var int
  28. */
  29. protected $count = 20;
  30. /**
  31. * @see SearcherInterface
  32. * @param array $params
  33. */
  34. public function init($params)
  35. {
  36. // Control des parametres transmis.
  37. $this->checkParams($params, array(
  38. 'tags' => "Muzich\CoreBundle\Searcher\ElementSearch::init(): \$params: Au moins un tag est nécéssaire"
  39. ));
  40. // Mise a jour des attributs
  41. $this->setAttributes(array(
  42. 'network', 'tags', 'count'
  43. ), $params);
  44. }
  45. /**
  46. * @see SearcherInterface
  47. * @param array $params
  48. */
  49. public function update($params)
  50. {
  51. // Mise a jour des attributs
  52. $this->setAttributes(array(
  53. 'network', 'tags', 'count'
  54. ), $params);
  55. }
  56. /**
  57. * Récupération des paramètres de la recherche.
  58. *
  59. * @return array
  60. */
  61. public function getParams()
  62. {
  63. return array(
  64. 'network' => $this->getNetwork(),
  65. 'tags' => $this->getTags(),
  66. 'count' => $this->getCount()
  67. );
  68. }
  69. public function getNetwork()
  70. {
  71. return $this->network;
  72. }
  73. public function getTags()
  74. {
  75. return $this->tags;
  76. }
  77. public function getCount()
  78. {
  79. return $this->count;
  80. }
  81. }