Commit 80814a1d by Aan Choesni Herlingga

master menu

parent 61e704e5
<?php
namespace App\Helpers;
use App\Models\Webprofile\Menu;
class InseoHelper
{
public static function tglbulanindo2($waktu, $tipe = '')
{
$menit = substr($waktu, 14, 2);
$jam = substr($waktu, 11, 2);
$tgl = substr($waktu, 8, 2);
$bln = substr($waktu, 5, 2);
$thn = substr($waktu, 0, 4);
$bulan = array('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'Nopember', 'Desember');
$idxhari = date('N', strtotime($waktu));
switch ($tipe) {
case 1:
$full = $tgl . ' ' . $bulan[(int) $bln - 1] . ' ' . $thn;
break;
case 2:
$full = $tgl . '/' . $bln . '/' . $thn;
break;
default:
$full = "$tgl " . $bulan[(int) $bln - 1] . " $thn";
}
return $full;
}
public static function tgl($waktu)
{
$tgl = substr($waktu, 8, 2);
$bln = substr($waktu, 5, 2);
$thn = substr($waktu, 0, 4);
$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;
}
}
<?php
namespace App\Http\Controllers\Webprofile\Backend;
use App\Models\Webprofile\Pages;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Menu;
use Validator;
use Uuid;
use Alert;
use Crypt;
use Auth;
class MenuController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$parent = Menu::where('status', '1')->whereNull('url')->whereIn('level', [1, 2])->pluck('name', 'id');
$page = Pages::where('post_status', '1')->pluck('title', 'id');
$data = Menu::select('id', 'parent', 'name', 'url', 'level', 'urutan')->orderby('level', 'asc')->orderby('urutan', 'asc')->get();
$arr = $this->build_menu();
return view('webprofile.backend.menu.index', compact('parent', 'page', 'data', 'arr'))->withTitle('Menu');
}
public function build_menu()
{
$data = Menu::select('id', 'parent', 'name', 'url', 'level', 'urutan')->where('level', '1')->orderby('urutan', 'asc')->get();
$menu = [];
$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;
}
public function menu_has_child($parentid)
{
$data = Menu::where('parent', $parentid)->count();
if ($data > 0) {
return true;
} else {
return false;
}
}
public function menu_get_child($parentid)
{
$cdata = Menu::select('id', 'parent', 'name', 'url', 'level', 'urutan')->where('parent', $parentid)->orderby('urutan', 'asc')->get();
$i = 0;
$cmenu = [];
foreach ($cdata as $citem) {
$cmenu[$i]['id'] = $citem->id;
$cmenu[$i]['parent'] = $citem->parent;
$cmenu[$i]['name'] = $citem->name;
$cmenu[$i]['url'] = $citem->url;
$cmenu[$i]['level'] = $citem->level;
$cmenu[$i]['urutan'] = $citem->urutan;
if ($this->menu_has_child($citem->parent)) {
$cmenu[$i]['child'] = $this->menu_get_child($citem->id);
}
$i++;
}
return $cmenu;
}
public function menu_up($id)
{
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) {
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan-1)->first();
}
if ($cur_menu->parentlevel != null) {
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan-1)->first();
}
Menu::where('id', Crypt::decrypt($id))->update([
'urutan' => $up_menu->urutan,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
Menu::where('id', $up_menu->id)->update([
'urutan' => $up_menu->urutan+1,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
return redirect()->route('menu.index');
}
public function menu_down($id)
{
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) {
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan+1)->first();
}
if ($cur_menu->parentlevel != null) {
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan+1)->first();
}
Menu::where('id', Crypt::decrypt($id))->update([
'urutan' => $up_menu->urutan,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
Menu::where('id', $up_menu->id)->update([
'urutan' => $up_menu->urutan-1,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
return redirect()->route('menu.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = $request->except('_token');
$validator = Validator::make($data, Menu::$rules, Menu::$errormessage);
if ($validator->fails()) {
$errormessage = $validator->messages();
return redirect()->route('menu.index')
->withErrors($validator)
->withInput();
} else {
if ($request->input('parent') == null || $request->input('parent') == '') {
$parentlevel = null;
$level = 1;
} else {
$getlevelparent = Menu::where('id', $request->input('parent'))->first()->level;
$parentlevel = $getlevelparent;
$level = (int)$getlevelparent + 1;
}
$urutan = Menu::where('level', $level)->where('parent', $request->input('parent'))->max('urutan');
$data['status'] = 1;
$data['level'] = $level;
$data['parentlevel'] = $parentlevel;
$data['urutan'] = $urutan+1;
$data['userid_created'] = Auth::user()->name;
$data['userid_updated'] = Auth::user()->name;
Menu::create($data);
Alert::success('Data berhasil disimpan')->persistent('Ok');
$successmessage = "Proses Tambah Menu Berhasil !!";
return redirect()->route('menu.index')->with('successMessage', $successmessage);
}
}
public function newstorepage(Request $request)
{
$data = $request->except('_token');
$validator = Validator::make($data, Menu::$rules, Menu::$errormessage);
if ($validator->fails()) {
$errormessage = $validator->messages();
return redirect()->route('menu.index')
->withErrors($validator)
->withInput();
} else {
if ($request->input('parentpage') == null || $request->input('parentpage') == '') {
$parentlevel = null;
$level = 1;
} else {
$getlevelparent = Menu::where('id', $request->input('parentpage'))->first()->level;
$parentlevel = $getlevelparent;
$level = (int)$getlevelparent + 1;
}
$urutan = Menu::where('level', $level)->where('parent', $request->input('parentpage'))->max('urutan');
$page = Pages::where('id', $request->input('page'))->first();
$data['name'] = $page->title;
$data['level'] = $level;
$data['parentlevel'] = $parentlevel;
$data['urutan'] = $urutan+1;
$data['parent'] = $request->input('parentpage');
$data['url'] = '/page/'.$page->slug;
$data['status'] = 1;
$data['userid_created'] = Auth::user()->name;
$data['userid_updated'] = Auth::user()->name;
Menu::create($data);
Alert::success('Data berhasil disimpan')->persistent('Ok');
$successmessage = "Proses Tambah Menu Berhasil !!";
return redirect()->route('menu.index')->with('successMessage', $successmessage);
}
}
/**
* Display the specified resource.
*
* @param \App\Models\Menu $menu
* @return \Illuminate\Http\Response
*/
public function show(Menu $menu)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Menu $menu
* @return \Illuminate\Http\Response
*/
public function edit(Menu $menu)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Menu $menu
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Menu $menu)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Menu $menu
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
try {
$ceklevel = Menu::where('id', Crypt::decrypt($id))->first();
$level = $ceklevel->level;
Menu::where('id', Crypt::decrypt($id))->delete(Crypt::decrypt($id));
$tataurut = Menu::where('level', $level)->orderBy('urutan', 'asc')->get();
$urut = 1;
foreach ($tataurut as $value) {
Menu::where('id', $value->id)->update([
'urutan' => $urut++,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
}
return redirect()->route('menu.index');
} catch (\Exception $id) {
return redirect()->route('menu.index');
}
}
}
......@@ -12,5 +12,13 @@ class Menu extends Model
public $incrementing = false;
protected $table = 'swp_menus';
protected $fillable = [];
protected $guarded = [];
public static $rules = [
// 'name' => 'required',
];
public static $errormessage = [
'required' => 'Form Input Ini Tidak Boleh Kosong / Harus Diisi',
];
}
......@@ -56,6 +56,7 @@
"Tests\\": "tests/"
},
"files": [
"app/Helpers/InseoHelper.php",
"app/Helpers/Setting.php"
]
},
......
......@@ -226,6 +226,7 @@ return [
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Image' => Intervention\Image\Facades\Image::class,
'InseoHelper' => App\Helpers\InseoHelper::class,
],
......
......@@ -19,7 +19,7 @@ class CreateMenusTable extends Migration
$table->string('url')->nullable();
$table->string('mode')->nullable();
$table->boolean('status')->nullable();
$table->integer('parent')->nullable();
$table->string('parent', 36)->nullable();
$table->integer('urutan')->nullable();
$table->integer('parentlevel')->nullable();
$table->integer('level')->nullable();
......
......@@ -36,7 +36,7 @@
</ul>
</li>
<li>
<a href="{{ url('webprofile/newmenu') }}"><span class="fa fa-tasks"></span> <span class="xn-text">@lang('feature.menu')</span></a>
<a href="{{ url('webprofile/menu') }}"><span class="fa fa-tasks"></span> <span class="xn-text">@lang('feature.menu')</span></a>
</li>
<li>
<a href="{{ url('webprofile/layouts') }}"><span class="fa fa-tasks"></span> <span class="xn-text">@lang('feature.layout')</span></a>
......
......@@ -12,6 +12,11 @@ Route::group(['middleware' => 'auth'], function () {
Route::resource('categoriesfile', 'CategoriesFileController');
Route::resource('file', 'FileController');
Route::resource('layouts', 'LayoutController');
Route::resource('menu', 'MenuController');
Route::post('storepage', 'MenuController@storepage')->name('menu.storepage');
Route::get('menu_up/{id}', 'MenuController@menu_up')->name('menu_up');
Route::get('menu_down/{id}', 'MenuController@menu_down')->name('menu_down');
});
// });
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment