|
@@ -177,7 +177,7 @@ class GenerateTreeCommand extends Command
|
|
}
|
|
}
|
|
else if(strpos($line, "!col:") === 0) { // !col:
|
|
else if(strpos($line, "!col:") === 0) { // !col:
|
|
if (!empty($currentMethod)) {
|
|
if (!empty($currentMethod)) {
|
|
- $currentMethod->setColumnSpec(substr($line, 5), $exitURL);
|
|
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'record');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (!empty($currentMethod) &&
|
|
else if (!empty($currentMethod) &&
|
|
@@ -236,7 +236,7 @@ class GenerateTreeCommand extends Command
|
|
}
|
|
}
|
|
else if(strpos($line, "!col:") === 0) { // !col:
|
|
else if(strpos($line, "!col:") === 0) { // !col:
|
|
if (!empty($currentMethod)) {
|
|
if (!empty($currentMethod)) {
|
|
- $currentMethod->setColumnSpec(substr($line, 5), $exitURL);
|
|
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'subRecord');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if(!empty($currentMethod)) {
|
|
else if(!empty($currentMethod)) {
|
|
@@ -671,12 +671,32 @@ class GenController {
|
|
}
|
|
}
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
- $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
|
|
|
+
|
|
|
|
+ $columnTitle = $this->snakeToTitleCase($column);
|
|
|
|
+ $columnValue = "<?= \$subRecord->$column ?>";
|
|
|
|
+ $hasLink = $method->exitURL && $column === $method->viewLinkField;
|
|
|
|
+ $linkTarget = $method->exitURL;
|
|
|
|
+
|
|
|
|
+ // check if this column has column spec
|
|
|
|
+ if(isset($method->columns[$column])) {
|
|
|
|
+ $columnTitle = $method->columns[$column]["label"];
|
|
|
|
+ if(isset($method->columns[$column]["query"])) {
|
|
|
|
+ $columnValue = "<?= \Illuminate\Support\Facades\DB::" .
|
|
|
|
+ "select(\"{$method->columns[$column]["query"]}\")[0]->result ?>";
|
|
|
|
+ }
|
|
|
|
+ if(isset($method->columns[$column]["link"])) {
|
|
|
|
+ $hasLink = true;
|
|
|
|
+ $linkTarget = $method->columns[$column]["link"];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $ths[] = "<th>$columnTitle</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($method->exitURL && $column === $method->viewLinkField ? '<a href="' . $method->exitURL . '">' : '') .
|
|
|
|
- "<?= \$subRecord->$column ?>" .
|
|
|
|
- ($method->exitURL && $column === $method->viewLinkField ? '</a>' : '') .
|
|
|
|
|
|
+ ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
|
|
|
|
+ $columnValue .
|
|
|
|
+ ($hasLink ? "</a>" : "") .
|
|
"</td>";
|
|
"</td>";
|
|
|
|
+
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
|
|
@@ -892,7 +912,7 @@ class GenControllerMethod {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public function setColumnSpec($line, $link) {
|
|
|
|
|
|
+ public function setColumnSpec($line, $link, $recordVariable) {
|
|
// ally_pro_id:Ally Pro:select name_display as 'result' from pro where id = $ally_pro_id limit 1
|
|
// ally_pro_id:Ally Pro:select name_display as 'result' from pro where id = $ally_pro_id limit 1
|
|
/*
|
|
/*
|
|
label
|
|
label
|
|
@@ -905,11 +925,11 @@ class GenControllerMethod {
|
|
];
|
|
];
|
|
if(count($parts) > 2) {
|
|
if(count($parts) > 2) {
|
|
$query = $parts[2];
|
|
$query = $parts[2];
|
|
- $query = preg_replace("/\\$(\S+)/", "{\$record->$1}", $query);
|
|
|
|
|
|
+ $query = preg_replace("/\\$(\S+)/", "{\$$recordVariable->$1}", $query);
|
|
$spec['query'] = $query;
|
|
$spec['query'] = $query;
|
|
}
|
|
}
|
|
if($link) {
|
|
if($link) {
|
|
- $spec['link'] = preg_replace("/\\$(\S+)/", "<?= \$record->$1 ?>", $link);
|
|
|
|
|
|
+ $spec['link'] = preg_replace("/\\$(\S+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
}
|
|
}
|
|
$this->columns[$parts[0]] = $spec;
|
|
$this->columns[$parts[0]] = $spec;
|
|
}
|
|
}
|