";
$code[] = "
";
}
$valueLine = "value='{{ old('$name') ? old('$name') : " . ($default ? "\$record->$default" : '\'\'') . " }}' ";
$valueStr = "{{ old('$name') ? old('$name') : " . ($default ? "\$record->$default" : '\'\'') . " }}";
switch ($type) {
case "select":
$code[] = "
";
break;
case "record":
$code[] = "
";
break;
case "bool":
$code[] = "
";
$code[] = "";
break;
case "textarea":
$code[] = "";
break;
default:
$code[] = "";
}
if($type !== 'hidden') {
$code[] = "
";
}
return implode("\n", $code);
}
}
class GenControllerMethod {
public $name;
public $route;
public $hasUID = false;
public $redirect = false;
public $type = '';
public $data = [];
public $parentSub = false;
public $childAddRoute = false;
public $table = false;
public $api = 'create';
public $show = null;
public $viewURL = false;
public $exitURL = false;
public $showLink = true;
public $incType = null;
public $incFields = null;
public $viewLinkField = 'uid';
public $columns = [];
public $columnActions = [];
public $groups = [];
public $dashboard = false;
public $noActionLinks = false;
public $queries = [];
public $subAdders = [];
public function __construct($name, $route)
{
$this->name = $name;
$this->route = $route;
if(strpos($this->route, "{uid}") !== FALSE) {
$this->hasUID = true;
}
}
public function addSubAdder($line, $parentControllerName, $label, $link) {
$parts = explode(":", $line);
$newSubAdder = [
"name" => "{$parts[0]}_{$parts[1]}",
"table" => $parts[1],
"api" => count($parts) >= 3 ? $parts[2] : null,
"link" => $link,
"data" => [],
"routeName" => "$parentControllerName-ACTION_{$parts[0]}_{$parts[1]}",
"buttonLabel" => $label
];
$this->subAdders[] = $newSubAdder;
return $newSubAdder;
}
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];
}
}
}
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
$parts = explode(":", $line);
$spec = [
"label" => $parts[1]
];
if(count($parts) > 2) {
$query = $parts[2];
// 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) {
$spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "= \$$recordVariable->$1 ?>", $link);
}
$this->columns[$parts[0]] = $spec;
}
public function addGroup($line, $link) {
// Basic Details:id,uid,created_at,clients_count
$parts = explode(":", $line);
$group = [
"name" => $parts[0],
"fields" => explode(",", $parts[1])
];
// is there a group action
if(count($parts) > 2) {
$actionParts = ["-"];
for($i = 2; $i < count($parts); $i++) {
$actionParts[] = $parts[$i];
}
$actionParts = implode(":", $actionParts);
$group["action"] = $this->addAction($actionParts, $link, true);
}
$this->groups[] = $group;
$this->dashboard = true;
}
public function addAction($line, $link, $group = false) {
// is_active:Deactivate:deactivate:edit:if:is_active
$parts = explode(":", $line);
$action = [
"label" => $parts[1],
"icon" => isset($parts[2]) ? $parts[2] : 'edit'
];
if(count($parts) >= 5 ) {
$action["condition"] = $parts[3];
$action["field"] = $parts[4];
}
if($link) {
$action['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "= \$record->$1 ?>", $link);
}
if(!$group) {
if(!isset($this->columnActions[$parts[0]])) {
$this->columnActions[$parts[0]] = [];
}
$this->columnActions[$parts[0]][] = $action;
}
return $action;
}
public function addQuery($line) {
$parts = explode(":", $line);
$this->queries[$parts[0]] = $parts[1];
}
}