class.float.wpdatacolumn.php
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
defined('ABSPATH') or die('Access denied.');
class FloatWDTColumn extends WDTColumn {
protected $_jsDataType = 'formatted-num';
protected $_dataType = 'float';
/**
* FloatWDTColumn constructor.
* @param array $properties
*/
public function __construct($properties = array()) {
parent::__construct($properties);
$this->_dataType = 'float';
$this->_filterType = 'number';
$this->addCSSClass('numdata float');
$this->setDecimalPlaces(WDTTools::defineDefaultValue($properties, 'decimalPlaces', -1));
}
/**
* @param $content
* @return mixed|string
*/
public function prepareCellOutput($content) {
if ($content === '' || $content === null) {
$content = '';
return $content;
}
$numberFormat = get_option('wdtNumberFormat') ? get_option('wdtNumberFormat') : 1;
$decimalPlaces = $this->getDecimalPlaces() != -1 ? $this->getDecimalPlaces() : get_option('wdtDecimalPlaces');
if ($numberFormat == 1) {
$formattedValue = number_format(
(float)$content,
$decimalPlaces,
',',
'.'
);
} else {
$formattedValue = number_format(
(float)$content,
$decimalPlaces
);
}
$formattedValue = apply_filters('wpdatatables_filter_float_cell', $formattedValue, $this->getParentTable()->getWpId());
return $formattedValue;
}
/**
* @return string
*/
public function getGoogleChartColumnType() {
return 'number';
}
}