public function addUser(UserInterface $user, $ip) { $userlist = $this->getUserlist(); $now = time(); $currUserFound = false; foreach ($userlist as $key => $onlineUserData) { if ($onlineUserData['id'] !== $user->getId()) { $diff = $now - $onlineUserData['added']; // if ip in array but id is not the same than the user has logged in! if ($diff > 300 || in_array($ip, $onlineUserData['ips'])) { unset($userlist[$key]); } } else { $currUserFound = true; $userlist[$key]['added'] = $now; $ips = $onlineUserData['ips']; $ips[] = $ip; $ips = array_unique($ips); $userlist[$key]['ips'] = $ips; $userlist[$key]['count'] = count($ips); } } if (!$currUserFound) { $count = 1; $ips = array($ip); $userlist[] = array('id' => (int) $user->getId(), 'added' => $now, 'username' => $user->getUsername(), 'type' => $user->getSymbbType(), 'count' => $count, 'ips' => $ips); } $this->memcache->set(self::CACHE_KEY, $userlist, self::LIFETIME); }
protected function createForUser(\Symbb\Core\UserBundle\Entity\UserInterface $object = null, $breadcrumb) { if ($object) { $uri = $this->router->generate('symbb_user_profile', array('id' => $object->getId(), 'name' => $object->getUsername())); $breadcrumb[] = array('name' => $object->getUsername(), 'link' => $uri); } $uri = $this->router->generate('symbb_user_userlist', array()); $breadcrumb[] = array('name' => $this->translator->trans('Members', array(), 'symbb_frontend'), 'link' => $uri); return $breadcrumb; }
/** * this method will add a visitor to the statistic * currently its only a memcache storage because this information * is not important if someone will track his visitors fully he should use a analytics tool * * @param UserInterface $user * @param Request $request */ public function addVisitor(UserInterface $user, Request $request) { $days = 30; $ip = $request->getClientIp(); $data = $this->getVisitors(); $date = new \DateTime(); $currTimestamp = $date->getTimestamp(); // entries should be only hourly $date->setTime($date->format('H'), 0, 0); $todayTimestamp = $date->getTimestamp(); if (!isset($data[$todayTimestamp])) { $data[$todayTimestamp] = array(); } $type = $user->getSymbbType(); $currVisitor = array('id' => $user->getId(), 'type' => $type, 'ip' => $ip, 'lastVisiting' => $currTimestamp); $overwriteKey = null; // remove entries who are to old $maxOldDate = new \DateTime(); $maxOldDate->setTime(0, 0, 0); $maxOldDate->modify('-' . $days . 'days'); foreach ($data as $timestamp => $tmp) { if (!is_numeric($timestamp) || $timestamp < $maxOldDate->getTimestamp()) { unset($data[$timestamp]); } } foreach ($data[$todayTimestamp] as $key => $visitor) { if ($currVisitor['type'] == 'guest' && $visitor['type'] == $currVisitor['type'] && $visitor['ip'] == $currVisitor['ip'] || $currVisitor['type'] == 'user' && $visitor['type'] == $currVisitor['type'] && $visitor['id'] == $currVisitor['id']) { $overwriteKey = $key; break; } } // if we have found the same visitor in the data // then we will overwrite it // if not we will add the vistor if ($overwriteKey !== null) { $data[$todayTimestamp][$overwriteKey] = $currVisitor; } else { $data[$todayTimestamp][] = $currVisitor; } // sort ksort($data, SORT_NUMERIC); // reverse so that the newest are the first $data = array_reverse($data, true); $this->memcache->set(self::MEMCACHE_VISITOR_KEY, $data, 86400 * $days); // 30 days valid }
public function getSymbbData(\Symbb\Core\UserBundle\Entity\UserInterface $user) { if (!isset($this->symbbDataCache[$user->getId()])) { $this->symbbDataCache[$user->getId()] = $user->getSymbbData(); } return $this->symbbDataCache[$user->getId()]; }
/** * @param \Symbb\Core\UserBundle\Entity\UserInterface $user * @return bool */ public function checkIfVoteable(\Symbb\Core\UserBundle\Entity\UserInterface $user) { $end = $this->getEnd(); $now = new \DateTime(); $now = $now->getTimestamp(); // if the time is over, no new Votes are allowed if ($end > 0 && $now > $end) { return false; } // if the user can change the vote if ($this->choicesChangeable) { return true; } $votes = $this->getVotes(); $count = 0; foreach ($votes as $vote) { if ($vote->getUser() && $vote->getUser()->getId() == $user->getId()) { $count++; } } // or if the user haven not used all choices if ($count < $this->getChoices()) { return true; } return false; }