You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\debug\models\search;
  8. use yii\base\Model;
  9. use yii\debug\components\search\Filter;
  10. use yii\debug\components\search\matchers;
  11. /**
  12. * Base search model
  13. *
  14. * @author Mark Jebri <mark.github@yandex.ru>
  15. * @since 2.0
  16. */
  17. class Base extends Model
  18. {
  19. /**
  20. * Adds filtering condition for a given attribute
  21. *
  22. * @param Filter $filter filter instance
  23. * @param string $attribute attribute to filter
  24. * @param boolean $partial if partial match should be used
  25. */
  26. public function addCondition(Filter $filter, $attribute, $partial = false)
  27. {
  28. $value = $this->$attribute;
  29. if (mb_strpos($value, '>') !== false) {
  30. $value = intval(str_replace('>', '', $value));
  31. $filter->addMatcher($attribute, new matchers\GreaterThan(['value' => $value]));
  32. } elseif (mb_strpos($value, '<') !== false) {
  33. $value = intval(str_replace('<', '', $value));
  34. $filter->addMatcher($attribute, new matchers\LowerThan(['value' => $value]));
  35. } else {
  36. $filter->addMatcher($attribute, new matchers\SameAs(['value' => $value, 'partial' => $partial]));
  37. }
  38. }
  39. }