output = $this->ln('
', 1); foreach ($in as $node) { $this->output .= $this->gem($node); } $this->output .= $this->ln('
', 1); // write form $template = file_get_contents(base_path("gem/templates/form.blade.php")); $this->output = str_replace('', $this->output, $template); file_put_contents(base_path("gem/forms/{$argv[2]}/build/form.blade.php"), $this->output); // write processor copy(base_path("gem/templates/processor.php"), base_path("gem/forms/{$argv[2]}/build/processor.php")); // write summary copy(base_path("gem/templates/summary.php"), base_path("gem/forms/{$argv[2]}/build/summary.php")); // copy output to store/section if(in_array("--write-to-storage", $argv) !== FALSE) { copy(base_path("gem/forms/{$argv[2]}/build/form.blade.php"), base_path("storage/sections/{$argv[2]}/form.blade.php")); copy(base_path("gem/forms/{$argv[2]}/build/processor.php"), base_path("storage/sections/{$argv[2]}/processor.php")); copy(base_path("gem/forms/{$argv[2]}/build/summary.php"), base_path("storage/sections/{$argv[2]}/summary.php")); } echo "OK"; } public function gem($_node, $_parentKey = false, $_level = 0) { $output = ''; $key = ($_parentKey ? $_parentKey . '__' : '') . $_node->K; // start container $output .= $this->ln('
', $_level + 1); // label $output .= $this->ln('', $_level + 2); // input $fieldLevel = $_level + 1; if (!!@$_node->T) { switch ($_node->T) { case 'YNUM': // start $output .= $this->ln('
', $fieldLevel + 1); // YES $output .= $this->ln('', $fieldLevel + 2); // NO $output .= $this->ln('', $fieldLevel + 2); // NO $output .= $this->ln('', $fieldLevel + 2); // MEMO $output .= $this->ln('', $fieldLevel + 2); // end $output .= $this->ln('
', $fieldLevel + 1); break; case 'SRV': // start $output .= $this->ln('
', $fieldLevel + 1); // VALUE $output .= $this->ln('', $fieldLevel + 2); // UNKNOWN $output .= $this->ln('', $fieldLevel + 2); // MEMO $output .= $this->ln('', $fieldLevel + 2); // end $output .= $this->ln('
', $fieldLevel + 1); break; case 'Text with Memo': // start $output .= $this->ln('
', $fieldLevel + 1); // VALUE $output .= $this->ln('', $fieldLevel + 2); // MEMO $output .= $this->ln('', $fieldLevel + 2); // end $output .= $this->ln('
', $fieldLevel + 1); break; case 'Multi Checkbox with Other': // start $output .= $this->ln('
', $fieldLevel + 1); foreach ($_node->Options as $option) { $output .= $this->ln('', $fieldLevel + 2); } // OTHER $output .= $this->ln('', $fieldLevel + 2); // end $output .= $this->ln('
', $fieldLevel + 1); break; case 'Accept': // start $output .= $this->ln('
', $fieldLevel + 1); // YES $output .= $this->ln('', $fieldLevel + 2); // NO $output .= $this->ln('', $fieldLevel + 2); // end $output .= $this->ln('
', $fieldLevel + 1); break; default: dump("Unknown type: {$_node->T}"); break; } } // subs if (!!@$_node->S) { $output .= $this->ln('
', $_level + 2); foreach ($_node->S as $sub) { $output .= $this->gem($sub, $key, $_level + 2); } $output .= $this->ln('
', $_level + 2); } // close container $output .= $this->ln('
', $_level + 1); $output .= $this->nl(); return $output; } public function formatText($_text) { $_text = preg_replace("/\{\{(.+?)\}\}/", '', $_text); return nl2br($_text); } public function ln($_line, $_indent = 1, $_nlAfter = true) { return str_repeat(" ", $_indent * 4) . $_line . ($_nlAfter ? "\n" : ''); } public function nl() { return "\n"; } }