You are here

public function ExportData::find in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php \AKlump\LoftDataGrids\ExportData::find()

Find a value in the dataset of the current page

Parameters

mixed $value:

mixed $key: (Optional) Defaults to NULL. Set this to constrain the search by key.

int $results: (Optional) Defaults to 1. The number of results to return. Enter 0 for no limit.

int $direction: (Optional) Defaults to 0. 0 to search from beginning, 1 to search backward from end.

Return value

array

  • Keys are the pointers.
  • Values are an array of fields in the current pointer

Overrides ExportDataInterface::find

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php, line 383

Class

ExportData

Namespace

AKlump\LoftDataGrids

Code

public function find($needle, $key = NULL, $results = 1, $direction = 0) {
  $result_set = array();
  $haystack = $this
    ->getPage($this->current_page);
  if ($direction == 1) {
    $haystack = array_reverse($haystack, TRUE);
  }
  foreach ($haystack as $pointer => $row) {
    $set = $row;
    if ($key !== NULL) {
      $set = array(
        $key => $row[$key],
      );
    }
    if ($found = array_intersect($set, array(
      $needle,
    ))) {
      $result_set[$pointer] = $found;
    }
    if ($results && count($result_set) === $results) {
      break;
    }
  }
  return $result_set;
}