/
Composite.class.php
100 lines (88 loc) · 2.67 KB
/
Composite.class.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
<?php
/**
* @package DataTypes
*/
class DataType_Composite extends DataTypePlugin {
protected $isEnabled = true;
protected $dataTypeName = "Composite";
protected $hasHelpDialog = true;
protected $dataTypeFieldGroup = "other";
protected $dataTypeFieldGroupOrder = 20;
protected $jsModules = array("Composite.js");
protected $processOrder = 100;
private $smarty;
public function __construct($runtimeContext) {
parent::__construct($runtimeContext);
if ($runtimeContext == "generation") {
$this->smarty = new SecureSmarty();
$this->smarty->template_dir = realpath(__DIR__ . "/../../../resources/libs/smarty");
$this->smarty->compile_dir = realpath(__DIR__ . "/../../../cache");
}
}
public function generate($generator, $generationContextData) {
$placeholders = array();
foreach ($generationContextData["existingRowData"] as $rowInfo) {
$colNum = $rowInfo["colNum"];
$randomData = is_array($rowInfo["randomData"]) ? $rowInfo["randomData"]["display"] : $rowInfo["randomData"];
$placeholders["ROW{$colNum}"] = $randomData;
}
while (list($key, $value) = each($placeholders)) {
$this->smarty->assign($key, $value);
}
$output = $this->smarty->fetch('string:' . $generationContextData["generationOptions"]);
return array(
"display" => $output
);
}
public function getRowGenerationOptions($generator, $postdata, $col, $num_cols) {
if (!isset($postdata["dtOption_$col"]) || empty($postdata["dtOption_$col"])) {
return false;
}
return $postdata["dtOption_$col"];
}
public function getExampleColumnHTML() {
$L = Core::$language->getCurrentLanguageStrings();
return $L["see_help_dialog"];
}
public function getOptionsColumnHTML() {
return '<textarea name="dtOption_%ROW%" id="dtOption_%ROW%" style="height: 70px; width: 260px"></textarea>';
}
public function getHelpHTML() {
$content =<<< END
<p>
{$this->L["Composite_help_1"]}
</p>
<p>
{$this->L["Composite_help_2"]}
</p>
<p>
{$this->L["Composite_help_3"]}
</p>
<ul>
<li>{$this->L["Composite_help_4"]}</li>
<li>{$this->L["Composite_help_5"]}
<ul>
<li><b>{\$ROW2-\$ROW1}</b> - {$this->L["Composite_subtraction"]}</li>
<li><b>{\$ROW2*\$ROW1}</b> - {$this->L["Composite_multiplication"]}</li>
<li><b>{\$ROW2/\$ROW1}</b> - {$this->L["Composite_division"]}</li>
</ul>
</li>
<li>
{$this->L["Composite_help_6"]}
<b>{if \$ROW1 == 5}{$this->L["Composite_na"]}{else}{\$ROW1}{/if}</b>
</li>
</ul>
<p>
{$this->L["Composite_help_7"]}
</p>
END;
return $content;
}
public function getDataTypeMetadata() {
return array(
"SQLField" => "TEXT default NULL",
"SQLField_Oracle" => "BLOB default NULL",
"SQLField_MSSQL" => "VARCHAR(MAX) NULL"
);
}
}