123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- class Gem extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'gem
- {path:path-in-gem}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- public $output = '';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- global $argv;
- $in = json_decode(file_get_contents(base_path("gem/forms/{$argv[2]}/spec.json")));
- $outPath = base_path("gem/forms/{$argv[2]}/build");
- $this->output = '<div class="gem-nodes">';
- foreach ($in as $node) {
- $this->output .= $this->gem($node);
- }
- $this->output .= '</div>';
- file_put_contents(base_path("gem/forms/{$argv[2]}/build/form.blade.php"), $this->output);
- echo "OK";
- }
- public function gem($_node, $_parentKey = false, $_level = 0)
- {
- $output = '';
- $key = ($_parentKey ? $_parentKey . '__' : '') . $_node->K;
- // start container
- $output .= $this->ln('<div ' .
- 'class="my-3 node node-level-' . $_level . '" ' .
- 'data-key="' . $key . '">', $_level + 1);
- // label
- $output .= $this->ln('<label>' . $_node->Q . '</label>', $_level + 2);
- // input
- if (!!@$_node->T) {
- switch ($_node->T) {
- case 'YNUM':
- // start
- $output .= $this->ln('<div class="d-flex align-items-center">', $_level + 1);
- // YES
- $output .= $this->ln('<label class="d-inline-flex align-items-center my-0 mr-3">', $_level + 2);
- $output .= $this->ln('<input name="' . $key . '" type="radio" value="YES" class="mr-1">', $_level + 3);
- $output .= $this->ln('<span>Yes</span>', $_level + 3);
- $output .= $this->ln('</label>', $_level + 2);
- // NO
- $output .= $this->ln('<label class="d-inline-flex align-items-center my-0 mr-3">', $_level + 2);
- $output .= $this->ln('<input name="' . $key . '" type="radio" value="NO" class="mr-1">', $_level + 3);
- $output .= $this->ln('<span>No</span>', $_level + 3);
- $output .= $this->ln('</label>', $_level + 2);
- // NO
- $output .= $this->ln('<label class="d-inline-flex align-items-center my-0 mr-3">', $_level + 2);
- $output .= $this->ln('<input name="' . $key . '" type="radio" value="UNKNOWN" class="mr-1">', $_level + 3);
- $output .= $this->ln('<span>Unknown</span>', $_level + 3);
- $output .= $this->ln('</label>', $_level + 2);
- // MEMO
- $output .= $this->ln('<input name="' . $key . '_memo" type="text" class="form-control form-control-sm">', $_level + 2);
- // end
- $output .= $this->ln('</div>', $_level + 1);
- break;
- }
- }
- // subs
- if (!!@$_node->S) {
- $output .= '<div class="subs pl-4">';
- foreach ($_node->S as $sub) {
- $output .= $this->gem($sub, $key, $_level + 1);
- }
- $output .= '</div>';
- }
- // close container
- $output .= $this->ln('</div>', $_level + 1);
- $output .= $this->nl();
- return $output;
- }
- public function ln($_line, $_indent = 1, $_nlAfter = true)
- {
- return str_repeat(" ", $_indent * 4) . $_line . ($_nlAfter ? "\n" : '');
- }
- public function nl()
- {
- return "\n";
- }
- }
|