Searcher.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Muzich\CoreBundle\Searcher;
  3. use Doctrine\ORM\Query;
  4. use Symfony\Bundle\DoctrineBundle\Registry;
  5. /**
  6. * Objet utiliser pour cadrer la recherche.
  7. *
  8. */
  9. abstract class Searcher
  10. {
  11. /**
  12. * Query est l'objet requete correspondant a la recherche
  13. *
  14. * @var Query
  15. */
  16. protected $query = null;
  17. protected function checkParams($params, $neededs)
  18. {
  19. foreach ($neededs as $config_id => $message)
  20. {
  21. if (!array_key_exists($config_id, $params))
  22. {
  23. throw new \Exception($message);
  24. }
  25. elseif (empty($params[$config_id]))
  26. {
  27. throw new \Exception($message);
  28. }
  29. }
  30. }
  31. protected function setAttributes($params_ids, $params)
  32. {
  33. foreach ($params_ids as $param_id)
  34. {
  35. if (array_key_exists($param_id, $params))
  36. {
  37. $this->$param_id = $params[$param_id];
  38. }
  39. }
  40. }
  41. protected function setQuery(Query $query)
  42. {
  43. $this->query = $query;
  44. }
  45. public function getQuery(Registry $doctrine, $user_id, $exec_type)
  46. {
  47. return $this->query;
  48. }
  49. }