class similar_handler_field_similarity in Similar Entries 6.2
Same name and namespace in other branches
- 7.2 views/similar_handler_field_similarity.inc \similar_handler_field_similarity
Similarity score field handler.
Hierarchy
- class \similar_handler_field_similarity extends \views_handler_field
Expanded class hierarchy of similar_handler_field_similarity
1 string reference to 'similar_handler_field_similarity'
- similar_views_data in views/
similar.views.inc - Implements hook_views_data().
File
- views/
similar_handler_field_similarity.inc, line 11 - Provides a field for displaying the similarity score of similar entries.
View source
class similar_handler_field_similarity extends views_handler_field {
/**
* Defines default values for field options.
*/
function option_definition() {
$options = parent::option_definition();
$options['score_type'] = array(
'default' => 1,
);
$options['round_decimal'] = array(
'default' => 0,
);
$options['percent_suffix'] = array(
'default' => 1,
);
$options['multiply_score'] = array(
'default' => 1,
);
return $options;
}
/**
* Provides options form for setting field as number or percentage.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['score_type'] = array(
'#type' => 'radios',
'#title' => t('Display type'),
'#default_value' => $this->options['score_type'],
'#options' => array(
0 => t('Show similarity score'),
1 => t('Show as percentage'),
),
);
$form['round_decimal'] = array(
'#type' => 'select',
'#title' => t('Round to nearest'),
'#default_value' => $this->options['round_decimal'],
'#options' => array(
0 => t('Whole number') . ' (1)',
1 => '10th (1.0)',
2 => '100th (1.00)',
3 => '1,000th (1.000)',
4 => '10,000th (1.0000)',
),
);
$form['percent_suffix'] = array(
'#type' => 'checkbox',
'#title' => t('Append % when showing percentage'),
'#default_value' => !empty($this->options['percent_suffix']),
);
$score_options = array(
'0.1' => '0.1',
'0.2' => '0.2',
'0.3' => '0.3',
'0.4' => '0.4',
'0.5' => '0.5',
'0.6' => '0.6',
'0.7' => '0.7',
'0.8' => '0.8',
'0.9' => '0.9',
);
for ($i = 1; $i < 101; $i++) {
$score_options[$i] = $i;
}
$form['multiply_score'] = array(
'#type' => 'select',
'#title' => t('Multiply score by'),
'#options' => $score_options,
'#default_value' => $this->options['multiply_score'],
);
}
function query() {
}
/**
* Renders the field as a number or percentage.
*/
function render($values) {
$output = round($values->score * $this->options['multiply_score'], $this->options['round_decimal']);
if ($this->options['score_type'] == 0) {
return $output;
}
else {
if (!empty($this->options['percent_suffix'])) {
$output .= '%';
}
return $output;
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
similar_handler_field_similarity:: |
function | Provides options form for setting field as number or percentage. | ||
similar_handler_field_similarity:: |
function | Defines default values for field options. | ||
similar_handler_field_similarity:: |
function | |||
similar_handler_field_similarity:: |
function | Renders the field as a number or percentage. |