|
1
|
|
|
<?php namespace Arcanedev\Breadcrumbs\Entities; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Arr; |
|
4
|
|
|
use Illuminate\Support\Fluent; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class BreadcrumbItem |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\Breadcrumbs\Entities |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
* |
|
12
|
|
|
* @property string title |
|
13
|
|
|
* @property string url |
|
14
|
|
|
* @property bool first |
|
15
|
|
|
* @property bool last |
|
16
|
|
|
*/ |
|
17
|
|
|
class BreadcrumbItem extends Fluent |
|
18
|
|
|
{ |
|
19
|
|
|
/* ----------------------------------------------------------------- |
|
20
|
|
|
| Constructor |
|
21
|
|
|
| ----------------------------------------------------------------- |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a breadcrumb item instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array|object $attributes |
|
28
|
|
|
*/ |
|
29
|
22 |
|
public function __construct(array $attributes = []) |
|
30
|
|
|
{ |
|
31
|
22 |
|
$keys = ['title', 'url', 'icon']; |
|
32
|
|
|
|
|
33
|
22 |
|
parent::__construct(Arr::only($attributes, $keys) + [ |
|
34
|
22 |
|
'extra' => Arr::except($attributes, $keys) |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
22 |
|
$this->resetPosition(); |
|
38
|
22 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/* ----------------------------------------------------------------- |
|
41
|
|
|
| Getters & Setters |
|
42
|
|
|
| ----------------------------------------------------------------- |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the title. |
|
47
|
|
|
* |
|
48
|
|
|
* @return string|null |
|
49
|
|
|
*/ |
|
50
|
4 |
|
public function getTitle() |
|
51
|
|
|
{ |
|
52
|
4 |
|
return $this->get('title'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the url. |
|
57
|
|
|
* |
|
58
|
|
|
* @return string|null |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function getUrl() |
|
61
|
|
|
{ |
|
62
|
4 |
|
return $this->get('url'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Set as first item. |
|
67
|
|
|
* |
|
68
|
|
|
* @return self |
|
69
|
|
|
*/ |
|
70
|
14 |
|
public function setFirst() |
|
71
|
|
|
{ |
|
72
|
14 |
|
$this->attributes['first'] = true; |
|
73
|
|
|
|
|
74
|
14 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set as last item. |
|
79
|
|
|
* |
|
80
|
|
|
* @return self |
|
81
|
|
|
*/ |
|
82
|
14 |
|
public function setLast() |
|
83
|
|
|
{ |
|
84
|
14 |
|
$this->attributes['last'] = true; |
|
85
|
|
|
|
|
86
|
14 |
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the extra attribute. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $key |
|
93
|
|
|
* @param mixed $default |
|
94
|
|
|
* |
|
95
|
|
|
* @return mixed |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function extra($key, $default = null) |
|
98
|
|
|
{ |
|
99
|
2 |
|
return Arr::get($this->attributes['extra'], $key, $default); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/* ----------------------------------------------------------------- |
|
103
|
|
|
| Main Methods |
|
104
|
|
|
| ----------------------------------------------------------------- |
|
105
|
|
|
*/ |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Make a breadcrumb item instance. |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $title |
|
111
|
|
|
* @param string $url |
|
112
|
|
|
* @param array $data |
|
113
|
|
|
* |
|
114
|
|
|
* @return self |
|
115
|
|
|
*/ |
|
116
|
16 |
|
public static function make($title, $url, array $data = []) |
|
117
|
|
|
{ |
|
118
|
16 |
|
return new self($data + compact('title', 'url')); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Reset position. |
|
123
|
|
|
* |
|
124
|
|
|
* @return self |
|
125
|
|
|
*/ |
|
126
|
22 |
|
public function resetPosition() |
|
127
|
|
|
{ |
|
128
|
22 |
|
$this->attributes['first'] = false; |
|
129
|
22 |
|
$this->attributes['last'] = false; |
|
130
|
|
|
|
|
131
|
22 |
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/* ----------------------------------------------------------------- |
|
135
|
|
|
| Check Methods |
|
136
|
|
|
| ----------------------------------------------------------------- |
|
137
|
|
|
*/ |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Check is first item. |
|
141
|
|
|
* |
|
142
|
|
|
* @return bool |
|
143
|
|
|
*/ |
|
144
|
6 |
|
public function isFirst() |
|
145
|
|
|
{ |
|
146
|
6 |
|
return $this->get('first', false); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Check is last item. |
|
151
|
|
|
* |
|
152
|
|
|
* @return bool |
|
153
|
|
|
*/ |
|
154
|
6 |
|
public function isLast() |
|
155
|
|
|
{ |
|
156
|
6 |
|
return $this->get('last', false); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|