-
Notifications
You must be signed in to change notification settings - Fork 357
/
Copy pathEditMenuViewService.php
61 lines (50 loc) · 1.52 KB
/
EditMenuViewService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
13.11.2019
EditMenuViewService.php
*/
namespace App\Services;
use App\Http\Menus\GetSidebarMenu;
class EditMenuViewService{
private $getSidebarMenu;
private $menu;
private $roleMenu;
public function __construct(){
$this->getSidebarMenu = new GetSidebarMenu();
}
private function findOnAllDeepById( $arr, $id ){
$result = false;
foreach($arr as $ar){
if($ar['id'] === $id){
$result = true;
}elseif($ar['slug'] === 'dropdown'){
$result = $this->findOnAllDeepById( $ar['elements'] ,$id );
}
if($result === true){
break;
}
}
return $result;
}
private function markDoubleOnAllDeep( &$arr, $roleArr){
for($k=0;$k<count($arr);$k++){
if($this->findOnAllDeepById( $roleArr, $arr[$k]['id'] )){
$arr[$k]['assigned'] = true;
}else{
$arr[$k]['assigned'] = false;
}
if($arr[$k]['slug'] === 'dropdown'){
$this->markDoubleOnAllDeep( $arr[$k]['elements'], $roleArr );
}
}
}
private function joinMenuDataArrays(){
$this->markDoubleOnAllDeep( $this->menu, $this->roleMenu );
return $this->menu;
}
public function getDataForView( $role ){
$this->menu = $this->getSidebarMenu->getAll();
$this->roleMenu = $this->getSidebarMenu->get( $role );
return $this->joinMenuDataArrays();
}
}