23 public $gccRequestParams;
50 public $usePersonalisation =
true;
61 public function __construct($folderIds = array(), $usePersonalisation =
true, $tag =
'', $gccRequestParams = null, $sorting = null)
66 if (!empty($folderIds)) {
68 $this->lang = substr(Yii::app()->language, 0, 2);
69 $this->gccRequestParams = isset($gccRequestParams)? $gccRequestParams : Yii::app()->getModule(
'personalizedContent')->gccRequestParams;
70 $this->sorting = isset($sorting)? $sorting : Yii::app()->getModule(
'personalizedContent')->sorting;
71 $this->usePersonalisation = $usePersonalisation;
74 $this->folderIds = $folderIds;
75 sort($this->folderIds);
78 $this->_cleanUp(Yii::app()->user->id);
92 private function _cleanUp($user_id)
95 $cacheId =
'persContent_PERS_'.md5(implode(
',', $this->folderIds).$this->lang.$this->gccRequestParams.$this->sorting.$maxTimestamp.$this->tag);
97 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
103 if ($filters && $this->data) {
104 foreach ($this->data as $id=>$contentPage) {
105 if (!is_null($this->_unsetNodes($filters, $user_id, $contentPage))) {
106 $data[$id] = $contentPage;
113 Yii::app()->cache->set($cacheId, $this->data);
128 private function _unsetNodes($filters, $user_id,
$data)
131 $persAttributes = array();
132 foreach ($filters as $filter) {
133 if (!empty(
$data[
'attributes'][$filter])) {
134 $persAttributes = array_merge($persAttributes,
$data[
'attributes'][$filter]);
139 if (
$data[
'contentid'] != in_array(
$data[
'contentid'], $this->folderIds)) {
140 $excludeURLs = Yii::app()->getModule(
'personalizedContent')->excludeURLs;
141 if ((isset(
$data[
'attributes'][
'url']) && in_array(
$data[
'attributes'][
'url'], $excludeURLs)) || !isset(
$data[
'attributes'][
'url'])) {
147 if ($this->usePersonalisation) {
148 if (!Yii::app()->getModule(
'personalisation')->rule->checkAccess($user_id, $persAttributes)) {
164 if (Yii::app()->getModule(
'contentSource')->contentSource->usePersonalisation) {
165 $filters = Yii::app()->getModule(
'contentSource')->contentSource->personalisationFields;
177 private function _loadData()
182 $this->gccRequestParams = rtrim($this->gccRequestParams,
',');
183 $requertFields = explode(
',', $this->gccRequestParams);
185 $requertFields[] =
'updatetimestamp';
186 $requertFields[] =
'name';
187 $requertFields[] =
'url';
189 $requertFields = array_unique($requertFields);
195 $cacheId =
'persContent_'.md5(implode(
',', $this->folderIds).$this->lang.$this->gccRequestParams.$maxTimestamp.$this->tag);
198 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
200 'filter' =>
'object.obj_type==10007 AND object.hideinoverview != 1 AND object.languagecode=="'.$this->lang.
'" AND (object.folder_id=="'.implode(
'" OR object.folder_id=="', $this->folderIds).
'")',
202 'sorting' => $this->sorting,
205 if (!empty($this->tag)) {
206 $params[
'filter'] .=
'AND object.tagging LIKE "*'.$this->tag.
'*"';
209 $params = Yii::app()->getComponent(
'repositoryApi')->addAdditionalParameters($params,
'contentRepositorySearch');
211 $data = Yii::app()->repositoryApi->request(
217 if (isset(
$data[
'status']) &&
$data[
'status'] ==
'ok') {
218 unset(
$data[
'status']);
223 Yii::app()->cache->set($cacheId,
$data);
236 $timestampCacheId =
'persContent_UTS_'.md5(implode(
',', $this->folderIds).$this->lang.$this->gccRequestParams.$this->sorting.$this->tag);
239 if (($maxTimestamp = Yii::app()->cache->get($timestampCacheId)) ===
false) {
241 'filter' =>
'object.obj_type==10007 AND object.hideinoverview != 1 AND object.languagecode=="'.$this->lang.
'" AND (object.folder_id=="'.implode(
'" OR object.folder_id=="', $this->folderIds).
'")',
243 'sorting' => $this->sorting,
245 if (!empty($this->tag)) {
246 $params[
'filter'] .=
'AND object.tagging LIKE "*'.$this->tag.
'*"';
249 $params = Yii::app()->getComponent(
'repositoryApi')->addAdditionalParameters($params,
'contentRepositorySearch');
251 $timestamps = Yii::app()->repositoryApi->request(
253 array(
'updatetimestamp')
255 $timestamps = unserialize($timestamps);
257 if (isset($timestamps[
'status']) && $timestamps[
'status']==
'ok') {
258 unset($timestamps[
'status']);
260 foreach ($timestamps as $id=>$contentFolder) {
261 if (isset($contentFolder[
'attributes'][
'updatetimestamp']) && $contentFolder[
'attributes'][
'updatetimestamp'] > $maxTimestamp) {
262 $maxTimestamp = $contentFolder[
'attributes'][
'updatetimestamp'];
266 Yii::app()->cache->set($timestampCacheId, $maxTimestamp, Yii::app()->getModule(
'personalizedContent')->cacheTime);
268 $maxTimestamp =
false;
271 return $maxTimestamp;