Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webprofile-jwg2024
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Siti Aisah
webprofile-jwg2024
Commits
a97be435
Commit
a97be435
authored
May 13, 2020
by
Aan Choesni Herlingga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optmized query backend menu
parent
72ab1c1a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
54 deletions
+31
-54
app/Helpers/InseoHelper.php
+4
-20
app/Http/Controllers/Webprofile/Backend/MenuController.php
+10
-21
app/Models/Webprofile/Menu.php
+5
-0
resources/views/webprofile/backend/menu/index.blade.php
+12
-13
No files found.
app/Helpers/InseoHelper.php
View file @
a97be435
...
...
@@ -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
;
}
}
app/Http/Controllers/Webprofile/Backend/MenuController.php
View file @
a97be435
...
...
@@ -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
)
{
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
::
w
ith
([
'rEn'
])
->
w
here
(
'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'
);
...
...
app/Models/Webprofile/Menu.php
View file @
a97be435
...
...
@@ -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'
]);
}
}
resources/views/webprofile/backend/menu/index.blade.php
View file @
a97be435
...
...
@@ -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,22 +151,22 @@
{{ Form::close() }}
</td>
</tr>
@if
(!empty(
$value['
child']
))
@foreach (
$value['
child']
as
$ckey
=>
$val
)
@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(InseoHelper::jumchild(2,
$val['parent
']
) != 1)
@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']
== InseoHelper::maxmenu(2,
$val['parent
']
))
@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>
...
...
@@ -175,7 +174,7 @@
<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['
child']
))
@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>
...
...
@@ -190,22 +189,22 @@
{{ Form::close() }}
</td>
</tr>
@if (!empty(
$val['
child']
))
@foreach (
$val['
child']
as
$ckey2
=>
$val2
)
@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(InseoHelper::jumchild(3,
$val2['parent
']
) != 1)
@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']
== InseoHelper::maxmenu(3,
$val2['parent
']
))
@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>
...
...
@@ -213,7 +212,7 @@
<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']
))
@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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment