-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetJSON.php
More file actions
129 lines (97 loc) · 3.48 KB
/
getJSON.php
File metadata and controls
129 lines (97 loc) · 3.48 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
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
126
127
128
<?php
include 'connect.php';
include 'menu.html';
//$group=$_GET['group'];
function splitStringToArray($inputString) {
$stringArray = explode(',', $inputString);
$stringArray = array_map('trim', $stringArray);
return $stringArray;
}
function isStringNotEmpty($inputString) {
$trimmedString = trim($inputString);
if (!empty($trimmedString)) {
return $inputString;
} else {
return false;
}
}
$querry = "SELECT question.row_counter, question.name, question.title, question.type, choice.question_name, choice.choice_name ,question.visible_if, question.is_required , question.show_other" . " FROM question, choice " . " WHERE choice.question_name = question.name ";
$result = $conn->query($querry);
if ($result) {
$surveyData = array(
"title" => "(CFO)",
"description" => "Description",
"logoPosition" => "right",
"pages" => array()
);
$currentPageName = "";
$currentElements = array();
$nameCounter=0;
while ($query_row = $result->fetch_assoc()) {
$nameCounter ++;
$name = $query_row['name'];
$type = $query_row['type'];
$show_other = $query_row['show_other'];
$visible_if = $query_row['visible_if'];
$is_required = $query_row['is_required'];
if(($type == "text")||($type == "boolean")){
$questionName = $query_row['question_name'];
$choice = $query_row['choice_name'];
$arrayOfStrings = splitStringToArray($choice);
$choices = $arrayOfStrings;
if ($currentPageName != $name) {
if (!empty($currentElements)) {
$surveyData["pages"][] = array(
"name" => $currentPageName,
"elements" => $currentElements
);
}
$currentPageName = $name.$nameCounter;
$currentElements = array();
}
$currentElements[] = array(
"type" => $type,
"name" => $questionName,
"title" => $name,
"isRequired" => isStringNotEmpty($is_required),
"visibleIf"=> isStringNotEmpty($visible_if),
//"showOtherItem" => false
// "choices" => $choices
);
}else{
$questionName = $query_row['question_name'];
$choice = $query_row['choice_name'];
$arrayOfStrings = splitStringToArray($choice);
$choices = $arrayOfStrings;
if ($currentPageName != $name) {
if (!empty($currentElements)) {
$surveyData["pages"][] = array(
"name" => $currentPageName,
"elements" => $currentElements
);
}
$currentPageName = $name.$nameCounter;
$currentElements = array();
}
$currentElements[] = array(
"type" => $type,
"name" => $questionName,
"title" => $name,
"isRequired" => isStringNotEmpty($is_required),
"visibleIf"=> isStringNotEmpty($visible_if),
"showOtherItem" => isStringNotEmpty( $show_other ) ,
"choices" => $choices
);
}
}
if (!empty($currentElements)) {
$surveyData["pages"][] = array(
"name" => $currentPageName,
"elements" => $currentElements
);
}
$jsonString = json_encode($surveyData, JSON_PRETTY_PRINT);
echo $jsonString;
}
echo mysqli_error($conn);
?>