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