|
@@ -81,6 +81,7 @@ class StatTreeController extends Controller
|
|
$statTree->model = $request->input('model');
|
|
$statTree->model = $request->input('model');
|
|
$statTree->slug = $request->input('slug');
|
|
$statTree->slug = $request->input('slug');
|
|
$statTree->is_template = (bool)$request->input('isTemplate');
|
|
$statTree->is_template = (bool)$request->input('isTemplate');
|
|
|
|
+ $statTree->pro_id = NULL;
|
|
if($request->input('proUid')) {
|
|
if($request->input('proUid')) {
|
|
$pro = Pro::where('uid', $request->input('proUid'))->first();
|
|
$pro = Pro::where('uid', $request->input('proUid'))->first();
|
|
if($pro) {
|
|
if($pro) {
|
|
@@ -207,7 +208,7 @@ class StatTreeController extends Controller
|
|
$statTreeLineClauseArg->clause_arg_id = $clauseArg->id;
|
|
$statTreeLineClauseArg->clause_arg_id = $clauseArg->id;
|
|
$statTreeLineClauseArg->access_level = 'ADMIN';
|
|
$statTreeLineClauseArg->access_level = 'ADMIN';
|
|
$statTreeLineClauseArg->stat_tree_id = $statTree->id;
|
|
$statTreeLineClauseArg->stat_tree_id = $statTree->id;
|
|
- $statTreeLineClauseArg->default_value = null;
|
|
|
|
|
|
+ $statTreeLineClauseArg->value = null;
|
|
|
|
|
|
// TODO: need to copy clause arg values from parent node for all except last clause
|
|
// TODO: need to copy clause arg values from parent node for all except last clause
|
|
|
|
|
|
@@ -278,7 +279,7 @@ class StatTreeController extends Controller
|
|
$children = [];
|
|
$children = [];
|
|
|
|
|
|
// clause text child
|
|
// clause text child
|
|
- $children[] = [
|
|
|
|
|
|
+ /*$children[] = [
|
|
"text" => $clause->clause_text,
|
|
"text" => $clause->clause_text,
|
|
"icon" => "fa fa-laptop-code text-primary text-sm",
|
|
"icon" => "fa fa-laptop-code text-primary text-sm",
|
|
"state" => [
|
|
"state" => [
|
|
@@ -295,7 +296,7 @@ class StatTreeController extends Controller
|
|
"data" => [
|
|
"data" => [
|
|
"type" => "clause_text"
|
|
"type" => "clause_text"
|
|
]
|
|
]
|
|
- ];
|
|
|
|
|
|
+ ];*/
|
|
|
|
|
|
// clause arg children
|
|
// clause arg children
|
|
$argsSystem = [];
|
|
$argsSystem = [];
|
|
@@ -304,7 +305,7 @@ class StatTreeController extends Controller
|
|
"text" => $clauseArg->arg_text . '<span class="text-secondary text-sm ml-2">' . $clauseArg->field_type . '</span>',
|
|
"text" => $clauseArg->arg_text . '<span class="text-secondary text-sm ml-2">' . $clauseArg->field_type . '</span>',
|
|
"icon" => "fa fa-cubes text-info",
|
|
"icon" => "fa fa-cubes text-info",
|
|
"state" => [
|
|
"state" => [
|
|
- "opened" => false,
|
|
|
|
|
|
+ "opened" => true,
|
|
"disabled" => false,
|
|
"disabled" => false,
|
|
"selected" => false,
|
|
"selected" => false,
|
|
],
|
|
],
|
|
@@ -320,7 +321,7 @@ class StatTreeController extends Controller
|
|
$argsSystem[] = [
|
|
$argsSystem[] = [
|
|
"arg_text" => $clauseArg->arg_text,
|
|
"arg_text" => $clauseArg->arg_text,
|
|
"field_type" => $clauseArg->field_type,
|
|
"field_type" => $clauseArg->field_type,
|
|
- "default_value" => null,
|
|
|
|
|
|
+ "value" => null,
|
|
"access_level" => null
|
|
"access_level" => null
|
|
];
|
|
];
|
|
}
|
|
}
|
|
@@ -328,7 +329,7 @@ class StatTreeController extends Controller
|
|
$nodes[] = [
|
|
$nodes[] = [
|
|
"text" => $clause->label,
|
|
"text" => $clause->label,
|
|
"state" => [
|
|
"state" => [
|
|
- "opened" => false,
|
|
|
|
|
|
+ "opened" => true,
|
|
"disabled" => false,
|
|
"disabled" => false,
|
|
"selected" => false,
|
|
"selected" => false,
|
|
],
|
|
],
|
|
@@ -376,7 +377,7 @@ class StatTreeController extends Controller
|
|
$value = null;
|
|
$value = null;
|
|
foreach ($lineClause->lineClauseArgs as $lineClauseArg) {
|
|
foreach ($lineClause->lineClauseArgs as $lineClauseArg) {
|
|
if($lineClauseArg->clause_arg_id === $clauseArg->id) {
|
|
if($lineClauseArg->clause_arg_id === $clauseArg->id) {
|
|
- $value = $lineClauseArg->default_value;
|
|
|
|
|
|
+ $value = $lineClauseArg->value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -388,10 +389,11 @@ class StatTreeController extends Controller
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- $isValid = $this->cleanupClause($clauseText);
|
|
|
|
- if ($isValid) {
|
|
|
|
|
|
+ //dump($clauseText);
|
|
|
|
+ /*$isValid = $this->cleanupClause($clauseText);
|
|
|
|
+ if ($isValid) {*/
|
|
array_push($clauses, $clauseText);
|
|
array_push($clauses, $clauseText);
|
|
- }
|
|
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
// if stat tree bound to a pro, apply pro_scope_clause
|
|
// if stat tree bound to a pro, apply pro_scope_clause
|
|
@@ -410,6 +412,70 @@ class StatTreeController extends Controller
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.$model.' WHERE '. implode(" AND ", $clauses);
|
|
$query = 'SELECT COUNT(*) FROM '.$model.' WHERE '. implode(" AND ", $clauses);
|
|
try {
|
|
try {
|
|
|
|
+ //dump($query);
|
|
|
|
+ $result = DB::select($query);
|
|
|
|
+ }
|
|
|
|
+ catch (\Exception $ex) {
|
|
|
|
+ $result = 'error';
|
|
|
|
+ }
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function applyStatTreeLineQueryClausesGroupByPros(StatTreeLine $statTreeLine, $proUids)
|
|
|
|
+ {
|
|
|
|
+ $model = $statTreeLine->statTree->model;
|
|
|
|
+ $clauses = [];
|
|
|
|
+ foreach ($statTreeLine->lineClauses as $lineClause) {
|
|
|
|
+ $clauseText = $lineClause->clause->clause_text;
|
|
|
|
+
|
|
|
|
+ // apply arg values
|
|
|
|
+ foreach ($lineClause->clause->clauseArgs as $clauseArg) {
|
|
|
|
+
|
|
|
|
+ $value = null;
|
|
|
|
+ foreach ($lineClause->lineClauseArgs as $lineClauseArg) {
|
|
|
|
+ if($lineClauseArg->clause_arg_id === $clauseArg->id) {
|
|
|
|
+ $value = $lineClauseArg->value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!is_null($value)) {
|
|
|
|
+ $clauseText = str_replace(
|
|
|
|
+ ':' . $clauseArg->arg_text, // search for :xxx
|
|
|
|
+ "'" . $value . "'::" . $clauseArg->field_type, // replace with '$value'::$field_type
|
|
|
|
+ $clauseText);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //dump($clauseText);
|
|
|
|
+ /*$isValid = $this->cleanupClause($clauseText);
|
|
|
|
+ if ($isValid) {*/
|
|
|
|
+ array_push($clauses, $clauseText);
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // if stat tree bound to a pro, apply pro_scope_clause
|
|
|
|
+ /*if(!$proUid) {
|
|
|
|
+ if($statTreeLine->statTree->pro && $statTreeLine->statTree->pro_scope_clause) {
|
|
|
|
+ $clauses[] = str_replace('@PRO_ID', $statTreeLine->statTree->pro->id, $statTreeLine->statTree->pro_scope_clause);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $mvPro = Pro::where('uid', $proUid)->first();
|
|
|
|
+ if($statTreeLine->statTree->pro_scope_clause) {
|
|
|
|
+ $clauses[] = str_replace('@PRO_ID', $mvPro->id, $statTreeLine->statTree->pro_scope_clause);
|
|
|
|
+ }
|
|
|
|
+ $query = 'SELECT COUNT(*) FROM '.$model.' WHERE '. implode(" AND ", $clauses);
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ $proUids = explode(",", $proUids);
|
|
|
|
+ $proUids = array_map(function($_x) {
|
|
|
|
+ return "'{$_x}'";
|
|
|
|
+ }, $proUids);
|
|
|
|
+ $clauses[] = "_j_pro.uid IN (" . implode(",", $proUids) . ")";
|
|
|
|
+ $proJoinClause = 'JOIN pro _j_pro on ' . str_replace('@PRO_ID', '_j_pro.id', $statTreeLine->statTree->pro_scope_clause);
|
|
|
|
+ $query = "SELECT COUNT(*), _j_pro.uid as _v_pro_uid FROM {$model} {$proJoinClause} WHERE " . implode(" AND ", $clauses) . " GROUP BY _j_pro.uid";
|
|
|
|
+ try {
|
|
|
|
+ //dump($query);
|
|
$result = DB::select($query);
|
|
$result = DB::select($query);
|
|
}
|
|
}
|
|
catch (\Exception $ex) {
|
|
catch (\Exception $ex) {
|
|
@@ -458,6 +524,24 @@ class StatTreeController extends Controller
|
|
return json_encode($result);
|
|
return json_encode($result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function getCountsForPros(Request $request) {
|
|
|
|
+ $statTreeUid = $request->get('uid');
|
|
|
|
+ if (!$statTreeUid) return $this->fail('No specified stat tree!');
|
|
|
|
+ $statTree = StatTree::where('uid', $statTreeUid)->first();
|
|
|
|
+ $lines = $statTree->lines;
|
|
|
|
+ $result = [];
|
|
|
|
+ foreach ($lines as $line) {
|
|
|
|
+ $query = $this->applyStatTreeLineQueryClausesGroupByPros($line, $request->input('proUids'));
|
|
|
|
+ if ($query && $query !== 'error') {
|
|
|
|
+ $result[$line->uid] = $query;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $result[$line->uid] = -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return json_encode($result);
|
|
|
|
+ }
|
|
|
|
+
|
|
private function lineObject(StatTreeLine $line) {
|
|
private function lineObject(StatTreeLine $line) {
|
|
|
|
|
|
// columns
|
|
// columns
|
|
@@ -479,10 +563,10 @@ class StatTreeController extends Controller
|
|
$args[] = [
|
|
$args[] = [
|
|
"arg_text" => $stlcArg->clauseArg->arg_text,
|
|
"arg_text" => $stlcArg->clauseArg->arg_text,
|
|
"field_type" => $stlcArg->clauseArg->field_type,
|
|
"field_type" => $stlcArg->clauseArg->field_type,
|
|
- "default_value" => $stlcArg->default_value,
|
|
|
|
|
|
+ "value" => $stlcArg->value,
|
|
"access_level" => $stlcArg->access_level
|
|
"access_level" => $stlcArg->access_level
|
|
];
|
|
];
|
|
- $argsLabel[] = $stlcArg->clauseArg->arg_text . ': ' . $stlcArg->default_value;
|
|
|
|
|
|
+ $argsLabel[] = $stlcArg->clauseArg->arg_text . ': ' . $stlcArg->value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$clause = [
|
|
$clause = [
|
|
@@ -598,7 +682,7 @@ class StatTreeController extends Controller
|
|
$statTreeLineClauseArg->id = $nextId[0]->nextval;
|
|
$statTreeLineClauseArg->id = $nextId[0]->nextval;
|
|
$statTreeLineClauseArg->stat_tree_line_clause_id = $statTreeLineClause->id; // this line cause
|
|
$statTreeLineClauseArg->stat_tree_line_clause_id = $statTreeLineClause->id; // this line cause
|
|
$statTreeLineClauseArg->clause_arg_id = $parentLineClauseArg->clause_arg_id;
|
|
$statTreeLineClauseArg->clause_arg_id = $parentLineClauseArg->clause_arg_id;
|
|
- $statTreeLineClauseArg->default_value = $parentLineClauseArg->default_value;
|
|
|
|
|
|
+ $statTreeLineClauseArg->value = $parentLineClauseArg->value;
|
|
$statTreeLineClauseArg->access_level = $parentLineClauseArg->access_level;
|
|
$statTreeLineClauseArg->access_level = $parentLineClauseArg->access_level;
|
|
$statTreeLineClauseArg->stat_tree_id = $statTree->id;
|
|
$statTreeLineClauseArg->stat_tree_id = $statTree->id;
|
|
$statTreeLineClauseArg->save();
|
|
$statTreeLineClauseArg->save();
|
|
@@ -629,12 +713,12 @@ class StatTreeController extends Controller
|
|
$statTreeLineClauseArg->id = $nextId[0]->nextval;
|
|
$statTreeLineClauseArg->id = $nextId[0]->nextval;
|
|
$statTreeLineClauseArg->stat_tree_line_clause_id = $statTreeLineClause->id;
|
|
$statTreeLineClauseArg->stat_tree_line_clause_id = $statTreeLineClause->id;
|
|
$statTreeLineClauseArg->clause_arg_id = $clauseArg->id;
|
|
$statTreeLineClauseArg->clause_arg_id = $clauseArg->id;
|
|
- $statTreeLineClauseArg->default_value = null;
|
|
|
|
|
|
+ $statTreeLineClauseArg->value = null;
|
|
$statTreeLineClauseArg->access_level = 'ADMIN';
|
|
$statTreeLineClauseArg->access_level = 'ADMIN';
|
|
for ($j=0; $j<count($line->clause->args); $j++) { // find the arg matching text and type from line->args and use that
|
|
for ($j=0; $j<count($line->clause->args); $j++) { // find the arg matching text and type from line->args and use that
|
|
if($line->clause->args[$j]->arg_text === $clauseArg->arg_text &&
|
|
if($line->clause->args[$j]->arg_text === $clauseArg->arg_text &&
|
|
$line->clause->args[$j]->field_type === $clauseArg->field_type) {
|
|
$line->clause->args[$j]->field_type === $clauseArg->field_type) {
|
|
- $statTreeLineClauseArg->default_value = $line->clause->args[$j]->default_value;
|
|
|
|
|
|
+ $statTreeLineClauseArg->value = $line->clause->args[$j]->value;
|
|
$statTreeLineClauseArg->access_level = $line->clause->args[$j]->access_level;
|
|
$statTreeLineClauseArg->access_level = $line->clause->args[$j]->access_level;
|
|
break;
|
|
break;
|
|
}
|
|
}
|