|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 13/03/2016 |
|
6
|
|
|
* Time: 19:52. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Classes\Repositories; |
|
10
|
|
|
|
|
11
|
|
|
use App\Model\Menu; |
|
12
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
13
|
|
|
use Illuminate\Support\Collection; |
|
14
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class MenuRepository. |
|
18
|
|
|
* |
|
19
|
|
|
* @method Menu withTrashed |
|
20
|
|
|
*/ |
|
21
|
|
|
class MenuRepository extends Menu |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
public function whereID(int $integer) : Menu |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->where('id', $integer)->first(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function restoreTrashedPlugin($plugin_name) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
return $this->withTrashed()->where('slug', $plugin_name)->restore(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function allByPriorityOrder() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
return $this->whereNull('menu_id')->orderBy('order_id', 'asc')->get(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function allByRowOrder() |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
return $this->whereNull('menu_id')->orderBy('order_id', 'asc')->get(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function listAllMenusNotRequired() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
return $this->whereNull('required')->pluck('title', 'id'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function makeList() |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
return $this->pluck('title', 'id'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function listWhereInternal() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
return $this->whereNotNull('page_id')->whereNull('menu_id')->pluck('title', 'id'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function submenusWhereID($integer) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
return $this->where('menu_id', $integer)->get(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function allMenus() |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
return $this->whereNull('menu_id')->get(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function allMenusWhereID($integer) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
return $this->where('menu_id', $integer)->get(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function allSubmenus() |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
return $this->whereNotNull('menu_id')->get(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function allSubmenusByPriorityOrderAndGrouped() |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
return$this->whereNotNull('menu_id')->orderBy('order_id', 'asc')->get()->groupBy('menu_id'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param $string |
|
86
|
|
|
* @return Menu|array|\stdClass |
|
87
|
|
|
*/ |
|
88
|
|
|
public function whereName($string) |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->where('slug', $string)->first(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* This will return the menus in order, that will be displayed in the front end. |
|
95
|
|
|
*/ |
|
96
|
|
|
public function whereFrontEndMenu() : Collection |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->whereNull('menu_id')->where('enabled', true)->orderBy('order_id', 'asc')->with('submenus')->get(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return a menus set of submenus from the database. |
|
103
|
|
|
*/ |
|
104
|
|
|
public function allSubmenusOfMenuID(int $integer) : Collection |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->where('menu_id', $integer)->where('enabled', true)->orderBy('order_id', 'asc')->get(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return all the global menus with the submenus and pages. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function allGlobalMenusWithSubmenus() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
return $this->whereNull('menu_id')->where('enabled', true)->with('page')->orderBy('order_id', 'asc')->get(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.