-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.comparedetail.wpdatacolumn.php
executable file
·125 lines (107 loc) · 4.48 KB
/
class.comparedetail.wpdatacolumn.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
defined('ABSPATH') or die("Cannot access pages directly.");
class CompareDetailWDTColumn extends WDTColumn
{
protected $_jsDataType = 'comparedetail';
protected $_dataType = 'comparedetail';
protected $_linkButtonAttribute = 0;
protected $_linkButtonLabel = '';
protected $_linkButtonClass = '';
/**
* CompareDetailWDTColumn constructor.
* @param array $properties
*/
public function __construct($properties = array())
{
parent::__construct($properties);
$this->_dataType = 'comparedetail';
$this->setLinkButtonAttribute(WDTTools::defineDefaultValue($properties, 'linkButtonAttribute', 0));
$this->setLinkButtonLabel(WDTTools::defineDefaultValue($properties, 'linkButtonLabel', ''));
$this->setLinkButtonClass(WDTTools::defineDefaultValue($properties, 'linkButtonClass', ''));
}
/**
* @param $content
* @return mixed|string
* @throws Exception
*/
public function prepareCellOutput($content)
{
$buttonClass = $this->getLinkButtonClass();
$tableSettings = WDTConfigController::loadTableFromDB($this->getParentTable()->getWpID());
$advancedSettings = json_decode($tableSettings->advanced_settings);
$compareDetailRenderPage = $advancedSettings->compareDetailRenderPage;
$compareDetailRenderPost = $advancedSettings->compareDetailRenderPost;
$compareDetailRender = $advancedSettings->compareDetailRender;
$formattedValue = '';
if ($this->getLinkButtonAttribute() == 1 && $content !== '') {
$buttonLabel = $this->getLinkButtonLabel() !== '' ? $this->getLinkButtonLabel() : $content;
if ($compareDetailRender == 'popup'){
$formattedValue = "<a class='compare_detail_column_btn'><button class='{$buttonClass}'>{$buttonLabel}</button></a>";
} else if ($compareDetailRender == 'wdtNewPage' || $compareDetailRender == 'wdtNewPost'){
$renderAction = $compareDetailRender == 'wdtNewPage' ? $compareDetailRenderPage : $compareDetailRenderPost;
$formattedValue = "<form class='wdt_cd_form' method='post' target='_blank' action='{$renderAction}'>
<input class='wdt_cd_hidden_data' type='hidden' name='wdt_details_data' value=''>
<input class='compare_detail_column_btn {$buttonClass}' type='submit' value='{$buttonLabel}'>
</form>";
}
} else {
if ($content == '') {
return null;
} else {
if ($compareDetailRender == 'popup'){
$formattedValue = "<a class='compare_detail_column_btn'>{$content}</a>";
} else if ($compareDetailRender == 'wdtNewPage' || $compareDetailRender == 'wdtNewPost'){
$renderAction = $compareDetailRender == 'wdtNewPage' ? $compareDetailRenderPage : $compareDetailRenderPost;
$formattedValue = "<form class='wdt_cd_form' method='post' target='_blank' action='{$renderAction}'>
<input class='wdt_cd_hidden_data' type='hidden' name='wdt_details_data' value=''>
<input class='compare_detail_column_btn cd-link' type='submit' value='{$content}'>
</form>";
}
}
}
$formattedValue = apply_filters('wpdatatables_filter_details_cell', $formattedValue, $this->getParentTable()->getWpId());
return $formattedValue;
}
/**
* @return int
*/
public function getLinkButtonAttribute()
{
return $this->_linkButtonAttribute;
}
/**
* @param int $linkButtonAttribute
*/
public function setLinkButtonAttribute($linkButtonAttribute)
{
$this->_linkButtonAttribute = $linkButtonAttribute;
}
/**
* @return string
*/
public function getLinkButtonLabel()
{
return $this->_linkButtonLabel;
}
/**
* @param string $linkButtonLabel
*/
public function setLinkButtonLabel($linkButtonLabel)
{
$this->_linkButtonLabel = $linkButtonLabel;
}
/**
* @return string
*/
public function getLinkButtonClass()
{
return $this->_linkButtonClass;
}
/**
* @param string $linkButtonClass
*/
public function setLinkButtonClass($linkButtonClass)
{
$this->_linkButtonClass = $linkButtonClass;
}
}