mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
44 lines
915 B
PHP
44 lines
915 B
PHP
<?php namespace Backend\Traits;
|
|
|
|
use Str;
|
|
|
|
/**
|
|
* Searchable Widget Trait
|
|
* Adds search features to back-end widgets
|
|
*
|
|
* @package winter\wn-backend-module
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
*/
|
|
|
|
trait SearchableWidget
|
|
{
|
|
protected $searchTerm = false;
|
|
|
|
protected function getSearchTerm()
|
|
{
|
|
return $this->searchTerm !== false ? $this->searchTerm : $this->getSession('search');
|
|
}
|
|
|
|
protected function setSearchTerm($term)
|
|
{
|
|
$this->searchTerm = trim($term);
|
|
$this->putSession('search', $this->searchTerm);
|
|
}
|
|
|
|
protected function textMatchesSearch(&$words, $text)
|
|
{
|
|
foreach ($words as $word) {
|
|
$word = trim($word);
|
|
if (!strlen($word)) {
|
|
continue;
|
|
}
|
|
|
|
if (Str::contains(Str::lower($text), $word)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|