Browse Source

implement hierarchy

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago committed by Gitea
parent
commit
0a45c5959b
  1. 27
      app/Http/Controllers/DivisiController.php

27
app/Http/Controllers/DivisiController.php

@ -9,7 +9,8 @@ class DivisiController extends Controller
{ {
private function getAllChildren($divisi, $depth = 0, $array = []) { private function getAllChildren($divisi, $depth = 0, $array = []) {
$array[$divisi->id] = $divisi->name; $divisi->depth = $depth;
array_push($array, $divisi);
foreach($divisi->children as $child){ foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array); $array = $this->getAllChildren($child, $depth + 1, $array);
} }
@ -69,20 +70,10 @@ class DivisiController extends Controller
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
} }
public function search(Request $request) public function search()
{ {
$payload = $request->all(); return $this->list();
// cant use builder for this case
if($payload['columns'][0]['value'] == "")
$this->list();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function list() public function list()
@ -91,7 +82,13 @@ class DivisiController extends Controller
$divisions = []; $divisions = [];
foreach($parentMenus as $menu){ foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu); $childs = $this->getAllChildren($menu);
$divisions = $divisions + $childs; foreach($childs as $d){
$d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){
$d->displayName = '--' . $d->displayName ;
}
array_push($divisions, $d);
}
} }
$countData = count($divisions); $countData = count($divisions);
if($countData == 0) if($countData == 0)

Loading…
Cancel
Save