diff --git a/app/Helpers/InseoHelper.php b/app/Helpers/InseoHelper.php index 4f56142..a331eef 100644 --- a/app/Helpers/InseoHelper.php +++ b/app/Helpers/InseoHelper.php @@ -2,8 +2,6 @@ namespace App\Helpers; -use App\Models\Webprofile\Menu; - class InseoHelper { public static function tglbulanindo2($waktu, $tipe = '') @@ -18,13 +16,13 @@ class InseoHelper switch ($tipe) { case 1: - $full = $tgl . ' ' . $bulan[(int) $bln - 1] . ' ' . $thn; + $full = $tgl.' '.$bulan[(int) $bln - 1].' '.$thn; break; case 2: - $full = $tgl . '/' . $bln . '/' . $thn; + $full = $tgl.'/'.$bln.'/'.$thn; break; default: - $full = "$tgl " . $bulan[(int) $bln - 1] . " $thn"; + $full = "$tgl ".$bulan[(int) $bln - 1]." $thn"; } return $full; @@ -36,22 +34,8 @@ class InseoHelper $bln = substr($waktu, 5, 2); $thn = substr($waktu, 0, 4); - $full = $tgl . ' - ' . $bln . ' - ' . $thn; + $full = $tgl.' - '.$bln.' - '.$thn; return $full; } - - public static function maxmenu($lvl, $parentid) - { - $hnewmenu = Menu::where('parent', $parentid)->where('level', $lvl)->max('urutan'); - - return $hnewmenu; - } - - public static function jumchild($lvl, $parentid) - { - $hnewmenu = Menu::where('parent', $parentid)->where('level', $lvl)->count(); - - return $hnewmenu; - } } diff --git a/app/Http/Controllers/Webprofile/Backend/MenuController.php b/app/Http/Controllers/Webprofile/Backend/MenuController.php index 11f1f3d..a762e91 100644 --- a/app/Http/Controllers/Webprofile/Backend/MenuController.php +++ b/app/Http/Controllers/Webprofile/Backend/MenuController.php @@ -41,24 +41,9 @@ class MenuController extends Controller public function build_menu() { - $data = Menu::select('id', 'parent', 'name', 'url', 'level', 'urutan')->where('level', '1')->orderby('urutan', 'asc')->get(); - $menu = []; + $data = Menu::select('id', 'parent', 'name', 'url', 'level', 'urutan')->where('level', '1')->orderby('urutan', 'asc')->with('rEn', 'rChild')->get()->toArray(); - $i = 0; - foreach ($data as $item) { - $menu[$i]['id'] = $item->id; - $menu[$i]['parent'] = $item->parent; - $menu[$i]['name'] = $item->name; - $menu[$i]['url'] = $item->url; - $menu[$i]['level'] = $item->level; - $menu[$i]['urutan'] = $item->urutan; - if ($this->menu_has_child($item->parent)) { - $menu[$i]['child'] = $this->menu_get_child($item->id); - } - ++$i; - } - - return $menu; + return $data; } public function menu_has_child($parentid) @@ -202,10 +187,14 @@ class MenuController extends Controller } } - private function createEn($data, $menu) + private function createEn($data, $menu, $translate = 1) { - $trans = new GoogleTranslate(); - $name = $trans->translate($this->SOURCE, $this->TARGET, $data['name']); + if ($translate == 1) { + $trans = new GoogleTranslate(); + $name = $trans->translate($this->SOURCE, $this->TARGET, $data['name']); + } else { + $name = $data['name']; + } $dataEn['menu_id'] = $menu->id; $dataEn['name'] = $name; @@ -236,9 +225,9 @@ class MenuController extends Controller $urutan = Menu::where('level', $level)->where('parent', $request->input('parentpage'))->max('urutan'); - $page = Pages::where('id', $request->input('page'))->first(); + $page = Pages::with(['rEn'])->where('id', $request->input('page'))->first(); - $data['name'] = $page->title; + $data['name'] = $page->rEn->title; $data['level'] = $level; $data['parentlevel'] = $parentlevel; $data['urutan'] = $urutan + 1; @@ -250,7 +239,7 @@ class MenuController extends Controller $save = Menu::create($data); - $this->createEn($data, $save); + $this->createEn($data, $save, 'notTranslate'); Alert::success('Data berhasil disimpan')->persistent('Ok'); diff --git a/app/Models/Webprofile/Menu.php b/app/Models/Webprofile/Menu.php index 0d0903d..c51603b 100644 --- a/app/Models/Webprofile/Menu.php +++ b/app/Models/Webprofile/Menu.php @@ -29,4 +29,9 @@ class Menu extends Model { return $this->hasOne(EnMenu::class, 'menu_id', 'id'); } + + public function rChild() + { + return $this->hasMany(Menu::class, 'parent', 'id')->orderBy('urutan', 'asc')->with(['rChild', 'rEn']); + } } diff --git a/resources/views/webprofile/backend/menu/index.blade.php b/resources/views/webprofile/backend/menu/index.blade.php index c9a76c9..b2a073f 100644 --- a/resources/views/webprofile/backend/menu/index.blade.php +++ b/resources/views/webprofile/backend/menu/index.blade.php @@ -120,16 +120,15 @@ <td> <a href="{!! url((string)$value['url']) !!}" target="_blank">{!! $value['name'] !!}</a> </td> - {{-- <td style="text-align: center;">{!! $value['level'] !!}</td> --}} <td style="text-align:center; vertical-align: middle;"> - @if(InseoHelper::jumchild(1, $value['parent']) != 1) + @if(count($value['r_child']) != 1) @if($value['urutan'] == 1) <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($value['id'])]) }}" class="btn btn-warning btn-xs"> <i class="fa fa-arrow-down"></i> </a> @endif @if($value['urutan'] > 1) - @if($value['urutan'] == InseoHelper::maxmenu(1, $value['parent'])) + @if($value['urutan'] == count($arr)) <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($value['id'])]) }}" class="btn btn-warning btn-xs"> <i class="fa fa-arrow-up"></i> </a> @@ -152,85 +151,85 @@ {{ Form::close() }} </td> </tr> - @if (!empty($value['child'])) - @foreach ($value['child'] as $ckey => $val) - <tr> - <td> - <a href="{!! url((string)$val['url']) !!}">{!! $val['name'] !!}</a> - </td> - {{-- <td style="text-align: center;">{!! $val['level'] !!}</td> --}} - <td style="text-align:center; vertical-align: middle;"> - @if(InseoHelper::jumchild(2, $val['parent']) != 1) - @if($val['urutan'] == 1) + @if(!empty($value['r_child'])) + @foreach ($value['r_child'] as $ckey => $val) + <tr> + <td> + <a href="{!! url((string)$val['url']) !!}">{!! $val['name'] !!}</a> + </td> + {{-- <td style="text-align: center;">{!! $val['level'] !!}</td> --}} + <td style="text-align:center; vertical-align: middle;"> + @if(count($value['r_child']) != 1) + @if($val['urutan'] == 1) + <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-down"></i> + </a> + @endif + @if($val['urutan'] > 1) + @if($val['urutan'] == count($value['r_child'])) + <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-up"></i> + </a> + @else + <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-up"></i> + </a> + @if($ckey+1 < count($value['r_child'])) <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> <i class="fa fa-arrow-down"></i> </a> @endif - @if($val['urutan'] > 1) - @if($val['urutan'] == InseoHelper::maxmenu(2, $val['parent'])) - <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-up"></i> - </a> - @else - <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-up"></i> + @endif + @endif + @endif + + <button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$val['id']}}"><i class="fa fa-trash-o"></i></button> + {{ Form::open(['url'=>route('menu.destroy', ['data'=>Crypt::encrypt($val['id'])]), 'method'=>'delete', 'id' => $val['id'], 'style' => 'display: none;']) }} + {{ csrf_field() }} + {{ Form::close() }} + </td> + </tr> + @if (!empty($val['r_child'])) + @foreach ($val['r_child'] as $ckey2 => $val2) + <tr> + <td> + <a href="{!! url((string)$val2['url']) !!}">{!! $val2['name'] !!}</a> + </td> + {{-- <td style="text-align: center;">{!! $val2['level'] !!}</td> --}} + <td style="text-align:center; vertical-align: middle;"> + @if(count($val['r_child']) != 1) + @if($val2['urutan'] == 1) + <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-down"></i> + </a> + @endif + @if($val2['urutan'] > 1) + @if($val2['urutan'] == count($val['r_child'])) + <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-up"></i> + </a> + @else + <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-up"></i> + </a> + @if($ckey2+1 < count($val['r_child'])) + <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> + <i class="fa fa-arrow-down"></i> </a> - @if($ckey+1 < count($value['child'])) - <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-down"></i> - </a> - @endif @endif @endif - @endif - - <button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$val['id']}}"><i class="fa fa-trash-o"></i></button> - {{ Form::open(['url'=>route('menu.destroy', ['data'=>Crypt::encrypt($val['id'])]), 'method'=>'delete', 'id' => $val['id'], 'style' => 'display: none;']) }} - {{ csrf_field() }} - {{ Form::close() }} - </td> - </tr> - @if (!empty($val['child'])) - @foreach ($val['child'] as $ckey2 => $val2) - <tr> - <td> - <a href="{!! url((string)$val2['url']) !!}">{!! $val2['name'] !!}</a> - </td> - {{-- <td style="text-align: center;">{!! $val2['level'] !!}</td> --}} - <td style="text-align:center; vertical-align: middle;"> - @if(InseoHelper::jumchild(3, $val2['parent']) != 1) - @if($val2['urutan'] == 1) - <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-down"></i> - </a> - @endif - @if($val2['urutan'] > 1) - @if($val2['urutan'] == InseoHelper::maxmenu(3, $val2['parent'])) - <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-up"></i> - </a> - @else - <a href="{{ route('menu_up', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-up"></i> - </a> - @if($ckey2+1 < count($val['child'])) - <a href="{{ route('menu_down', ['data'=>Crypt::encrypt($val2['id'])]) }}" class="btn btn-warning btn-xs"> - <i class="fa fa-arrow-down"></i> - </a> - @endif - @endif - @endif - @endif + @endif + @endif - <button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$val2['id']}}"><i class="fa fa-trash-o"></i></button> - {{ Form::open(['url'=>route('menu.destroy', ['data'=>Crypt::encrypt($val2['id'])]), 'method'=>'delete', 'id' => $val2['id'], 'style' => 'display: none;']) }} - {{ csrf_field() }} - {{ Form::close() }} - </td> - </tr> - @endforeach - @endif - @endforeach + <button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$val2['id']}}"><i class="fa fa-trash-o"></i></button> + {{ Form::open(['url'=>route('menu.destroy', ['data'=>Crypt::encrypt($val2['id'])]), 'method'=>'delete', 'id' => $val2['id'], 'style' => 'display: none;']) }} + {{ csrf_field() }} + {{ Form::close() }} + </td> + </tr> + @endforeach + @endif + @endforeach @endif @endforeach </table>