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