Browse Source

update recursive

pull/3/head
wahyu 1 year ago
parent
commit
ad699117ce
  1. 9
      app/Http/Controllers/ActivityController.php

9
app/Http/Controllers/ActivityController.php

@ -175,6 +175,7 @@ class ActivityController extends Controller
}else{ }else{
$data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get();
} }
$parent = Activity::findOrFail($id);
$dataFinal=[]; $dataFinal=[];
foreach ($data as $val) { foreach ($data as $val) {
$activity = $this->getchildActivityForActual($val->id, $params); $activity = $this->getchildActivityForActual($val->id, $params);
@ -187,11 +188,19 @@ class ActivityController extends Controller
return isset($item['actual_start']); return isset($item['actual_start']);
}), 'actual_start'); }), 'actual_start');
$returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; $returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null;
if (isset($parent)) {
$parent->actual_start = $returnActualStartOrEnd;
$parent->save();
}
}else{ }else{
$actualEndValues = array_column(array_filter($dataFinal, function($item) { $actualEndValues = array_column(array_filter($dataFinal, function($item) {
return isset($item['actual_end']); return isset($item['actual_end']);
}), 'actual_end'); }), 'actual_end');
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null; $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null;
if (isset($parent)) {
$parent->actual_end = $returnActualStartOrEnd;
$parent->save();
}
} }
// return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]);

Loading…
Cancel
Save