Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
HistoryModule.php
1 <?php
2 
3 /**
4  * Gentics Portal.Node PHP
5  * Author & Copyright (c) by Gentics Software GmbH
6  * sales@gentics.com
7  * http://www.gentics.com
8  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
9  * You must not use this software without a valid license agreement.
10  *
11  * HistoryModule
12  * This module allows user to remember pages he was visited
13  *
14  * Interaction with module performs with one widget and one function
15  * Widget:
16  * - LastVisitedPages - displays last N visited pages
17  *
18  * HistoryModule::save() function save specified page to user history
19  * HistoryModule::flushHistory() flush current user history
20  *
21 **/
22 class HistoryModule extends CWebModule
23 {
24 
25  /**
26  * How long history will be storing in cache
27  *
28  * @var string
29  **/
30  public $cacheTime = 3600;
31 
32  /**
33  * If automatically save url to history after each request. In this case page id and page title missed
34  *
35  * @var string
36  **/
37  public $autoSave = false;
38 
39  public function init()
40  {
41  parent::init();
42  $this->setImport(array(
43  'history.models.VisitedHistory'
44  ));
45 
46  if($this->autoSave) {
47  Yii::app()->onEndRequest = array(new VisitedHistory(), 'saveUrlToHistory');
48  }
49  }
50 
51  /**
52  * When this function invokes it saves specified page to user history
53  *
54  * @return void
55  * @author Me
56  **/
57  public function save($url, $title, $page_id, $collection_id = null)
58  {
59  VisitedHistory::addItem($url, $title, $page_id, $collection_id);
60  }
61 
62  /**
63  * Current collection id
64  *
65  * @return string
66  **/
67  public function getCollectionId()
68  {
70  }
71 
72  /**
73  * Flush(clear) user history
74  * @param string $collection_id id of collection which to flush. If empty then current user history will flushed
75  *
76  * @return void
77  **/
78  public function flushHistory($collection_id = null)
79  {
80  VisitedHistory::flush($collection_id);
81  }
82 
83  /**
84  * Translates a message to the specified language.
85  *
86  * @param string $str message
87  * @param array $params params
88  * @param string $dic dictionary
89  *
90  * @return string
91  */
92  public static function t($str = '', $params = array(), $dic = 'core')
93  {
94  return Yii::t("HistoryModule." . $dic, $str, $params);
95  }
96 }