private function doInternalSearch(Collection $columns, array $searchColumns)
{
if ((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches)) {
return;
}
$value = $this->search;
$caseSensitive = $this->options['caseSensitive'];
$toSearch = array();
$searchType = self::AND_CONDITION;
// Map the searchColumns to the real columns
$ii = 0;
foreach ($columns as $i => $col) {
if (in_array($columns->get($i)->getName(), $searchColumns) || in_array($columns->get($i)->getName(), $this->fieldSearches)) {
// map values to columns, where there is no value use the global value
if (($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE) {
$toSearch[$ii] = $this->columnSearches[$field];
} else {
if ($value) {
$searchType = self::OR_CONDITION;
}
$toSearch[$ii] = $value;
}
}
$ii++;
}
$self = $this;
$this->workingCollection = $this->workingCollection->filter(function ($row) use($toSearch, $caseSensitive, $self, $searchType) {
for ($i = 0, $stack = array(), $nb = count($row); $i < $nb; $i++) {
if (!array_key_exists($i, $toSearch)) {
continue;
}
$column = $i;
if ($self->getAliasMapping()) {
$column = $self->getNameByIndex($i);
}
if ($self->getOption('stripSearch')) {
$search = strip_tags($row[$column]);
} else {
$search = $row[$column];
}
if ($caseSensitive) {
if ($self->exactWordSearch) {
if ($toSearch[$i] === $search) {
$stack[$i] = true;
}
} else {
if (str_contains($search, $toSearch[$i])) {
$stack[$i] = true;
}
}
} else {
if ($self->getExactWordSearch()) {
if (mb_strtolower($toSearch[$i]) === mb_strtolower($search)) {
$stack[$i] = true;
}
} else {
if (str_contains(mb_strtolower($search), mb_strtolower($toSearch[$i]))) {
$stack[$i] = true;
}
}
}
}
if ($searchType == $self::AND_CONDITION) {
$result = array_diff_key(array_filter($toSearch), $stack);
if (empty($result)) {
return true;
}
} else {
if (!empty($stack)) {
return true;
}
}
});
}