コード例 #1
0
ファイル: Filter.php プロジェクト: imerr/Grids
 /**
  * Applies filtering to data source.
  */
 public function apply()
 {
     $value = $this->getValue();
     if (null === $value || '' === $value) {
         return;
     }
     if ($func = $this->config->getFilteringFunc()) {
         $func($value, $this->grid->getConfig()->getDataProvider());
         return;
     }
     $operator = $this->config->getOperator();
     if ($operator === FilterConfig::OPERATOR_LIKE || $operator === FilterConfig::OPERATOR_LIKE_R) {
         // Search for non-escaped wildcards
         $found = false;
         for ($i = 0; $i < mb_strlen($value); $i++) {
             if (in_array(mb_substr($value, $i, 1), ['%', '_']) && $i > 0 && mb_substr($value, $i - 1, 1) != '\\') {
                 $found = true;
                 break;
             }
         }
         // If none are found, insert wildcards to improve user experience
         if (!$found) {
             if ($operator === FilterConfig::OPERATOR_LIKE) {
                 $value = "%{$value}%";
             } else {
                 if ($operator === FilterConfig::OPERATOR_LIKE_R) {
                     $value .= '%';
                 }
             }
         }
     }
     $this->grid->getConfig()->getDataProvider()->filter($this->config->getName(), $this->config->getOperator(), $value);
 }
コード例 #2
0
ファイル: Filter.php プロジェクト: XaphanBael/Grids
 /**
  * Applies filtering to data source.
  */
 public function apply()
 {
     $value = $this->getValue();
     if (null === $value || '' === $value) {
         return;
     }
     if ($func = $this->config->getFilteringFunc()) {
         $func($value, $this->grid->getConfig()->getDataProvider());
         return;
     }
     $isLike = $this->config->getOperator() === FilterConfig::OPERATOR_LIKE;
     if ($isLike && strpos($value, '%') === false) {
         $value = "%{$value}%";
     }
     $this->grid->getConfig()->getDataProvider()->filter($this->config->getName(), $this->config->getOperator(), $value);
 }