PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.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 2.0, at includes/Core/Messages/EmailTemplateHandler.php

121 lines 3.2 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 private static $_formID;
9 private static $_emailTemplateModel;
10 private $_user_details;
11
12 public function __construct($formID, array $user_details = null) {
13 static::$_formID = $formID;
14 static::$_emailTemplateModel = new EmailTemplateModel();
15 $this->_user_details = $user_details;
16 }
17
18 public function getAllTemplate($templateID = null, $userID = null) {
19 $condition = [
20 'form_id' => static::$_formID,
21 ];
22 if (!is_null($templateID)) {
23 $condition = array_merge($condition, ['id' => $templateID]);
24 }
25 if (!is_null($userID)) {
26 $condition = array_merge($condition, ['user_id' => $userID]);
27 }
28 return static::$_emailTemplateModel->get(
29 [
30 'id',
31 'title',
32 'sub',
33 'body'
34 ],
35 $condition
36 );
37 }
38
39 public function getATemplate($templateID) {
40 return $this->getAllTemplate($templateID);
41 }
42
43 public function saveTemplate($templateDetail) {
44 return static::$_emailTemplateModel->insert(
45 [
46 'title' => $templateDetail->title,
47 'sub' => $templateDetail->sub,
48 'body' => $templateDetail->body,
49 'form_id' => static::$_formID,
50 'user_id' => $this->_user_details['id'],
51 'user_ip' => $this->_user_details['ip'],
52 'created_at'=> $this->_user_details['time'],
53 'updated_at'=> $this->_user_details['time']
54 ]
55 );
56 }
57
58 public function updateTemplate($templateDetail) {
59 return static::$_emailTemplateModel->update(
60 [
61 'title' => $templateDetail->title,
62 'sub' => $templateDetail->sub,
63 'body' => $templateDetail->body,
64 'form_id' => static::$_formID,
65 'user_id' => $this->_user_details['id'],
66 'user_ip' => $this->_user_details['ip'],
67 'updated_at'=> $this->_user_details['time']
68 ],
69 [
70 'id' => $templateDetail->id
71 ]
72 );
73 }
74
75 public function deleteTemplate($templateID) {
76 return static::$_emailTemplateModel->delete(
77 [
78 'id' => $templateID,
79 'form_id' => static::$_formID,
80 ]
81 );
82 }
83
84 public function duplicateTemplate($templateID) {
85 $templateDetail = static::$_emailTemplateModel->get(
86 [
87 'id' => $templateID,
88 'form_id' => static::$_formID,
89 ]
90 );
91 if (is_wp_error($templateDetail) || empty($templateDetail)) {
92 return $templateDetail;
93 }
94
95 $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
96 "Duplicate of $templateDetail[0]->title";
97
98 $templateDetail[0]->title = $title;
99 return $this->saveTemplate($templateDetail);
100 }
101
102 public function duplicateAllTempInAForm($oldFromId) {
103 $allCols = ['title', 'sub', 'body', 'form_id', 'user_id', 'user_ip', 'created_at', 'updated_at'];
104 $dupData = [
105 'title',
106 'sub',
107 'body',
108 static::$_formID,
109 $this->_user_details['id'],
110 $this->_user_details['ip'],
111 $this->_user_details['time'],
112 $this->_user_details['time']
113 ];
114 return static::$_emailTemplateModel->duplicate(
115 $allCols,
116 $dupData,
117 ['form_id' => $oldFromId]
118 );
119 }
120 }
121