public function views_php_handler_field::php_post_execute in Views PHP 7
Same name and namespace in other branches
- 6 plugins/views/views_php_handler_field.inc \views_php_handler_field::php_post_execute()
- 7.2 plugins/views/views_php_handler_field.inc \views_php_handler_field::php_post_execute()
See also
views_php_views_post_execute()
File
- plugins/
views/ views_php_handler_field.inc, line 131
Class
- views_php_handler_field
- A handler to provide a field that is constructed by the administrator using PHP.
Code
public function php_post_execute() {
// Execute value PHP code.
if (!empty($this->options['php_value'])) {
$code = $this->options['php_value'] . ';';
$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;
}
$row->{$this->field_alias} = $function($this->view, $this, $this->php_static_variable, $normalized_row, $row);
}
ob_end_clean();
}
// If we're sorting, do the actual sorting then fix the results as per the pager info.
if (!empty($this->options['use_php_click_sortable']) && !empty($this->php_click_sort_order)) {
if ($this->options['use_php_click_sortable'] == self::CLICK_SORT_PHP) {
if (!empty($this->options['php_click_sortable'])) {
$this->php_click_sort_function = TRUE;
}
}
else {
$predefined = array(
self::CLICK_SORT_NUMERIC => array(
$this,
'php_click_sort_numeric',
),
self::CLICK_SORT_ALPHA => 'strcasecmp',
self::CLICK_SORT_ALPHA_CASE => 'strcmp',
self::CLICK_SORT_NAT => 'strnatcasecmp',
self::CLICK_SORT_NAT_CASE => 'strnatcmp',
);
$this->php_click_sort_function = $predefined[$this->options['use_php_click_sortable']];
}
if (isset($this->php_click_sort_function)) {
usort($this->view->result, array(
$this,
'php_click_sort',
));
}
}
}