You are here

public function views_php_handler_filter::php_post_execute in Views PHP 7

Same name and namespace in other branches
  1. 6 plugins/views/views_php_handler_filter.inc \views_php_handler_filter::php_post_execute()

See also

views_php_views_post_execute()

File

plugins/views/views_php_handler_filter.inc, line 84

Class

views_php_handler_filter
A handler to filter a view using PHP defined by the administrator.

Code

public function php_post_execute() {

  // Evaluate the PHP code.
  if (!empty($this->options['php_filter'])) {
    $code = $this->options['php_filter'] . ';';
    $function = function ($view, $handler, &$static, $row, $data) use ($code) {
      return eval($code);
    };
    ob_start();
    foreach ($this->view->result as $i => $row) {
      $normalized_row = new stdClass();
      foreach ($this->view->display_handler
        ->get_handlers('field') as $field => $handler) {
        $normalized_row->{$field} = isset($row->{$handler->field_alias}) ? $row->{$handler->field_alias} : NULL;
      }
      if ($function($this->view, $this, $this->php_static_variable, $normalized_row, $row)) {
        unset($this->view->result[$i]);
      }
    }
    ob_end_clean();
  }
}