danielebarchiesi@0: ''); danielebarchiesi@0: danielebarchiesi@0: return $options; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function options_form(&$form, &$form_state) { danielebarchiesi@0: $form['expression'] = array( danielebarchiesi@0: '#type' => 'textarea', danielebarchiesi@0: '#title' => t('Expression'), danielebarchiesi@0: '#description' => t('Enter mathematical expressions such as 2 + 2 or sqrt(5). You may assign variables and create mathematical functions and evaluate them. Use the ; to separate these. For example: f(x) = x + 2; f(2).'), danielebarchiesi@0: '#default_value' => $this->options['expression'], danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Create a place for the help danielebarchiesi@0: $form['expression_help'] = array(); danielebarchiesi@0: parent::options_form($form, $form_state); danielebarchiesi@0: danielebarchiesi@0: // Then move the existing help: danielebarchiesi@0: $form['expression_help'] = $form['alter']['help']; danielebarchiesi@0: unset($form['expression_help']['#dependency']); danielebarchiesi@0: unset($form['alter']['help']); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function render($values) { danielebarchiesi@0: ctools_include('math-expr'); danielebarchiesi@0: $tokens = array_map('floatval', $this->get_render_tokens(array())); danielebarchiesi@0: $value = strtr($this->options['expression'], $tokens); danielebarchiesi@0: $expressions = explode(';', $value); danielebarchiesi@0: $math = new ctools_math_expr; danielebarchiesi@0: foreach ($expressions as $expression) { danielebarchiesi@0: if ($expression !== '') { danielebarchiesi@0: $value = $math->evaluate($expression); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // The rest is directly from views_handler_field_numeric but because it danielebarchiesi@0: // does not allow the value to be passed in, it is copied. danielebarchiesi@0: if (!empty($this->options['set_precision'])) { danielebarchiesi@0: $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']); danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $remainder = abs($value) - intval(abs($value)); danielebarchiesi@0: $value = $value > 0 ? floor($value) : ceil($value); danielebarchiesi@0: $value = number_format($value, 0, '', $this->options['separator']); danielebarchiesi@0: if ($remainder) { danielebarchiesi@0: // The substr may not be locale safe. danielebarchiesi@0: $value .= $this->options['decimal'] . substr($remainder, 2); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Check to see if hiding should happen before adding prefix and suffix. danielebarchiesi@0: if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) { danielebarchiesi@0: return ''; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Should we format as a plural. danielebarchiesi@0: if (!empty($this->options['format_plural']) && ($value != 0 || !$this->options['empty_zero'])) { danielebarchiesi@0: $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $this->sanitize_value($this->options['prefix'] . $value . $this->options['suffix']); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function query() { } danielebarchiesi@0: }