|
@@ -139,7 +139,7 @@ class GenerateTreeCommand extends Command
|
|
$currentController->hasAdd = $hasAdd;
|
|
$currentController->hasAdd = $hasAdd;
|
|
$currentController->hasView = $hasView;
|
|
$currentController->hasView = $hasView;
|
|
$currentController->hasRemove = $hasRemove;
|
|
$currentController->hasRemove = $hasRemove;
|
|
- $currentController->addMethod("index", "/$line");
|
|
|
|
|
|
+ $currentMethod = $currentController->addMethod("index", "/$line");
|
|
if(!empty($currentSubController)) {
|
|
if(!empty($currentSubController)) {
|
|
$currentSubController->save();
|
|
$currentSubController->save();
|
|
}
|
|
}
|
|
@@ -155,11 +155,26 @@ class GenerateTreeCommand extends Command
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
- case 8: // sub-type declaration | add_new fields
|
|
|
|
|
|
+ case 8: // sub-type declaration | add_new fields | !inc/!exc
|
|
|
|
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
$currentSubType = $line;
|
|
$currentSubType = $line;
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!inc:") === 0) { // !inc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!exc:") === 0) { // !exc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!lnk:") === 0) { // !lnk:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->viewLinkField = substr($line, 5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if (!empty($currentMethod) &&
|
|
else if (!empty($currentMethod) &&
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
@@ -199,17 +214,32 @@ class GenerateTreeCommand extends Command
|
|
break;
|
|
break;
|
|
|
|
|
|
case 16: // data for actions and subs
|
|
case 16: // data for actions and subs
|
|
- if(!empty($currentMethod)) {
|
|
|
|
- $currentMethod->data[] = $line;
|
|
|
|
- if($exitURL) {
|
|
|
|
- if(strpos("=", $line) !== FALSE) {
|
|
|
|
- $currentMethod->viewURL = $exitURL;
|
|
|
|
|
|
+ if(strpos($line, "!inc:") === 0) { // !inc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- $currentMethod->exitURL = $exitURL;
|
|
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!exc:") === 0) { // !exc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!lnk:") === 0) { // !lnk:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->viewLinkField = substr($line, 5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->data[] = $line;
|
|
|
|
+ if($exitURL) {
|
|
|
|
+ if(strpos("=", $line) !== FALSE) {
|
|
|
|
+ $currentMethod->viewURL = $exitURL;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $currentMethod->exitURL = $exitURL;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case 20: // SUB add_new fields
|
|
case 20: // SUB add_new fields
|
|
@@ -456,12 +486,23 @@ class GenController {
|
|
"<i class='fa fa-trash'></i>" .
|
|
"<i class='fa fa-trash'></i>" .
|
|
"</a></td>";
|
|
"</a></td>";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // !inc/!exc
|
|
|
|
+ if($method->incType === "include") {
|
|
|
|
+ $columns = $method->incFields;
|
|
|
|
+ }
|
|
|
|
+ else if($method->incType === "exclude") {
|
|
|
|
+ $columns = array_filter($columns, function($item) use ($method) {
|
|
|
|
+ return in_array($item, $method->incFields) === FALSE;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($controller->hasView && $column === 'uid' ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
|
|
|
|
+ ($controller->hasView && $column === $method->viewLinkField ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
"<?= \$record->$column ?>" .
|
|
"<?= \$record->$column ?>" .
|
|
- ($controller->hasView && $column === 'uid' ? '</a>' : '') .
|
|
|
|
|
|
+ ($controller->hasView && $column === $method->viewLinkField ? '</a>' : '') .
|
|
"</td>";
|
|
"</td>";
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
@@ -589,12 +630,23 @@ class GenController {
|
|
|
|
|
|
$ths = [];
|
|
$ths = [];
|
|
$tds = [];
|
|
$tds = [];
|
|
|
|
+
|
|
|
|
+ // !inc/!exc
|
|
|
|
+ if($method->incType === "include") {
|
|
|
|
+ $columns = $method->incFields;
|
|
|
|
+ }
|
|
|
|
+ else if($method->incType === "exclude") {
|
|
|
|
+ $columns = array_filter($columns, function($item) use ($method) {
|
|
|
|
+ return in_array($item, $method->incFields) === FALSE;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($method->exitURL && $column === 'uid' ? '<a href="' . $method->exitURL . '">' : '') .
|
|
|
|
|
|
+ ($method->exitURL && $column === $method->viewLinkField ? '<a href="' . $method->exitURL . '">' : '') .
|
|
"<?= \$subRecord->$column ?>" .
|
|
"<?= \$subRecord->$column ?>" .
|
|
- ($method->exitURL && $column === 'uid' ? '</a>' : '') .
|
|
|
|
|
|
+ ($method->exitURL && $column === $method->viewLinkField ? '</a>' : '') .
|
|
"</td>";
|
|
"</td>";
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
@@ -789,6 +841,9 @@ class GenControllerMethod {
|
|
public $viewURL = false;
|
|
public $viewURL = false;
|
|
public $exitURL = false;
|
|
public $exitURL = false;
|
|
public $showLink = true;
|
|
public $showLink = true;
|
|
|
|
+ public $incType = null;
|
|
|
|
+ public $incFields = null;
|
|
|
|
+ public $viewLinkField = 'uid';
|
|
public function __construct($name, $route)
|
|
public function __construct($name, $route)
|
|
{
|
|
{
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
@@ -797,4 +852,14 @@ class GenControllerMethod {
|
|
$this->hasUID = true;
|
|
$this->hasUID = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public function setIncFields($type, $fields) {
|
|
|
|
+ $this->incType = $type;
|
|
|
|
+ $this->incFields = $fields;
|
|
|
|
+ for ($i = 0; $i < count($this->incFields); $i++) {
|
|
|
|
+ if($this->incFields[$i][0] === '@') {
|
|
|
|
+ $this->incFields[$i] = substr($this->incFields[$i], 1);
|
|
|
|
+ $this->viewLinkField = $this->incFields[$i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|