|
@@ -185,6 +185,11 @@ class GenerateTreeCommand extends Command
|
|
$currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'record');
|
|
$currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'record');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!qry:") === 0) { // !qry:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->addQuery(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
|
|
@@ -246,6 +251,11 @@ class GenerateTreeCommand extends Command
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!qry:") === 0) { // !qry:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->addQuery(substr($line, 5));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if(strpos($line, "!grp:") === 0) { // !grp:
|
|
else if(strpos($line, "!grp:") === 0) { // !grp:
|
|
if (!empty($currentMethod)) {
|
|
if (!empty($currentMethod)) {
|
|
$currentMethod->addGroup(substr($line, 5), $exitURL);
|
|
$currentMethod->addGroup(substr($line, 5), $exitURL);
|
|
@@ -398,9 +408,12 @@ class GenController {
|
|
$code[] = "\t\t" . 'return redirect("' . $target . '");';
|
|
$code[] = "\t\t" . 'return redirect("' . $target . '");';
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
|
|
+
|
|
|
|
+ $input = [];
|
|
|
|
+
|
|
if($method->hasUID) {
|
|
if($method->hasUID) {
|
|
$code[] = "\t\t\$record = DB::table('{$this->dbTable}')->where('uid', \$uid)->first();";
|
|
$code[] = "\t\t\$record = DB::table('{$this->dbTable}')->where('uid', \$uid)->first();";
|
|
- $input = ["'record'"];
|
|
|
|
|
|
+ $input[] = "'record'";
|
|
// if sub-index controller, load subRecords
|
|
// if sub-index controller, load subRecords
|
|
if($method->type === 'sub' && count($method->data)) {
|
|
if($method->type === 'sub' && count($method->data)) {
|
|
$parts = explode(",", $method->data[0]);
|
|
$parts = explode(",", $method->data[0]);
|
|
@@ -433,6 +446,16 @@ class GenController {
|
|
// $code[] = "\t\t\$subRecords = DB::table('$foreignTable')->where('$foreignField', \$record->$localField)->get();";
|
|
// $code[] = "\t\t\$subRecords = DB::table('$foreignTable')->where('$foreignField', \$record->$localField)->get();";
|
|
$input[] = "'subRecords'";
|
|
$input[] = "'subRecords'";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ foreach ($method->queries as $key => $query) {
|
|
|
|
+ // replace $x with " . ($record->x ? $record->x : "''") . "
|
|
|
|
+ $query = preg_replace("/([^$])\\$([a-zA-Z0-9_]+)/", "$1\" . (\$record->$2 ? \$record->$2 : \"''\") . \"", $query);
|
|
|
|
+ // replace $$x with " . ($subRecord->x ? $subRecord->x : "''") . "
|
|
|
|
+ $query = preg_replace("/\\$\\$([a-zA-Z0-9_]+)/", "\" . (\$subRecord->$1 ? \$subRecord->$1 : \"''\") . \"", $query);
|
|
|
|
+ $code[] = "\t\t\$result_$key = DB::select(\"$query\");";
|
|
|
|
+ $input[] = "'result_$key'";
|
|
|
|
+ }
|
|
|
|
+
|
|
// return response()->view('pro/my_teams/add_new', compact('records'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
|
|
// return response()->view('pro/my_teams/add_new', compact('records'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
|
|
$code[] = "\t\treturn response()->view('{$this->root}/{$this->name}/{$method->name}', " .
|
|
$code[] = "\t\treturn response()->view('{$this->root}/{$this->name}/{$method->name}', " .
|
|
"compact(" . implode(", ", $input) . "), " .
|
|
"compact(" . implode(", ", $input) . "), " .
|
|
@@ -790,6 +813,9 @@ class GenController {
|
|
"select(\"{$method->columns[$field]["query"]}\");\n" .
|
|
"select(\"{$method->columns[$field]["query"]}\");\n" .
|
|
"echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
|
|
"echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
|
|
}
|
|
}
|
|
|
|
+ else if(isset($method->columns[$field]["getter"])) {
|
|
|
|
+ $columnValue = $method->columns[$field]["getter"];
|
|
|
|
+ }
|
|
if(isset($method->columns[$field]["link"])) {
|
|
if(isset($method->columns[$field]["link"])) {
|
|
$hasLink = true;
|
|
$hasLink = true;
|
|
$linkTarget = $method->columns[$field]["link"];
|
|
$linkTarget = $method->columns[$field]["link"];
|
|
@@ -1044,6 +1070,7 @@ class GenControllerMethod {
|
|
public $groups = [];
|
|
public $groups = [];
|
|
public $dashboard = false;
|
|
public $dashboard = false;
|
|
public $noActionLinks = false;
|
|
public $noActionLinks = false;
|
|
|
|
+ public $queries = [];
|
|
public function __construct($name, $route)
|
|
public function __construct($name, $route)
|
|
{
|
|
{
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
@@ -1070,8 +1097,50 @@ class GenControllerMethod {
|
|
];
|
|
];
|
|
if(count($parts) > 2) {
|
|
if(count($parts) > 2) {
|
|
$query = $parts[2];
|
|
$query = $parts[2];
|
|
- $query = preg_replace("/\\$([a-zA-Z0-9_]+)/", "\" . ($$recordVariable->$1 ? $$recordVariable->$1 : -1) . \"", $query);
|
|
|
|
- $spec['query'] = $query;
|
|
|
|
|
|
+ // check if named query
|
|
|
|
+ if($query[0] === '~') {
|
|
|
|
+ // hcp_pro_id:HCP Pro:~pros:name_display:id,=,$hcp_pro_id;is_active,=,true:all
|
|
|
|
+ $recordSet = '$result_' . substr($query, 1);
|
|
|
|
+ $field = $parts[3];
|
|
|
|
+ $checkParts = explode(";", $parts[4]);
|
|
|
|
+ $checks = [];
|
|
|
|
+ foreach ($checkParts as $checkPart) {
|
|
|
|
+ $checkPart = explode(",", $checkPart);
|
|
|
|
+ $value = $checkPart[2];
|
|
|
|
+ if(strpos($value, '$$') === 0) {
|
|
|
|
+ $value = '$subRecord->' . substr($value, 2);
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($value, '$') === 0) {
|
|
|
|
+ $value = '$record->' . substr($value, 1);
|
|
|
|
+ }
|
|
|
|
+ $checks[] = [
|
|
|
|
+ "field" => $checkPart[0],
|
|
|
|
+ "op" => $checkPart[1],
|
|
|
|
+ "value" => $value
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $condition = 'all';
|
|
|
|
+ if(count($parts) >= 6) {
|
|
|
|
+ $condition = $parts[5];
|
|
|
|
+ }
|
|
|
|
+ $checksArray = ["["];
|
|
|
|
+ foreach ($checks as $check) {
|
|
|
|
+ $checksArray[] = "[";
|
|
|
|
+ $checksArray[] = "'{$check['field']}'";
|
|
|
|
+ $checksArray[] = ", ";
|
|
|
|
+ $checksArray[] = "'{$check['op']}'";
|
|
|
|
+ $checksArray[] = ", ";
|
|
|
|
+ $checksArray[] = "{$check['value']}";
|
|
|
|
+ $checksArray[] = "], ";
|
|
|
|
+ }
|
|
|
|
+ $checksArray[] = "]";
|
|
|
|
+ $checks = implode("", $checksArray);
|
|
|
|
+ $spec['getter'] = "<?= value_from_rs($recordSet, '$field', " . $checks . ", '$condition'); ?>";
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $query = preg_replace("/\\$([a-zA-Z0-9_]+)/", "\" . ($$recordVariable->$1 ? $$recordVariable->$1 : -1) . \"", $query);
|
|
|
|
+ $spec['query'] = $query;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if($link) {
|
|
if($link) {
|
|
$spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
$spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
@@ -1119,4 +1188,8 @@ class GenControllerMethod {
|
|
}
|
|
}
|
|
return $action;
|
|
return $action;
|
|
}
|
|
}
|
|
|
|
+ public function addQuery($line) {
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $this->queries[$parts[0]] = $parts[1];
|
|
|
|
+ }
|
|
}
|
|
}
|