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 $this->sortby = $sortby;
87 $this->_loadActivePath();
99 public function cleanUp($user_id, $usePersonalisation =
true)
104 $this->usePersonalisation = $usePersonalisation;
109 if ($filters &&
$data) {
110 $data = $this->_unsetNodes($filters, $user_id,
$data);
125 private function _unsetNodes($filters, $user_id,
$data)
128 $persAttributes = array();
129 foreach ($filters as $filter) {
130 if (!empty(
$data[
'attributes'][$filter])) {
131 $persAttributes = array_merge($persAttributes,
$data[
'attributes'][$filter]);
136 if (
$data[
'contentid'] != $this->startfolderId) {
137 $excludeURLs = Yii::app()->getModule(
'navigation')->excludeURLs;
140 $startpageUrl = isset(
$data[
'attributes'][
'startpageurl_' . $this->lang]) ?
$data[
'attributes'][
'startpageurl_' . $this->lang] : (isset(
$data[
'attributes'][
'startpageurl']) ?
$data[
'attributes'][
'startpageurl'] :
'');
143 if (empty($startpageUrl) || in_array($startpageUrl, $excludeURLs)) {
149 if ($this->usePersonalisation && !Yii::app()->getModule(
'personalisation')->rule->checkAccess($user_id, $persAttributes)) {
152 }
else if (isset(
$data[
'children'])) {
154 foreach (
$data[
'children'] as $kChild => $child) {
155 $data[
'children'][$kChild] = $this->_unsetNodes($filters, $user_id, $child);
156 if (is_null(
$data[
'children'][$kChild])) {
157 unset(
$data[
'children'][$kChild]);
160 if (count(
$data[
'children']) == 0) {
161 unset(
$data[
'children']);
174 if (Yii::app()->getModule(
'contentSource')->contentSource->usePersonalisation) {
175 $filters = Yii::app()->getModule(
'contentSource')->contentSource->personalisationFields;
187 private function _loadData()
189 $sysLangs = Yii::app()->getModule(
'language')->languages;
190 if (empty($sysLangs[$this->lang])) {
191 $sysLangs[$this->lang] = $this->lang;
194 $requestFields = array(
203 foreach ($sysLangs as $lang) {
204 $requestFields[] =
'name_' . $lang;
205 $requestFields[] =
'startpageurl_' . $lang;
208 $requestFields = array_merge($requestFields,$this->additionalParams);
210 $cacheId =
'navigation_'.$this->startfolderId.
'&langs='.serialize($sysLangs);
211 $updateTimestamp = $this->_getYoungestTimestamp($this->startfolderId, $cacheId);
212 $cacheId .= $updateTimestamp;
217 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
219 $filtersList = implode(
',', $filters);
222 $data = Yii::app()->repositoryApi->requestNavigation(
224 'rootfilter' =>
'object.contentid=="'.$this->startfolderId.
'"',
225 'sorting' => $this->sortby,
226 'navigation' =>
'true',
227 'childfilter' =>
'object.obj_type==10002 AND object.navhidden!=1',
230 CMap::mergeArray($this->getFiltersList(), $requestFields)
234 Yii::app()->cache->set($cacheId,
$data, $this->getTreeCacheTime());
243 private function _getYoungestTimestamp($objectId, $objectCacheId)
245 $cacheId =
'youngest_' . $objectCacheId;
246 if (($updateTimestamp = Yii::app()->cache->get($cacheId)) ==
false) {
247 $updateTimestamp = Yii::app()->repositoryApi->requestNavigation(
249 "filter" =>
'object.contentid=="' . $objectId .
'"',
252 array(
"updatetimestamp")
254 Yii::app()->cache->set($cacheId, $updateTimestamp, $this->getLatestUpdateTimestampCacheTime());
257 return $updateTimestamp;
265 private function _loadActivePath()
270 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
271 if (!empty($this->activeElement)) {
272 $data = Yii::app()->repositoryApi->requestActivePath(
274 'root' => $this->startfolderId,
275 'filter' =>
'object.contentid=="'.$this->activeElement.
'"',
281 unset(
$data[
'status']);
287 Yii::app()->cache->set($cacheId,
$data, $this->getTreeCacheTime());
288 Yii::trace(
'active path for element ' . $this->activeElement .
' putted to cache',
'test');
290 Yii::trace(
'active path for element ' . $this->activeElement .
' taken from cache',
'test');
293 $this->activePath =
$data;
307 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
324 if ($node[
'contentid'] == $contentId) {
326 } elseif (!empty($node[
'children'])) {
327 foreach ($node[
'children'] as $childNode) {
328 if ($searchedNode = self::extractBranch($childNode, $contentId)) {
329 return $searchedNode;