Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
PreviewController.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  *
11  * @author Vitalii Kovalchuk <vitaly.kovalchuk@oberig.com>
12  */
13 
14 /**
15  * PersonalizedContent controller class
16  *
17  * @author Vitalii Kovalchuk <vitaly.kovalchuk@oberig.com>
18  *
19  */
20 class PreviewController extends Controller
21 {
22 
23  /**
24  * default action used to show widget preview
25  *
26  * @return void
27  *
28  * @throws Exception
29  */
30  public function actionIndex()
31  {
32  $folderIds = Yii::app()->request->getQuery('folderIds', null);
33  $pageId = Yii::app()->request->getQuery('pageId', null);
34  $usePersonalisation = Yii::app()->request->getQuery('usePersonalisation', 'Y');
35  $lang = Yii::app()->request->getQuery('lang', null);
36 
37  if (empty($folderIds)) {
38  throw new Exception(PersonalizedContentModule::t('PersonalizedContentPreview error: folderIds is required and can`t be blank'));
39  } else if (empty($pageId)) {
40  throw new Exception(PersonalizedContentModule::t('PersonalizedContentPreview error: pageId is required and can`t be blank'));
41  }
42 
43  if (empty($lang)) {
44  $lang = substr(Yii::app()->language, 0, 2);
45  }
46 
47  $folderIds = explode(',', $folderIds);
48  foreach ($folderIds as &$folderId) {
49  $folderId = '10002.'.intval($folderId);
50  }
51 
52  $data = Yii::app()->repositoryApi->request(
53  array(
54  'filter' => 'object.languagecode=="'.$lang.'" AND object.contentid=='.$pageId,
55  'type' => 'php',
56  ),
57  array('content')
58  );
59  $data = unserialize($data);
60 
61  $tplString = !empty($data[$pageId]['attributes']['content']) ? $data[$pageId]['attributes']['content'] : '';
62  /*$tplString = '<div class="personalized-content-item">
63  <a href="{{url}}">{{name}}</a>
64  <br/>
65  <a href="{{url}}">{{url}}</a>
66  <br/>
67  <span>{{content}}</span>
68  date:{{date}}<br/>
69  time:{{time}}<br/>
70  datetime:{{datetime}}<br/>
71  </div>';*/
72 
73  if (empty($tplString)) {
74  throw new Exception(PersonalizedContentModule::t('PersonalizedContentPreview error: could not load tplString from GCC or it is empty'));
75  }
76 
77  $this->widget(
78  'personalizedContent.widgets.PersonalizedContentWidget',
79  array(
80  'folderIds'=>$folderIds,
81  'tplString'=>$tplString,
82  'usePersonalisation'=>($usePersonalisation == 'Y' ? true : false)
83  )
84  );
85  }
86 }