forked from nalarfag/GWU_Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGWUAction.php
112 lines (80 loc) · 4.47 KB
/
GWUAction.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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include_once dirname(__FILE__) . '/models/GWAction.php';
include_once dirname(__FILE__) . '/models/GWQuestion.php';
include_once dirname(__FILE__) . '/models/GWQuestionnaire.php';
include_once dirname(__FILE__) . '/models/GWAnswerChoice.php';
include_once dirname(__FILE__) . '/models/GWWrapper.php';
if (!defined('GWU_BUILDER_DIR'))
define('GWU_BUILDER_DIR', WP_PLUGIN_DIR . '\\' . GWU_Builder);
use WordPress\ORM\Model\GWWrapper;
if (!class_exists('GWUAction')) {
class GWUAction {
public function saveAction() {
//$ActionID;
$QuestSequence = ( isset($_POST['QuestionSeq']) ? $_POST['QuestionSeq'] : '' );
$QuestionnaireID = ( isset($_POST['QuestionnaireID']) ? $_POST['QuestionnaireID'] : '' );
$ActionType = ( isset($_POST['ActionType']) ? $_POST['ActionType'] : NULL );
$LinkToAction= ( isset($_POST['LinkToAction']) ? $_POST['LinkToAction'] : NULL );
$Duration = ( isset($_POST['Duration']) ? $_POST['Duration'] : NULL );
$Sequence = ( isset($_POST['Sequence']) ? $_POST['Sequence'] : NULL );
$Content = ( isset($_POST['Content']) ? $_POST['Content'] : NULL );
$Deleted = ( isset($_POST['Deleted']) ? $_POST['Deleted'] : 'false' );
$Wrapper = new GWWrapper();
if($LinkToAction != '') {
if(isset($_POST['ActionID'])) {
$action = $Wrapper->getActions(intval($_POST['ActionID']))[0];
$action->set_ActionType($ActionType);
$action->set_LinkToAction($LinkToAction);
$action->set_Duration($Duration);
$action->set_Sequence($Sequence);
$action->set_Content($Content);
$action->set_Deleted($Deleted);
$action->update();
} else {
$ActionID = $Wrapper->saveAction($QuestSequence, $QuestionnaireID, $ActionType, $LinkToAction, $Duration, $Sequence, $Content, $Deleted);
$question = $Wrapper->getQuestion($QuestSequence, $QuestionnaireID)[0];
$question->set_ActionID(intval($ActionID['ActionID']));
$question->update();
}
}
echo json_encode(array('success' => true, 'result' => $ActionID));
die();
}
public function getActions() {
$QuestionnaireID = $_POST['QuestionnaireID'];
$QuestSequence = $_POST['QuestSequence'];
$Wrapper = new GWWrapper();
$actions = $Wrapper->listActions($QuestionnaireID, $QuestSequence);
echo json_encode(array('success' => true, 'result' => $actions));
die();
}
public function doneAction() {
$QuestionnaireID = ( isset($_POST['QuestionnaireID']) ? $_POST['QuestionnaireID'] : '' );
wp_redirect(add_query_arg(array('page' => 'GWU_add-Questionnaire-page',
'id' => 'view', 'Qid' => $QuestionnaireID
), admin_url('admin.php')));
}
public function removeAction() {
//file_put_contents("/tmp/log.txt", 'Inside removeActionFunction', FILE_APPEND);
$Wrapper = new GWWrapper();
$ActionID = ( isset($_POST['ActionID']) ? $_POST['ActionID'] : '' );
$actions = $Wrapper->getActions(intval($ActionID));
//$action = new GWAction();
$action = $actions[0];
//file_put_contents("/var/www/html/wordpress/wp-content/plugins/GWU_Builder/models/log.txt", $action->get_ActionID(), FILE_APPEND);
//$result = $action->delete();
//$action = $Wrapper->getActions(7)[0];
//file_put_contents("/var/www/html/wordpress/wp-content/plugins/GWU_Builder/models/log.txt", $action->get_ActionID(), FILE_APPEND);
//var_dump($action);
$action->delete();
echo json_encode(array('success' => true));
die();
}
}
}
?>