47 public $usePersonalisation =
true;
49 public function getTreeCacheTime()
51 return Yii::app()->getModule(
'navigation')->cacheTime;
54 public function getLatestUpdateTimestampCacheTime()
56 return Yii::app()->getModule(
'navigation')->timestampCacheTime;
62 public $additionalParams = array();
67 public $sortby =
"sortorder:asc";
80 $this->lang = substr(Yii::app()->language, 0, 2);
84 $this->additionalParams = $additionalParams;
85 if ($sortby === null) {
86 $this->sortby = Yii::app()->getModule(
'navigation')->sortorder;
88 $this->sortby = $sortby;
92 $this->_loadActivePath();
106 public function cleanUp($user_id, $usePersonalisation =
true)
111 $this->usePersonalisation = $usePersonalisation;
116 if ($filters &&
$data) {
117 $data = $this->_unsetNodes($filters, $user_id,
$data);
132 $defaultUrl = Yii::app()->getModule(
'navigation')->startpage_url;
133 $startpage_url_prefix = Yii::app()->getModule(
'navigation')->startpage_url_prefix;
135 if (isset($item[
'attributes'][$startpage_url_prefix . $lang])
136 && !empty($item[
'attributes'][$startpage_url_prefix . $lang])) {
137 $startpageUrl = $item[
'attributes'][$startpage_url_prefix . $lang];
138 }
else if (isset($item[
'attributes'][
'startpageurl']) && !empty($item[
'attributes'][
'startpageurl'])) {
139 $startpageUrl = $item[
'attributes'][
'startpageurl'];
141 $startpageUrl = $defaultUrl;
143 return $startpageUrl;
155 $defaultName = Yii::app()->getModule(
'navigation')->branch_name;
156 $name_prefix = Yii::app()->getModule(
'navigation')->name_prefix;
158 if (isset($item[
'attributes'][$name_prefix . $lang]) && !empty($item[
'attributes'][$name_prefix . $lang])) {
159 $name = $item[
'attributes'][$name_prefix . $lang];
160 }
else if(isset($item[
'attributes'][
'name']) && !empty($item[
'attributes'][
'name'])) {
161 $name = $item[
'attributes'][
'name'];
163 $name = $defaultName;
177 private function _unsetNodes($filters, $user_id,
$data)
180 $persAttributes = array();
181 foreach ($filters as $filter) {
182 if (!empty(
$data[
'attributes'][$filter])) {
183 $persAttributes = array_merge($persAttributes,
$data[
'attributes'][$filter]);
188 if (
$data[
'contentid'] != $this->startfolderId) {
191 $excludeURLs = Yii::app()->getModule(
'navigation')->excludeURLs;
193 if (empty($startpageUrl) || in_array($startpageUrl, $excludeURLs)) {
199 if ($this->usePersonalisation && !Yii::app()->getModule(
'personalisation')->rule->checkAccess($user_id, $persAttributes)) {
202 }
else if (isset(
$data[
'children'])) {
204 foreach (
$data[
'children'] as $kChild => $child) {
205 $data[
'children'][$kChild] = $this->_unsetNodes($filters, $user_id, $child);
206 if (is_null(
$data[
'children'][$kChild])) {
207 unset(
$data[
'children'][$kChild]);
210 if (count(
$data[
'children']) == 0) {
211 unset(
$data[
'children']);
224 if (Yii::app()->getModule(
'contentSource')->contentSource->usePersonalisation) {
225 $filters = Yii::app()->getModule(
'contentSource')->contentSource->personalisationFields;
237 private function _loadData()
240 global $navigationCache;
252 $sysLangs = Yii::app()->getModule(
'language')->languages;
253 if (empty($sysLangs[$this->lang])) {
254 $sysLangs[$this->lang] = $this->lang;
257 $requestFields = array(
266 foreach ($sysLangs as $lang) {
267 $requestFields[] =
'name_' . $lang;
268 $requestFields[] =
'startpageurl_' . $lang;
271 $requestFields = array_merge($requestFields,$this->additionalParams);
273 $cacheId =
'navigation_'.$this->startfolderId.
'&langs='.serialize($sysLangs);
274 $updateTimestamp = $this->_getYoungestTimestamp($this->startfolderId, $cacheId);
275 $cacheId .= $updateTimestamp;
280 if (isset( $navigationCache[$cacheId])) {
281 $data = $navigationCache[$cacheId];
285 $data = Yii::app()->cache->get($cacheId);
289 if (
$data !==
false) {
290 if ( $compress ==
true )
$data = unserialize( gzuncompress(
$data ) );
292 $navigationCache[$cacheId] =
$data;
296 if (
$data ===
false) {
299 $filtersList = implode(
',', $filters);
302 $data = Yii::app()->repositoryApi->requestNavigation(
304 'rootfilter' =>
'object.contentid=="'.$this->startfolderId.
'"',
305 'sorting' => $this->sortby,
306 'navigation' =>
'true',
307 'childfilter' =>
'object.obj_type==10002 AND object.navhidden!=1',
310 CMap::mergeArray($this->getFiltersList(), $requestFields)
313 if ( $compress ==
true )
314 $cachedata = gzcompress(
$data, 9 );
316 $cachedata = unserialize(
$data );
320 Yii::app()->cache->set($cacheId, $cachedata, $this->getTreeCacheTime());
329 private function _getYoungestTimestamp($objectId, $objectCacheId)
331 $cacheId =
'youngest_' . $objectCacheId;
332 if (($updateTimestamp = Yii::app()->cache->get($cacheId)) ==
false) {
333 $updateTimestamp = Yii::app()->repositoryApi->requestNavigation(
335 "rootfilter" =>
'object.contentid=="' . $objectId .
'"',
336 "type" =>
"youngest",
337 "childfilter" =>
"object.obj_type==10002 AND object.navhidden!=1"
341 Yii::app()->cache->set($cacheId, $updateTimestamp, $this->getLatestUpdateTimestampCacheTime());
344 return $updateTimestamp;
352 private function _loadActivePath()
357 $cacheId = Yii::app()->cache->get(
"navigation_version").
'activePath_' . $this->startfolderId .
'_' .
$this->activeElement;
360 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
361 if (!empty($this->activeElement)) {
362 $data = Yii::app()->repositoryApi->requestActivePath(
364 'root' => $this->startfolderId,
365 'filter' =>
'object.contentid=="'.$this->activeElement.
'"',
371 unset(
$data[
'status']);
377 Yii::app()->cache->set($cacheId,
$data, $this->getTreeCacheTime());
378 Yii::trace(
'active path for element ' . $this->activeElement .
' putted to cache',
'test');
380 Yii::trace(
'active path for element ' . $this->activeElement .
' taken from cache',
'test');
383 $this->activePath =
$data;
399 if ( isset( $navigationCache[$cacheId] ) ) {
400 $data = $navigationCache[$cacheId];
420 if ($node[
'contentid'] == $contentId) {
422 } elseif (!empty($node[
'children'])) {
423 foreach ($node[
'children'] as $childNode) {
424 if ($searchedNode = self::extractBranch($childNode, $contentId)) {
425 return $searchedNode;