41 public $usePersonalisation =
true;
46 public $htmlCacheKey =
'';
56 public $tagstyles = array();
61 public $tagsSeparator =
', ';
68 public function run($limit = null)
72 if (!empty($this->folderIds)) {
73 sort($this->folderIds);
76 $this->_cleanUp(Yii::app()->user->id);
77 $this->_extractTags($limit);
91 private function _extractTags($limit = null)
93 if (empty($this->data)) {
97 $this->tags = array();
99 foreach ($this->data as $entry) {
100 if (!empty($entry[
'attributes'][
'tagging'])) {
101 $tags = explode($this->tagsSeparator, $entry[
'attributes'][
'tagging']);
103 foreach (
$tags as $tag) {
105 $this->tags[$tag] = empty($this->tags[$tag]) ? 1 : $this->tags[$tag]+1;
110 Yii::trace(
'Tags and usage: '.print_r($this->tags,
true),
'Api requests(start)');
112 if (!empty($this->tags)) {
118 $this->tags = array_slice($this->tags, 0 ,$limit);
121 $tagstylesQty = count($this->tagstyles);
122 $max = max($this->tags);
123 $step = ceil($max / count($this->tagstyles));
125 foreach ($this->tags as $k=>$v) {
126 $index = round($v/$step);
127 $index = $index<=($tagstylesQty-1) ? $index : $index-1;
129 $url = $this->overviewPage;
130 $url .= strpos($url,
'?')!==
false ?
'&tag='.$k :
'?tag='.$k;
131 $url .=
'&folderIds='.str_replace(
'10002.',
'', implode(
',', $this->folderIds));
133 $this->tags[$k] = array(
134 'class' => $this->tagstyles[$index],
150 private function _cleanUp($user_id)
153 $cacheId =
'tagcloud_PERS_'.md5(implode(
',', $this->folderIds).$this->lang.$maxTimestamp.intval($this->usePersonalisation));
154 $this->htmlCacheKey =
'tagcloud_HTML_'.md5(implode(
',', $this->folderIds).implode(
',', $this->tagstyles).$this->lang.$maxTimestamp.intval($this->usePersonalisation).$this->overviewPage.$this->tagsSeparator);
156 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
162 if ($filters && $this->data) {
163 foreach ($this->data as $id=>$contentPage) {
164 if (!is_null($this->_unsetNodes($filters, $user_id, $contentPage))) {
165 $data[$id] = $contentPage;
172 Yii::app()->cache->set($cacheId, $this->data);
187 private function _unsetNodes($filters, $user_id,
$data)
190 $persAttributes = array();
191 foreach ($filters as $filter) {
192 if (!empty(
$data[
'attributes'][$filter])) {
193 $persAttributes = array_merge($persAttributes,
$data[
'attributes'][$filter]);
198 if ($this->usePersonalisation) {
199 if (!Yii::app()->getModule(
'personalisation')->rule->checkAccess($user_id, $persAttributes)) {
215 if (Yii::app()->getModule(
'contentSource')->contentSource->usePersonalisation) {
216 $filters = Yii::app()->getModule(
'contentSource')->contentSource->personalisationFields;
228 private function _loadData()
232 $requertFields = array(
241 $cacheId =
'tagcloud_'.md5(implode(
',', $this->folderIds).$this->lang.$maxTimestamp);
244 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
245 $data = Yii::app()->repositoryApi->request(
247 'filter' =>
'object.obj_type==10007 AND object.languagecode=="'.$this->lang.
'" AND (object.folder_id=="'.implode(
'" OR object.folder_id=="', $this->folderIds).
'")',
254 if (isset(
$data[
'status']) &&
$data[
'status'] ==
'ok') {
255 unset(
$data[
'status']);
259 Yii::app()->cache->set($cacheId,
$data);
273 $timestampCacheId =
'tagcloud_UTS_'.md5(implode(
',', $this->folderIds).$this->lang);
276 if (($maxTimestamp = Yii::app()->cache->get($timestampCacheId)) ===
false) {
278 $timestamps = Yii::app()->repositoryApi->request(
280 'filter' =>
'object.contentid=="'.implode(
'" OR object.contentid=="', $this->folderIds).
'"',
282 'sorting' =>
'updatetimestamp:desc',
286 array(
'updatetimestamp')
288 $timestamps = unserialize($timestamps);
290 if (isset($timestamps[
'status']) && $timestamps[
'status']==
'ok') {
291 unset($timestamps[
'status']);
293 foreach ($timestamps as $id=>$contentFolder) {
294 if (isset($contentFolder[
'attributes'][
'updatetimestamp']) && $contentFolder[
'attributes'][
'updatetimestamp'] > $maxTimestamp) {
295 $maxTimestamp = $contentFolder[
'attributes'][
'updatetimestamp'];
299 Yii::app()->cache->set($timestampCacheId, $maxTimestamp, Yii::app()->getModule(
'tagcloud')->cacheTime);
301 $maxTimestamp =
false;
304 return $maxTimestamp;