Base.php 832 Bytes
Newer Older
Mark committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?php

namespace yii\debug\models\search;

use yii\base\Model;
use yii\debug\components\search\Filter;
use yii\debug\components\search\matches;

class Base extends Model
{

	/**
	 * @param Filter $filter
	 * @param string $attribute
	 * @param boolean $partial
	 */
	public function addCondition($filter, $attribute, $partial = false)
	{
		$value = $this->$attribute;

		if (mb_strpos($value, '>') !== false) {

			$value = intval(str_replace('>', '', $value));
			$filter->addMatch($attribute, new matches\Greater(['value' => $value]));

		} elseif (mb_strpos($value, '<') !== false) {

			$value = intval(str_replace('<', '', $value));
			$filter->addMatch($attribute, new matches\Lower(['value' => $value]));

		} else {
			$filter->addMatch($attribute, new matches\Exact(['value' => $value, 'partial' => $partial]));
		}

	}

}