|
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\Support\Collection; |
|
13
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class MenuRepository. |
|
18
|
|
|
* |
|
19
|
|
|
* @method Menu withTrashed |
|
20
|
|
|
*/ |
|
21
|
|
|
class MenuRepository extends BaseRepository |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var Menu|Builder|Collection |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $model; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* PageRepository constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param Menu $model |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(Menu $model) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->model = $model; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Frontend requires that a organised list of menus is returned. |
|
40
|
|
|
* |
|
41
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
42
|
|
|
*/ |
|
43
|
|
|
public function organisedMenuList() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->model->whereNull('parent_id')->where('status', true)->with('page')->orderBy('order', 'asc')->get(); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Top level menus, without any further parents. |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
52
|
|
|
*/ |
|
53
|
|
|
public function whereTopLevel() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->model->whereNull('parent_id')->orderBy('order', 'asc')->get(); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function whereTopLevelEditable() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->model->where('lock', false)->whereNull('parent_id')->orderBy('order', 'asc')->get(); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Where the menu belongs to a another menu. |
|
65
|
|
|
* |
|
66
|
|
|
* @param int $integer |
|
67
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
68
|
|
|
*/ |
|
69
|
|
|
public function whereParent(int $integer) |
|
70
|
|
|
{ |
|
71
|
|
|
return ($integer == 1) ? $this->whereTopLevel() : $this->model->where('parent_id', $integer)->orderBy('order', 'asc')->get(); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
76
|
|
|
*/ |
|
77
|
|
|
public function allParentsWithChildren() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->model->whereNull('parent_id')->with(['children' => function (HasMany $children) { |
|
|
|
|
|
|
80
|
|
|
}])->orderBy('order', 'asc')->get(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.