Completed
Push — master ( 1337ee...b15437 )
by Wanderson
01:57
created

BreadCrumb::createLink()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 10
nc 3
nop 1
dl 0
loc 14
rs 9.2
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * BreadCrumbs
5
 * Cria breadcrumbs personalizados
6
 * Exemplo de um breadcrumb: - Página Inicial > Produto > Óculos de Sol
7
 *
8
 */
9
10
namespace Win\Html\Navigation;
11
12
use Win\Mvc\Application;
13
14
class BreadCrumb {
15
16
	private static $text;
17
18
	/**
19
	 * Melhora o BreadCrumb, adicionando Links se possível
20
	 * @param string $breadCrumb apenas texto
21
	 * @return string BreadCrumb com Links
22
	 */
23
	public static function createLink($breadCrumb) {
24
		$app = Application::app();
25
26
		$baseLink = explode('»', $breadCrumb, 2);
27
		if (count($baseLink) > 1) {
28
			if ($app->controller->getAction() != 'index' and trim($baseLink[0]) != 'Página Inicial') {
29
				return '<a href="' . $app->getPage() . '/">' . $baseLink[0] . '</a> » ' . $baseLink[1];
30
			} else {
31
				return '<a href="">' . $baseLink[0] . '</a> » ' . $baseLink[1];
32
			}
33
		} else {
34
			return $breadCrumb;
35
		}
36
	}
37
38
	public static function getLink() {
39
		return static::createLink(static::getText());
40
	}
41
42
	public static function getText() {
43
		return self::$text;
44
	}
45
46
	public static function setText($text) {
47
		self::$text = $text;
48
	}
49
50
}
51