/
nav_item.php
163 lines (146 loc) · 3.63 KB
/
nav_item.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace Concrete\Block\Autonav;
/**
* An object used by the Autonav Block to display navigation items in a tree.
*/
class NavItem
{
protected $level;
protected $isActive = false;
protected $_c;
public $hasChildren = false;
public $cID;
public $cPath;
public $cPointerExternalLink;
public $cPointerExternalLinkNewWindow;
public $cvDescription;
public $cvName;
/**
* Instantiates an Autonav Block Item.
*
* @param array $itemInfo
* @param int $level
*/
public function __construct($itemInfo, $level = 1)
{
$this->level = $level;
if (is_array($itemInfo)) {
// this is an array pulled from a separate SQL query
foreach ($itemInfo as $key => $value) {
$this->{$key} = $value;
}
}
return $this;
}
/**
* Returns the number of children below this current nav item.
*
* @return int
*/
public function hasChildren()
{
return $this->hasChildren;
}
/**
* Determines whether this nav item is the current page the user is on.
*
* @param \Concrete\Core\Page\Page $c The page object for the current page
*
* @return bool
*/
public function isActive(&$c)
{
if ($c) {
$cID = ($c->getCollectionPointerID() > 0) ? $c->getCollectionPointerOriginalID() : $c->getCollectionID();
return $cID == $this->cID;
}
}
/**
* Returns the description of the current navigation item (typically grabbed from the page's short description field).
*
* @return string
*/
public function getDescription()
{
return $this->cvDescription;
}
/**
* Returns a target for the nav item.
*/
public function getTarget()
{
if ($this->cPointerExternalLink != '') {
if ($this->cPointerExternalLinkNewWindow) {
return '_blank';
}
}
$_c = $this->getCollectionObject();
if (is_object($_c)) {
return $_c->getAttribute('nav_target');
}
return '';
}
/**
* Gets a URL that will take the user to this particular page. Checks against concrete.seo.url_rewriting, the page's path, etc..
*
* @return string $url
*/
public function getURL()
{
if ($this->cPointerExternalLink != '') {
$link = $this->cPointerExternalLink;
} elseif ($this->cPath) {
$link = $this->cPath;
} elseif ($this->cID == HOME_CID) {
$link = DIR_REL . '/';
} else {
$link = DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $this->cID;
}
return $link;
}
/**
* Gets the name of the page or link.
*
* @return string
*/
public function getName()
{
return $this->cvName;
}
/**
* Gets the pageID for the navigation item.
*
* @return int
*/
public function getCollectionID()
{
return $this->cID;
}
/**
* Gets the current level at the nav tree that we're at.
*
* @return int
*/
public function getLevel()
{
return $this->level;
}
/**
* Sets the collection Object of the navigation item to the passed object.
*
* @param \Concrete\Core\Page\Page $obj
*/
public function setCollectionObject(&$obj)
{
$this->_c = $obj;
}
/**
* Gets the collection Object of the navigation item.
*
* @return \Concrete\Core\Page\Page
*/
public function getCollectionObject()
{
return $this->_c;
}
}