10 public static function saveUrlToHistory($event)
12 self::addItem(Yii::app()->request->getUrl());
15 public static function getCacheKey($collection_id){
17 return md5($collection_id .
"_history_url");
20 public static function addItem($url, $title = null, $page_id = null, $collection_id = null)
22 if ($collection_id === null) {
25 $key = self::getCacheKey($collection_id);
26 $userHistory = Yii::app()->cache->get($key);
27 if($userHistory ===
false){
28 $userHistory = array();
31 foreach($userHistory as $k => $uh){
32 if ($uh[
'url'] == $url){
33 $userHistory[$k][
'timestamp'] = time();
38 $userHistory[] = array(
'url' => $url,
'title' => $title,
'page_id' => $page_id,
'collection_id' => $collection_id,
'timestamp' => time());
40 Yii::app()->cache->set($key, $userHistory, Yii::app()->getModule(
'history')->cacheTime);
43 public static function getItems($collection_id = null, $count = null)
45 if ($collection_id === null) {
48 $key = md5($collection_id .
"_history_url");
49 $userHistory = Yii::app()->cache->get($key);
50 if($userHistory ===
false){
54 foreach ($userHistory as $key => $val) {
55 $time[$key] = $val[
'timestamp'];
57 array_multisort($time, SORT_ASC, $userHistory);
60 $count = count($userHistory);
62 return array_slice(array_reverse($userHistory),0,$count);
72 public static function flush($collection_id = null)
74 if ($collection_id === null) {
77 $key = md5($collection_id .
"_history_url");
78 $userHistory = Yii::app()->cache->delete($key);
88 return Yii::app()->user->isGuest ? Yii::app()->session->getSessionId() : Yii::app()->user->id;