hasMany(StatTreeLineClause::class, 'stat_tree_line_id', 'id'); } public function statTree(){ return $this->hasOne(StatTree::class, 'id', 'stat_tree_id'); } public function parent(){ return $this->hasOne(StatTreeLine::class, 'id', 'parent_stat_tree_line_id'); } public function children(){ return $this->hasMany(StatTreeLine::class, 'parent_stat_tree_line_id', 'id') ->orderBy('tree_order_position_index'); } public function reportColumns(){ return $this->hasMany(StatTreeLineReportColumn::class, 'stat_tree_line_id', 'id') ->orderBy('position_index'); } public function displayLabel() { $lastStatTreeLineClause = StatTreeLineClause::where('stat_tree_line_id', $this->id) ->orderBy('position_index', 'DESC') ->first(); if($lastStatTreeLineClause) { return $lastStatTreeLineClause->clause_label; } return '-'; } public function displayLineClause() { $lastStatTreeLineClause = StatTreeLineClause::where('stat_tree_line_id', $this->id) ->orderBy('position_index', 'DESC') ->first(); if($lastStatTreeLineClause) { return $lastStatTreeLineClause; } return null; } public function columnsJSON() { $columns = []; foreach ($this->reportColumns as $column) { $columns[] = [ "label" => $column->label, "display_key" => $column->display_key, ]; } return json_encode($columns); } public function argsJSON() { $args = []; $displayLineClause = $this->displayLineClause(); if(!!$displayLineClause) { foreach($displayLineClause->statTreeLineClauseArgs as $stlcArg) { $args[] = [ "uid" => $stlcArg->uid, "arg_text" => $stlcArg->clauseArg->arg_text, "field_type" => $stlcArg->clauseArg->field_type, "default_value" => $stlcArg->default_value, "access_level" => $stlcArg->access_level, ]; } } return json_encode($args); } }