PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.2.0
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 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Messages / EmailTemplateHandler.php

EmailTemplateHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.2.0, at includes/Core/Messages/EmailTemplateHandler.php

136 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Messages;
4
5 use BitCode\BitForm\Core\Database\EmailTemplateModel;
6
7 final class EmailTemplateHandler
8 {
9 private static $_formID;
10 private static $_emailTemplateModel;
11 private $_user_details;
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;
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]);
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 'status',
38 'config'
39 ],
40 $condition
41 );
42 }
43
44 public function getATemplate($templateID)
45 {
46 return $this->getAllTemplate($templateID);
47 }
48
49 public function saveTemplate($templateDetail)
50 {
51 return static::$_emailTemplateModel->insert(
52 [
53 'title' => $templateDetail->title,
54 'sub' => $templateDetail->sub,
55 'body' => $templateDetail->body,
56 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1,
57 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null,
58 'form_id' => static::$_formID,
59 'user_id' => $this->_user_details['id'],
60 'user_ip' => $this->_user_details['ip'],
61 'created_at'=> $this->_user_details['time'],
62 'updated_at'=> $this->_user_details['time']
63 ]
64 );
65 }
66
67 public function updateTemplate($templateDetail)
68 {
69 return static::$_emailTemplateModel->update(
70 [
71 'title' => $templateDetail->title,
72 'sub' => $templateDetail->sub,
73 'body' => $templateDetail->body,
74 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1,
75 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null,
76 'form_id' => static::$_formID,
77 'user_id' => $this->_user_details['id'],
78 'user_ip' => $this->_user_details['ip'],
79 'updated_at'=> $this->_user_details['time']
80 ],
81 [
82 'id' => $templateDetail->id
83 ]
84 );
85 }
86
87 public function deleteTemplate($templateID)
88 {
89 return static::$_emailTemplateModel->delete(
90 [
91 'id' => $templateID,
92 'form_id' => static::$_formID,
93 ]
94 );
95 }
96
97 public function duplicateTemplate($templateID)
98 {
99 $templateDetail = static::$_emailTemplateModel->get(
100 [
101 'id' => $templateID,
102 'form_id' => static::$_formID,
103 ]
104 );
105 if (is_wp_error($templateDetail) || empty($templateDetail)) {
106 return $templateDetail;
107 }
108
109 $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
110 "Duplicate of $templateDetail[0]->title";
111
112 $templateDetail[0]->title = $title;
113 return $this->saveTemplate($templateDetail);
114 }
115
116 public function duplicateAllTempInAForm($oldFromId)
117 {
118 $allCols = ['title', 'sub', 'body', 'form_id', 'user_id', 'user_ip', 'created_at', 'updated_at'];
119 $dupData = [
120 'title',
121 'sub',
122 'body',
123 static::$_formID,
124 $this->_user_details['id'],
125 $this->_user_details['ip'],
126 $this->_user_details['time'],
127 $this->_user_details['time']
128 ];
129 return static::$_emailTemplateModel->duplicate(
130 $allCols,
131 $dupData,
132 ['form_id' => $oldFromId]
133 );
134 }
135 }
136