| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Fallback; |
| 4 |
|
| 5 |
use BitCode\BitForm\Admin\Form\AdminFormManager; |
| 6 |
use BitCode\BitForm\Core\Database\EmailTemplateModel; |
| 7 |
use BitCode\BitForm\Core\Database\FallbackModel; |
| 8 |
use BitCode\BitForm\Core\Database\SuccessMessageModel; |
| 9 |
use BitCode\BitForm\Core\Form\FormHandler; |
| 10 |
use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 11 |
use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler; |
| 12 |
|
| 13 |
class FormEntryMetaChange |
| 14 |
{ |
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
$this->fallbackModel = new FallbackModel(); |
| 18 |
} |
| 19 |
|
| 20 |
public function changeMeta() |
| 21 |
{ |
| 22 |
$formHandler = FormHandler::getInstance(); |
| 23 |
$all_forms = $formHandler->admin->getAllForm(); |
| 24 |
foreach ($all_forms as $form) { |
| 25 |
$this->formID = $form->id; |
| 26 |
$formManager = new AdminFormManager($this->formID); |
| 27 |
$allFields = $formManager->getFormContent()->fields; |
| 28 |
foreach ($allFields as $fieldKey => $fieldVal) { |
| 29 |
$this->fieldKey = $fieldKey; |
| 30 |
$this->field_name = preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $fieldVal->lbl); |
| 31 |
$this->fallbackModel->changeMetaKey($this->fieldKey, $this->field_name); |
| 32 |
$this->changeIntegKey(); |
| 33 |
$this->changeWorkflowKey(); |
| 34 |
$this->changeSuccessMessageKey(); |
| 35 |
$this->changeEmailTempKey(); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
private function changeIntegKey() |
| 41 |
{ |
| 42 |
$integrationHandler = new IntegrationHandler($this->formID); |
| 43 |
|
| 44 |
$formIntegrations = $integrationHandler->getAllIntegration(); |
| 45 |
|
| 46 |
foreach ($formIntegrations as $integration) { |
| 47 |
$integId = $integration->id; |
| 48 |
$integstr = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $integration->integration_details); |
| 49 |
$this->fallbackModel->changeIntegKey($integId, $integstr); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private function changeWorkflowKey() |
| 54 |
{ |
| 55 |
$workflowHandler = new WorkFlowHandler($this->formID); |
| 56 |
$formWorkflows = $workflowHandler->getAllworkFlow(); |
| 57 |
foreach ($formWorkflows as $workflow) { |
| 58 |
$workflowId = $workflow['id']; |
| 59 |
$logics = wp_json_encode($workflow['logics']); |
| 60 |
$actions = wp_json_encode($workflow['actions']); |
| 61 |
$successAction = wp_json_encode($workflow['successAction']); |
| 62 |
$workflowAction = '{"action":' . $actions . ',"successAction":' . $successAction . '}'; |
| 63 |
|
| 64 |
$logics = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $logics); |
| 65 |
$workflowAction = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $workflowAction); |
| 66 |
|
| 67 |
$this->fallbackModel->changeWorkflowKey($workflowId, $logics, $workflowAction); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
private function changeSuccessMessageKey() |
| 72 |
{ |
| 73 |
$successMessageModel = new SuccessMessageModel(); |
| 74 |
$allSuccessMessages = $successMessageModel->get(); |
| 75 |
|
| 76 |
foreach ($allSuccessMessages as $message) { |
| 77 |
$messageId = $message->id; |
| 78 |
$title = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $message->message_title); |
| 79 |
$content = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $message->message_content); |
| 80 |
$this->fallbackModel->changeSuccessMessageKey($messageId, $title, $content); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
private function changeEmailTempKey() |
| 85 |
{ |
| 86 |
$emailTemplateModel = new EmailTemplateModel(); |
| 87 |
$allEmailTemp = $emailTemplateModel->get(); |
| 88 |
|
| 89 |
foreach ($allEmailTemp as $temp) { |
| 90 |
$tempId = $temp->id; |
| 91 |
$sub = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $temp->sub); |
| 92 |
$body = str_replace("{$this->fieldKey}{$this->field_name}", $this->fieldKey, $temp->body); |
| 93 |
$this->fallbackModel->changeEmailTempKey($tempId, $sub, $body); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|