public function views_php_handler_sort::php_sort in Views PHP 7
Same name and namespace in other branches
- 6 plugins/views/views_php_handler_sort.inc \views_php_handler_sort::php_sort()
- 7.2 plugins/views/views_php_handler_sort.inc \views_php_handler_sort::php_sort()
Helper function; usort() callback for sort support.
File
- plugins/
views/ views_php_handler_sort.inc, line 85
Class
- views_php_handler_sort
- A handler to sort a view using PHP defined by the administrator.
Code
public function php_sort($row1, $row2) {
$factor = strtoupper($this->options['order']) == 'ASC' ? 1 : -1;
$code = $this->options['php_sort'] . ';';
$function = function ($view, $handler, &$static, $row1, $row2) use ($code) {
return eval($code);
};
foreach (array(
'row1' => 'normalized_row1',
'row2' => 'normalized_row2',
) as $name => $normalized_name) {
${$normalized_name} = new stdClass();
foreach ($this->view->display_handler
->get_handlers('field') as $field => $handler) {
${$normalized_name}->{$field} = isset(${$name}->{$handler->field_alias}) ? ${$name}->{$handler->field_alias} : NULL;
}
}
$result = (int) $function($this->view, $this, $this->php_static_variable, $normalized_row1, $normalized_row2);
return $factor * $result;
}