PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
V3.3.2 3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 All 139 releases
← All changes | includes/Core/Messages/EmailTemplateHandler.php +109 -109 1.9 → 2.15.3 View file →
@@ -5,125 +5,125 @@
5 5 use BitCode\BitForm\Core\Database\EmailTemplateModel;
6 6
7 7 final class EmailTemplateHandler
8 8 {
9 - private static $_formID;
10 - private static $_emailTemplateModel;
11 - private $_user_details;
9 + private static $_formID;
10 + private static $_emailTemplateModel;
11 + private $_user_details;
12 12
13 - public function __construct($formID, array $user_details = null)
14 - {
15 - static::$_formID = $formID;
16 - static::$_emailTemplateModel = new EmailTemplateModel();
17 - $this->_user_details = $user_details;
13 + public function __construct($formID, array $user_details = null)
14 + {
15 + static::$_formID = $formID;
16 + static::$_emailTemplateModel = new EmailTemplateModel();
17 + $this->_user_details = $user_details;
18 + }
19 +
20 + public function getAllTemplate($templateID = null, $userID = null)
21 + {
22 + $condition = [
23 + 'form_id' => static::$_formID,
24 + ];
25 + if (!is_null($templateID)) {
26 + $condition = array_merge($condition, ['id' => $templateID]);
18 27 }
28 + if (!is_null($userID)) {
29 + $condition = array_merge($condition, ['user_id' => $userID]);
30 + }
31 + return static::$_emailTemplateModel->get(
32 + [
33 + 'id',
34 + 'title',
35 + 'sub',
36 + 'body'
37 + ],
38 + $condition
39 + );
40 + }
19 41
20 - public function getAllTemplate($templateID = null, $userID = null)
21 - {
22 - $condition = array(
23 - 'form_id' => static::$_formID,
24 - );
25 - if (!is_null($templateID)) {
26 - $condition = array_merge($condition, array('id' => $templateID));
27 - }
28 - if (!is_null($userID)) {
29 - $condition = array_merge($condition, array('user_id' => $userID));
30 - }
31 - return static::$_emailTemplateModel->get(
32 - array(
33 - 'id',
34 - 'title',
35 - 'sub',
36 - 'body'
37 - ),
38 - $condition
39 - );
40 - }
42 + public function getATemplate($templateID)
43 + {
44 + return $this->getAllTemplate($templateID);
45 + }
41 46
42 - public function getATemplate($templateID)
43 - {
44 - return $this->getAllTemplate($templateID);
45 - }
47 + public function saveTemplate($templateDetail)
48 + {
49 + return static::$_emailTemplateModel->insert(
50 + [
51 + 'title' => $templateDetail->title,
52 + 'sub' => $templateDetail->sub,
53 + 'body' => $templateDetail->body,
54 + 'form_id' => static::$_formID,
55 + 'user_id' => $this->_user_details['id'],
56 + 'user_ip' => $this->_user_details['ip'],
57 + 'created_at'=> $this->_user_details['time'],
58 + 'updated_at'=> $this->_user_details['time']
59 + ]
60 + );
61 + }
46 62
47 - public function saveTemplate($templateDetail)
48 - {
49 - return static::$_emailTemplateModel->insert(
50 - array(
51 - "title"=> $templateDetail->title,
52 - "sub"=> $templateDetail->sub,
53 - "body"=> $templateDetail->body,
54 - "form_id"=> static::$_formID,
55 - "user_id"=> $this->_user_details['id'],
56 - "user_ip"=>$this->_user_details['ip'],
57 - "created_at"=> $this->_user_details['time'],
58 - "updated_at"=> $this->_user_details['time']
59 - )
60 - );
61 - }
63 + public function updateTemplate($templateDetail)
64 + {
65 + return static::$_emailTemplateModel->update(
66 + [
67 + 'title' => $templateDetail->title,
68 + 'sub' => $templateDetail->sub,
69 + 'body' => $templateDetail->body,
70 + 'form_id' => static::$_formID,
71 + 'user_id' => $this->_user_details['id'],
72 + 'user_ip' => $this->_user_details['ip'],
73 + 'updated_at'=> $this->_user_details['time']
74 + ],
75 + [
76 + 'id' => $templateDetail->id
77 + ]
78 + );
79 + }
62 80
63 - public function updateTemplate($templateDetail)
64 - {
65 - return static::$_emailTemplateModel->update(
66 - array(
67 - "title"=> $templateDetail->title,
68 - "sub"=> $templateDetail->sub,
69 - "body"=> $templateDetail->body,
70 - "form_id"=> static::$_formID,
71 - "user_id"=> $this->_user_details['id'],
72 - "user_ip"=>$this->_user_details['ip'],
73 - "updated_at"=> $this->_user_details['time']
74 - ),
75 - array(
76 - "id" => $templateDetail->id
77 - )
78 - );
79 - }
81 + public function deleteTemplate($templateID)
82 + {
83 + return static::$_emailTemplateModel->delete(
84 + [
85 + 'id' => $templateID,
86 + 'form_id' => static::$_formID,
87 + ]
88 + );
89 + }
80 90
81 - public function deleteTemplate($templateID)
82 - {
83 - return static::$_emailTemplateModel->delete(
84 - array(
85 - 'id' => $templateID,
86 - 'form_id' => static::$_formID,
87 - )
88 - );
91 + public function duplicateTemplate($templateID)
92 + {
93 + $templateDetail = static::$_emailTemplateModel->get(
94 + [
95 + 'id' => $templateID,
96 + 'form_id' => static::$_formID,
97 + ]
98 + );
99 + if (is_wp_error($templateDetail) || empty($templateDetail)) {
100 + return $templateDetail;
89 101 }
90 102
91 - public function duplicateTemplate($templateID)
92 - {
93 - $templateDetail = static::$_emailTemplateModel->get(
94 - array(
95 - 'id' => $templateID,
96 - 'form_id' => static::$_formID,
97 - )
98 - );
99 - if (is_wp_error($templateDetail) || empty($templateDetail)) {
100 - return $templateDetail;
101 - }
103 + $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
104 + "Duplicate of $templateDetail[0]->title";
102 105
103 - $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
104 - "Duplicate of $templateDetail[0]->title";
106 + $templateDetail[0]->title = $title;
107 + return $this->saveTemplate($templateDetail);
108 + }
105 109
106 - $templateDetail[0]->title = $title;
107 - return $this->saveTemplate($templateDetail);
108 - }
109 -
110 - public function duplicateAllTempInAForm($oldFromId)
111 - {
112 - $allCols = ["title","sub","body","form_id","user_id","user_ip","created_at","updated_at"];
113 - $dupData = array(
114 - "title",
115 - "sub",
116 - "body",
117 - static::$_formID,
118 - $this->_user_details['id'],
119 - $this->_user_details['ip'],
120 - $this->_user_details['time'],
121 - $this->_user_details['time']
122 - );
123 - return static::$_emailTemplateModel->duplicate(
124 - $allCols,
125 - $dupData,
126 - ['form_id' => $oldFromId]
127 - );
128 - }
110 + public function duplicateAllTempInAForm($oldFromId)
111 + {
112 + $allCols = ['title', 'sub', 'body', 'form_id', 'user_id', 'user_ip', 'created_at', 'updated_at'];
113 + $dupData = [
114 + 'title',
115 + 'sub',
116 + 'body',
117 + static::$_formID,
118 + $this->_user_details['id'],
119 + $this->_user_details['ip'],
120 + $this->_user_details['time'],
121 + $this->_user_details['time']
122 + ];
123 + return static::$_emailTemplateModel->duplicate(
124 + $allCols,
125 + $dupData,
126 + ['form_id' => $oldFromId]
127 + );
128 + }
129 129 }