93 private $_filterIncrement = 0;
102 private $_filterBrackets = [];
111 private $_filterEvalRendered =
'';
136 $this->_allowedDirsMask = (string)$regex;
149 $this->_allowedFilesMask = (string)$regex;
162 $this->_disallowedFilesMask = (string)$regex;
174 $this->_collectDirs = (bool)
$value;
186 $this->_collectFiles = (bool)
$value;
198 $this->_collectRecursively = (bool)
$value;
213 throw new \Exception(
'Unable to set target directory.');
228 $this->_dirsFirst = (bool)
$value;
242 $collectedResult = [];
243 if (!is_array($dir)) {
246 foreach ($dir as $folder) {
247 if ($nodes = glob($folder .
'/*', GLOB_NOSORT)) {
248 foreach ($nodes as $node) {
249 $collectedResult[] = $node;
253 if (empty($collectedResult)) {
257 foreach ($collectedResult as
$item) {
258 if (
is_dir(
$item) && (!$this->_allowedDirsMask || preg_match($this->_allowedDirsMask, basename(
$item)))) {
259 if ($this->_collectDirs) {
260 if ($this->_dirsFirst) {
261 $this->_collectedDirs[] =
$item;
263 $this->_collectedFiles[] =
$item;
266 if ($this->_collectRecursively) {
271 ) && (!$this->_allowedFilesMask || preg_match(
272 $this->_allowedFilesMask,
274 )) && (!$this->_disallowedFilesMask || !preg_match(
275 $this->_disallowedFilesMask,
279 $this->_collectedFiles[] =
$item;
293 public function loadData($printQuery =
false, $logQuery =
false)
298 if (empty($this->_targetDirs)) {
299 throw new \Exception(
'Please specify at least one target directory.');
302 $this->_collectedFiles = [];
303 $this->_collectedDirs = [];
305 $this->_generateAndFilterAndSort(
'_collectedFiles');
306 if ($this->_dirsFirst) {
307 $this->_generateAndFilterAndSort(
'_collectedDirs');
308 $this->_collectedFiles = array_merge($this->_collectedDirs, $this->_collectedFiles);
312 $this->_totalRecords =
count($this->_collectedFiles);
321 foreach ($this->_collectedFiles as
$row) {
323 if ($isPaginated && ($cnt < $from || $cnt > $to)) {
326 $item =
new $this->_itemObjectClass();
328 if (!
$item->hasId()) {
345 private function _generateAndFilterAndSort($attributeName)
348 foreach ($this->{$attributeName} as $key => $filename) {
349 $this->{$attributeName}[$key] = $this->
_generateRow($filename);
353 if (!empty($this->_filters)) {
354 foreach ($this->{$attributeName} as $key =>
$row) {
356 unset($this->{$attributeName}[$key]);
362 if (!empty($this->_orders)) {
363 usort($this->{$attributeName}, [$this,
'_usort']);
377 foreach ($this->_orders as $key => $direction) {
378 $result = $a[$key] > $b[$key] ? 1 : ($a[$key] < $b[$key] ? -1 : 0);
379 return self::SORT_ORDER_ASC === strtoupper($direction) ?
$result : -
$result;
392 public function setOrder($field, $direction = self::SORT_ORDER_DESC)
394 $this->_orders = [$field => $direction];
406 return [
'filename' => $filename,
'basename' => basename($filename)];
425 $this->_filters[$this->_filterIncrement] = [
428 'is_and' =>
'and' ===
$type,
429 'callback' => $callback,
430 'is_inverted' => $isInverted,
432 $this->_filterIncrement++;
448 if (!$this->_isFiltersRendered) {
450 for (
$i = 0;
$i < $this->_filterIncrement;
$i++) {
451 if (isset($this->_filterBrackets[
$i])) {
454 $this->_filterBrackets[
$i][
'is_and']
455 ) . $this->_filterBrackets[
$i][
'value'];
457 $f =
'$this->_filters[' .
$i .
']';
460 $this->_filters[
$i][
'is_and']
462 ($this->_filters[
$i][
'is_inverted'] ?
'!' :
'') .
463 '$this->_invokeFilter(' .
464 "{$f}['callback'], array({$f}['field'], {$f}['value'], " .
468 $this->_filterEvalRendered = $eval;
469 $this->_isFiltersRendered =
true;
472 if ($this->_filterEvalRendered) {
473 eval(
'$result = ' . $this->_filterEvalRendered .
';');
490 if (!array_key_exists($field,
$row)) {
493 return call_user_func_array($callback, $callbackParams);
513 if (!is_array($cond)) {
518 if (isset($cond[
'from']) || isset($cond[
'to'])) {
520 if (isset($cond[
'from'])) {
525 [$this,
'filterCallbackIsLessThan'],
529 if (isset($cond[
'to'])) {
534 [$this,
'filterCallbackIsMoreThan'],
540 if (isset($cond[
'eq'])) {
543 if (isset($cond[
'neq'])) {
546 if (isset($cond[
'like'])) {
549 if (isset($cond[
'nlike'])) {
554 [$this,
'filterCallbackLike'],
558 if (isset($cond[
'in'])) {
561 if (isset($cond[
'nin'])) {
566 [$this,
'filterCallbackInArray'],
570 if (isset($cond[
'notnull'])) {
575 [$this,
'filterCallbackIsNull'],
579 if (isset($cond[
'null'])) {
582 if (isset($cond[
'moreq'])) {
587 [$this,
'filterCallbackIsLessThan'],
591 if (isset($cond[
'gt'])) {
594 if (isset($cond[
'lt'])) {
597 if (isset($cond[
'gteq'])) {
602 [$this,
'filterCallbackIsLessThan'],
606 if (isset($cond[
'lteq'])) {
611 [$this,
'filterCallbackIsMoreThan'],
615 if (isset($cond[
'finset'])) {
616 $filterValue = $cond[
'finset'] ? explode(
',', $cond[
'finset']) : [];
621 foreach ($cond as $orCond) {
638 $this->_filterBrackets[$this->_filterIncrement] = [
639 'value' => $bracket ===
')' ?
')' :
'(',
642 $this->_filterIncrement++;
655 if (isset($this->_filterBrackets[$increment]) &&
')' === $this->_filterBrackets[$increment][
'value']) {
658 $prevIncrement = $increment - 1;
659 $prevBracket =
false;
660 if (isset($this->_filterBrackets[$prevIncrement])) {
661 $prevBracket = $this->_filterBrackets[$prevIncrement][
'value'];
663 if ($prevIncrement < 0 || $prevBracket ===
'(') {
666 return $isAnd ?
' && ' :
' || ';
689 return array_keys($this->_items);
704 $filterValue = trim(stripslashes($filterValue),
'\'');
705 $filterValue = trim($filterValue,
'%');
706 $filterValueRegex =
'(.*?)' . preg_quote($filterValue,
'/') .
'(.*?)';
708 return (
bool)preg_match(
"/^{$filterValueRegex}\$/i",
$row[$field]);
723 return $filterValue ==
$row[$field];
738 return in_array(
$row[$field], $filterValue);
754 return null ===
$row[$field];
769 return $row[$field] > $filterValue;
784 return $row[$field] < $filterValue;
filterCallbackInArray($field, $filterValue, $row)
elseif(isset( $params[ 'redirect_parent']))
loadData($printQuery=false, $logQuery=false)
filterCallbackIsNull($field, $filterValue, $row)
_addFilterBracket($bracket='(', $isAnd=true)
addCallbackFilter($field, $value, $type, $callback, $isInverted=false)
setCollectRecursively($value)
_invokeFilter($callback, $callbackParams)
addFilter($field, $value, $type='and')
setOrder($field, $direction=self::SORT_ORDER_DESC)
setDisallowedFilesFilter($regex)
filterCallbackIsMoreThan($field, $filterValue, $row)
filterCallbackEq($field, $filterValue, $row)
_renderConditionBeforeFilterElement($increment, $isAnd)
addFieldToFilter($field, $cond, $type='and')
filterCallbackLike($field, $filterValue, $row)
filterCallbackIsLessThan($field, $filterValue, $row)
addItem(\Magento\Framework\DataObject $item)
getCurPage($displacement=0)