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 / Admin / Form / Template / TemplateProvider.php

TemplateProvider.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Admin/Form/Template/TemplateProvider.php

76 lines 2.1 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\Admin\Form\Template;
4
5 use FilesystemIterator;
6
7 final class TemplateProvider {
8 /**
9 * Undocumented function
10 *
11 * @return all
12 */
13 public function getAllTemplates() {
14 return $this->allTemplates();
15 }
16
17 /**
18 * Undocumented function
19 *
20 * @return void
21 */
22 protected function allTemplates() {
23 $dirs = new FilesystemIterator(__DIR__);
24 foreach ($dirs as $dirInfo) {
25 if ($dirInfo->isFile()) {
26 $integartionBaseName = basename($dirInfo);
27 if ('Template.php' === substr($integartionBaseName, -strlen('Template.php'))) {
28 $className = substr($integartionBaseName, 0, strpos($integartionBaseName, '.php'));
29 $className = __NAMESPACE__ . '\\' . $className;
30 $templateDetail = new $className();
31 $Templates[] = [
32 'title' => $templateDetail->getTitle(),
33 'description' => $templateDetail->getDescription(),
34 'status' => $templateDetail->getStatus(),
35 'thumbnail' => $templateDetail->getThumbnail(),
36 'category' => $templateDetail->getCategory()
37 ];
38 }
39 }
40 }
41 return json_encode($Templates);
42 }
43
44 /**
45 * Undocumented function
46 *
47 * @param String $name
48 * @return void
49 */
50 protected function setTemplate($name = 'Contact Form', $newFormId) {
51 $name = is_null($name) ? 'Contact Form' : $name;
52 $name = str_replace(' ', null, $name);
53 $file = false !== strpos($name, 'Template') ? $name . '.php' : $name . 'Template.php';
54 if (file_exists(__DIR__ . '/' . $file)) {
55 $className = __NAMESPACE__ . '\\' . $name . 'Template';
56 $templateDetail = new $className();
57 return [
58 'fields' => json_decode($templateDetail->getFields($newFormId)),
59 'layout' => json_decode($templateDetail->getLayout($newFormId)),
60 'form_name' => $templateDetail->getTitle()
61 ];
62 } else {
63 return false;
64 }
65 }
66
67 /**
68 * This function helps to get TEMPLATE
69 *
70 * @return bool setTemplate()
71 */
72 public function getTemplate($name, $newFormId) {
73 return $this->setTemplate($name, $newFormId);
74 }
75 }
76