@@ 71-161 (lines=91) @@ | ||
68 | * Return array with users wich last activity was less then 2 minutes ago |
|
69 | * @return boolean |
|
70 | */ |
|
71 | public function getOnline() { |
|
72 | $locale = MY_Controller::getCurrentLocale(); |
|
73 | $query = " |
|
74 | SELECT |
|
75 | `mod_stats_attendance`.`id_user`, |
|
76 | `mod_stats_attendance`.`type_id`, |
|
77 | `mod_stats_attendance`.`id_entity`, |
|
78 | IF (`mod_stats_attendance`.`id_user` < 0, 'Guest', `users`.`username`) as `username`, |
|
79 | IF (`mod_stats_attendance`.`id_user` < 0, '', `users`.`email`) as `email`, |
|
80 | FROM_UNIXTIME(`mod_stats_attendance`.`time_add`) as `last_activity`, |
|
81 | ||
82 | -- ---- for urls ---- |
|
83 | route.url AS `last_url`, |
|
84 | -- ------------------ |
|
85 | ||
86 | -- ---- for names ---- |
|
87 | CASE `mod_stats_attendance`.`type_id` |
|
88 | WHEN 1 |
|
89 | THEN IF(route.parent_url <> '', concat(route.parent_url, '/', route.url), route.url) |
|
90 | WHEN 2 |
|
91 | THEN IF(route.parent_url <> '', concat(route.parent_url, '/', route.url), route.url) |
|
92 | WHEN 3 |
|
93 | THEN `shop_category_i18n`.`name` |
|
94 | WHEN 4 |
|
95 | THEN `shop_products_i18n`.`name` |
|
96 | END as `page_name` |
|
97 | -- ------------------ |
|
98 | FROM |
|
99 | (SELECT * FROM `mod_stats_attendance` ORDER BY `id` DESC) as `mod_stats_attendance` |
|
100 | LEFT JOIN `users` ON `users`.`id` = `mod_stats_attendance`.`id_user` |
|
101 | ||
102 | -- ---- for urls ---- |
|
103 | LEFT JOIN `content` ON `content`.`id` = `mod_stats_attendance`.`id_entity` |
|
104 | AND `mod_stats_attendance`.`type_id` = 1 |
|
105 | LEFT JOIN `category` ON `category`.`id` = `mod_stats_attendance`.`id_entity` |
|
106 | AND `mod_stats_attendance`.`type_id` = 2 |
|
107 | LEFT JOIN `shop_category` ON `shop_category`.`id` = `mod_stats_attendance`.`id_entity` |
|
108 | AND `mod_stats_attendance`.`type_id` = 3 |
|
109 | LEFT JOIN `shop_products` ON `shop_products`.`id` = `mod_stats_attendance`.`id_entity` |
|
110 | AND `mod_stats_attendance`.`type_id` = 4 |
|
111 | -- ------------------ |
|
112 | ||
113 | -- ---- for names ---- |
|
114 | LEFT JOIN `shop_category_i18n` ON `shop_category`.`id` = `shop_category_i18n`.`id` |
|
115 | AND `shop_category_i18n`.`locale` = '{$locale}' |
|
116 | LEFT JOIN `shop_products_i18n` ON `shop_products`.`id` = `shop_products_i18n`.`id` |
|
117 | AND `shop_products_i18n`.`locale` = '{$locale}' |
|
118 | -- ------------------ |
|
119 | ||
120 | LEFT JOIN route ON route.entity_id = `mod_stats_attendance`.id_entity AND type = ( |
|
121 | CASE `mod_stats_attendance`.`type_id` |
|
122 | WHEN 1 |
|
123 | THEN 'page' |
|
124 | WHEN 2 |
|
125 | THEN 'category' |
|
126 | WHEN 3 |
|
127 | THEN 'shop_category' |
|
128 | WHEN 4 |
|
129 | THEN 'product' |
|
130 | END |
|
131 | ) |
|
132 | ||
133 | WHERE 1 |
|
134 | AND FROM_UNIXTIME(`mod_stats_attendance`.`time_add`) >= NOW() - INTERVAL 120 SECOND |
|
135 | GROUP BY |
|
136 | `mod_stats_attendance`.`id_user` |
|
137 | ORDER BY |
|
138 | `mod_stats_attendance`.`id` DESC |
|
139 | "; |
|
140 | ||
141 | $results = $this->db->query($query); |
|
142 | ||
143 | if ($results) { |
|
144 | $results = $results->result_array(); |
|
145 | foreach ($results as &$result) { |
|
146 | if ($result['type_id'] == Attendance::PAGE) { |
|
147 | $result['last_url'] = $this->getUrl($result['id_entity'], \core\models\Route::TYPE_PAGE); |
|
148 | } elseif ($result['type_id'] == Attendance::CATEGORY) { |
|
149 | $result['last_url'] = $this->getUrl($result['id_entity'], \core\models\Route::TYPE_CATEGORY); |
|
150 | } elseif ($result['type_id'] == Attendance::SHOP_CATEGORY) { |
|
151 | $result['last_url'] = $this->getUrl($result['id_entity'], \core\models\Route::TYPE_SHOP_CATEGORY); |
|
152 | } elseif ($result['type_id'] == Attendance::PRODUCT) { |
|
153 | $result['last_url'] = $this->getUrl($result['id_entity'], \core\models\Route::TYPE_PRODUCT); |
|
154 | } |
|
155 | } |
|
156 | ||
157 | return $results; |
|
158 | } |
|
159 | ||
160 | return false; |
|
161 | } |
|
162 | ||
163 | protected function getUrl($id, $type) { |
|
164 | $urlConfiguration = \core\src\CoreFactory::getConfiguration()->getUrlRules(); |
@@ 54-126 (lines=73) @@ | ||
51 | * |
|
52 | * @return int |
|
53 | */ |
|
54 | public function getLastViewedPage() { |
|
55 | $locale = MY_Controller::getCurrentLocale(); |
|
56 | ||
57 | $query |
|
58 | = " |
|
59 | SELECT |
|
60 | `users`.`username`, |
|
61 | `type_id`, |
|
62 | `route`.`type`, |
|
63 | `id_entity`, |
|
64 | (CASE `mod_stats_attendance`.`type_id` |
|
65 | WHEN 1 THEN `content`.`title` |
|
66 | WHEN 2 THEN `category`.`name` |
|
67 | WHEN 3 THEN `shop_category_i18n`.`name` |
|
68 | WHEN 4 THEN `shop_products_i18n`.`name` |
|
69 | END) AS `page_name` |
|
70 | FROM |
|
71 | `mod_stats_attendance` |
|
72 | LEFT JOIN |
|
73 | route |
|
74 | ON |
|
75 | route.entity_id = mod_stats_attendance.id_entity |
|
76 | LEFT JOIN |
|
77 | `content` |
|
78 | ON |
|
79 | `content`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 1 |
|
80 | LEFT JOIN |
|
81 | `category` |
|
82 | ON |
|
83 | `category`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 2 |
|
84 | LEFT JOIN |
|
85 | `shop_category` |
|
86 | ON |
|
87 | `shop_category`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 3 |
|
88 | LEFT JOIN |
|
89 | `shop_products` |
|
90 | ON |
|
91 | `shop_products`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 4 |
|
92 | LEFT JOIN |
|
93 | `shop_category_i18n` |
|
94 | ON |
|
95 | `shop_category`.`id` = `shop_category_i18n`.`id` AND `shop_category_i18n`.`locale` = '{$locale}' |
|
96 | LEFT JOIN |
|
97 | `shop_products_i18n` |
|
98 | ON |
|
99 | `shop_products`.`id` = `shop_products_i18n`.`id` AND `shop_products_i18n`.`locale` = '{$locale}' |
|
100 | LEFT JOIN |
|
101 | `users` |
|
102 | ON |
|
103 | `users`.`id` = `mod_stats_attendance`.`id_user` |
|
104 | ORDER BY |
|
105 | `mod_stats_attendance`.`time_add` |
|
106 | DESC |
|
107 | LIMIT 1 |
|
108 | "; |
|
109 | $result = $this->db->query($query); |
|
110 | if ($result) { |
|
111 | $result = $result->row_array(); |
|
112 | if ($result['type_id'] == Attendance::PAGE) { |
|
113 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_PAGE); |
|
114 | } elseif ($result['type_id'] == Attendance::CATEGORY) { |
|
115 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_CATEGORY); |
|
116 | } elseif ($result['type_id'] == Attendance::SHOP_CATEGORY) { |
|
117 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_SHOP_CATEGORY); |
|
118 | } elseif ($result['type_id'] == Attendance::PRODUCT) { |
|
119 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_PRODUCT); |
|
120 | } |
|
121 | ||
122 | return $result; |
|
123 | } |
|
124 | ||
125 | return false; |
|
126 | } |
|
127 | ||
128 | protected function getUrl($id, $type) { |
|
129 | $urlConfiguration = CoreFactory::getConfiguration()->getUrlRules(); |