Filter.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Filter;
  11. use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
  12. use Sonata\AdminBundle\Filter\FilterInterface;
  13. use Doctrine\ORM\QueryBuilder;
  14. use Symfony\Component\Form\FormFactory;
  15. abstract class Filter implements FilterInterface
  16. {
  17. protected $name = null;
  18. protected $value = null;
  19. protected $options = array();
  20. protected $fieldDescription = array();
  21. public function setFieldDescription(FieldDescriptionInterface $fieldDescription)
  22. {
  23. $this->name = $fieldDescription->getName();
  24. $this->fieldDescription = $fieldDescription;
  25. $this->options = array_merge($this->getDefaultOptions(), $fieldDescription->getOptions());
  26. }
  27. public function getName()
  28. {
  29. return $this->name;
  30. }
  31. /**
  32. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  33. */
  34. public function getFieldDescription()
  35. {
  36. return $this->fieldDescription;
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function getDefaultOptions()
  42. {
  43. return array();
  44. }
  45. /**
  46. * @param $name
  47. * @param null $default
  48. * @return mixed
  49. */
  50. public function getOption($name, $default = null)
  51. {
  52. if (array_key_exists($name, $this->options)) {
  53. return $this->options[$name];
  54. }
  55. return $default;
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getFieldType()
  61. {
  62. return $this->getOption('field_type', 'text');
  63. }
  64. /**
  65. * @return array
  66. */
  67. public function getFieldOptions()
  68. {
  69. return $this->getOption('field_options', array('required' => false));
  70. }
  71. /**
  72. * @param $options
  73. * @return void
  74. */
  75. public function setOptions($options)
  76. {
  77. $this->options = $options;
  78. }
  79. /**
  80. * @return array
  81. */
  82. public function getOptions()
  83. {
  84. return $this->options;
  85. }
  86. /**
  87. * @param $value
  88. * @return void
  89. */
  90. public function setValue($value)
  91. {
  92. $this->value = $value;
  93. }
  94. /**
  95. * @return null
  96. */
  97. public function getValue()
  98. {
  99. return $this->value;
  100. }
  101. }