_getUserIp(); $select = $this->db->select(); $select->from($this->pair) ->where('idSession = ' . $this->db->quote($idSession)) ->where('ipAddress = ' . $this->db->quote($ipAddress)) ->order('id DESC'); $activityRow = $this->db->fetchRow($select); if (empty($activityRow)) { $statiscicsInfo = array( 'idSession' => $idSession, 'ipAddress' => $ipAddress, 'userAgent' => $this->_getUserAgent(), ); $this->insert($statiscicsInfo); } return $this; } protected function _getUserIp() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $userIp = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $userIp = $_SERVER['REMOTE_ADDR']; } return trim($userIp); } protected function _getUserAgent() { $agent = $_SERVER['HTTP_USER_AGENT']; return trim($agent); } public function getActivity() { $traffic = array(); $select = $this->db->select(); $select->from($this->pair, "COUNT(DISTINCT `UserActivity`.`ipAddress`)"); $select->where("`{$this->_tableAlias}`.`added` LIKE " . $this->db->quote(date('Y-m-d') . '%')); $traffic['today'] = (int) $this->db->fetchOne($select); $select->reset('where') ->where("added LIKE " . $this->db->quote(date('Y-m-d', time() - 24 * 60 * 60) . '%')); $traffic['yesterday'] = (int) $this->db->fetchOne($select); $select->reset('where') ->where("added LIKE " . $this->db->quote(date('Y-m-d', time() - 28 * 24 * 60 * 60) . '%')); $traffic['fourWeeksAgo'] = (int) $this->db->fetchOne($select); $select->reset('where') ->where("added LIKE " . $this->db->quote(date( 'Y-m-d', mktime(0, 0, 0, date('m'), date('d'), (date('Y') - 1))) . '%') ); $traffic['yearAgo'] = (int) $this->db->fetchOne($select); return $traffic; } }