Browse Source

Update empty weight calculation

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
d4ac659b85
  1. 47
      app/Http/Controllers/ActivityController.php

47
app/Http/Controllers/ActivityController.php

@ -11,6 +11,7 @@ use App\Models\VersionGantt;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ActivityController extends Controller
{
@ -348,6 +349,52 @@ class ActivityController extends Controller
$activityStack = [];
$hasWeight = false;
foreach ($data['activities'] as $key => $value) {
if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){
$hasWeight = true;
break;
}
}
if(!$hasWeight){
foreach ($data['activities'] as $key => $value) {
if($key == 0){
$data['activities'][$key]['weight'] = 100;
} else {
$parentWeight = 0;
$siblingsCount = 1;
$i = $key;
while($i > 0){
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){
$parentWeight = $data['activities'][$i - 1]['weight'];
break;
}
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++;
}
$i--;
}
$i = $key+1;
while($i < count($data['activities'])){
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){
break;
}
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++;
}
$i++;
}
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
Log::info('level '.$data['activities'][$key]['level'].' bobot '.$data['activities'][$key]['weight'].' parent '.$parentWeight.' siblings '.$siblingsCount);
}
};
}
foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']);
$endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']);

Loading…
Cancel
Save