@@ 13-51 (lines=39) @@ | ||
10 | * @author PyroCMS, Inc. <[email protected]> |
|
11 | * @author Ryan Thompson <[email protected]> |
|
12 | */ |
|
13 | class NavigationCollection extends Collection |
|
14 | { |
|
15 | ||
16 | /** |
|
17 | * Return the active link. |
|
18 | * |
|
19 | * @return null|NavigationLinkInterface |
|
20 | */ |
|
21 | public function active() |
|
22 | { |
|
23 | /* @var NavigationLinkInterface $item */ |
|
24 | foreach ($this->items as $item) { |
|
25 | if ($item->isActive()) { |
|
26 | return $item; |
|
27 | } |
|
28 | } |
|
29 | ||
30 | return null; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get a navigation link. |
|
35 | * |
|
36 | * @param mixed $key |
|
37 | * @param null $default |
|
38 | * @return NavigationLinkInterface |
|
39 | */ |
|
40 | public function get($key, $default = null) |
|
41 | { |
|
42 | /* @var NavigationLinkInterface $item */ |
|
43 | foreach ($this->items as $item) { |
|
44 | if ($item->getSlug() == $key) { |
|
45 | return $item; |
|
46 | } |
|
47 | } |
|
48 | ||
49 | return $default ? $this->get($default) : null; |
|
50 | } |
|
51 | } |
|
52 |
@@ 13-50 (lines=38) @@ | ||
10 | * @author PyroCMS, Inc. <[email protected]> |
|
11 | * @author Ryan Thompson <[email protected]> |
|
12 | */ |
|
13 | class ViewCollection extends Collection |
|
14 | { |
|
15 | ||
16 | /** |
|
17 | * Return the active view or null. |
|
18 | * |
|
19 | * @return null|ViewInterface |
|
20 | */ |
|
21 | public function active() |
|
22 | { |
|
23 | /* @var ViewInterface $item */ |
|
24 | foreach ($this->items as $item) { |
|
25 | if ($item->isActive()) { |
|
26 | return $item; |
|
27 | } |
|
28 | } |
|
29 | ||
30 | return null; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Find a view by it's slug. |
|
35 | * |
|
36 | * @param $slug |
|
37 | * @return null|ViewInterface |
|
38 | */ |
|
39 | public function findBySlug($slug) |
|
40 | { |
|
41 | /* @var ViewInterface $item */ |
|
42 | foreach ($this->items as $item) { |
|
43 | if ($item->getSlug() == $slug) { |
|
44 | return $item; |
|
45 | } |
|
46 | } |
|
47 | ||
48 | return null; |
|
49 | } |
|
50 | } |
|
51 |