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 $excludeURLs = Yii::app()->getModule(
'personalizedContent')->excludeURLs;
140 if ((isset(
$data[
'attributes'][
'url']) && in_array(
$data[
'attributes'][
'url'], $excludeURLs)) || !isset(
$data[
'attributes'][
'url'])) {
145 if ($this->usePersonalisation) {
146 if (!Yii::app()->getModule(
'personalisation')->rule->checkAccess($user_id, $persAttributes)) {
162 if (Yii::app()->getModule(
'contentSource')->contentSource->usePersonalisation) {
163 $filters = Yii::app()->getModule(
'contentSource')->contentSource->personalisationFields;
175 private function _loadData()
180 $this->gccRequestParams = rtrim($this->gccRequestParams,
',');
181 $requertFields = explode(
',', $this->gccRequestParams);
183 $requertFields[] =
'updatetimestamp';
184 $requertFields[] =
'name';
185 $requertFields[] =
'url';
187 $requertFields = array_unique($requertFields);
193 $cacheId =
'persContent_'.md5(implode(
',', $this->folderIds).$this->lang.$this->gccRequestParams.$maxTimestamp.$this->tag);
196 if ((
$data = Yii::app()->cache->get($cacheId)) ===
false) {
198 '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).
'")',
200 'sorting' => $this->sorting,
203 if (!empty($this->tag)) {
204 $params[
'filter'] .=
'AND object.tagging LIKE "*'.$this->tag.
'*"';
207 $params = Yii::app()->getComponent(
'repositoryApi')->addAdditionalParameters($params,
'contentRepositorySearch');
209 $data = Yii::app()->repositoryApi->request(
215 if (isset(
$data[
'status']) &&
$data[
'status'] ==
'ok') {
216 unset(
$data[
'status']);
221 Yii::app()->cache->set($cacheId,
$data);
234 $timestampCacheId =
'persContent_UTS_'.md5(implode(
',', $this->folderIds).$this->lang.$this->gccRequestParams.$this->sorting.$this->tag);
237 if (($maxTimestamp = Yii::app()->cache->get($timestampCacheId)) ===
false) {
239 '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).
'")',
241 'sorting' => $this->sorting,
243 if (!empty($this->tag)) {
244 $params[
'filter'] .=
'AND object.tagging LIKE "*'.$this->tag.
'*"';
247 $params = Yii::app()->getComponent(
'repositoryApi')->addAdditionalParameters($params,
'contentRepositorySearch');
249 $timestamps = Yii::app()->repositoryApi->request(
251 array(
'updatetimestamp')
253 $timestamps = unserialize($timestamps);
255 if (isset($timestamps[
'status']) && $timestamps[
'status']==
'ok') {
256 unset($timestamps[
'status']);
258 foreach ($timestamps as $id=>$contentFolder) {
259 if (isset($contentFolder[
'attributes'][
'updatetimestamp']) && $contentFolder[
'attributes'][
'updatetimestamp'] > $maxTimestamp) {
260 $maxTimestamp = $contentFolder[
'attributes'][
'updatetimestamp'];
264 Yii::app()->cache->set($timestampCacheId, $maxTimestamp, Yii::app()->getModule(
'personalizedContent')->cacheTime);
266 $maxTimestamp =
false;
269 return $maxTimestamp;