/**
  * @param int $lastDays
  *
  * @return array
  */
 public function getStatisticData($lastDays = 10)
 {
     $dateTime = DateTimer::getDateTime4TimeStamp(strtotime('-' . $lastDays - 1 . ' days'));
     $numberList = $this->getStatisticDataNumberList($dateTime);
     $result = [];
     if ($this->defaultValues) {
         // set some default values
         $range = DateTimer::getDateRange4Period($dateTime, new DateTime());
         foreach ($range as $date) {
             $result[$date->format($this->format)] = 0;
         }
     }
     if ($numberList) {
         foreach ($numberList as $numberData) {
             /** @var DateTime $date */
             $date = $numberData['created'];
             $dateFormat = $date->format($this->format);
             if (!isset($result[$dateFormat])) {
                 $result[$dateFormat] = 0;
             }
             $result[$dateFormat] += $numberData['amount'];
         }
     }
     return $result;
 }
 /**
  * @param $ip
  * @param $timeInterVal
  *
  * @return int
  */
 public function getNumberOfFailLogin4Ip($ip, $timeInterVal)
 {
     $query = $this->createQueryBuilder('p')->select('p')->where('p.ip = :ipString')->setParameter('ipString', $ip)->andWhere('p.created >= :expireTime')->setParameter('expireTime', DateTimer::getDateTime4TimeStamp(time() - $timeInterVal))->getQuery();
     /**
      * TODO remove count
      */
     return count($query->getArrayResult());
 }
Beispiel #3
0
 /**
  * Set expire
  * @param $expire
  * @return self
  */
 public function setExpire($expire)
 {
     if (!$expire instanceof \DateTime) {
         if (is_integer($expire)) {
             $expire = DateTimer::getDateTime4TimeStamp($expire);
         } else {
             $expire = new \DateTime($expire);
         }
     }
     $this->expire = $expire;
     return $this;
 }
Beispiel #4
0
 /**
  * @return array
  */
 protected function getDonationDataSuccess()
 {
     $timestamp = DateTimer::getZeroTimeStamp(time());
     $dateTime = DateTimer::getDateTime4TimeStamp($timestamp);
     $donateEntity = $this->getDonateLogEntity();
     $donateData = $donateEntity->getDonationDataSuccess($dateTime);
     return $donateData;
 }
Beispiel #5
0
 /**
  * @param SmallUserInterface $user
  * @return bool
  */
 protected function handleInvalidLogin(SmallUserInterface $user)
 {
     $maxTries = $this->collectionOptions->getLoginOptions()->getExploit()['try'];
     if (!$maxTries) {
         return false;
     }
     $entityManager = $this->entityManager;
     /**
      * Set LoginHistory
      */
     $class = $this->collectionOptions->getEntityOptions()->getLoginFailed();
     /** @var \PServerCore\Entity\LoginFailed $loginFailed */
     $loginFailed = new $class();
     $loginFailed->setUsername($user->getUsername());
     $loginFailed->setIp($this->ipService->getIp());
     $entityManager->persist($loginFailed);
     $entityManager->flush();
     $time = $this->collectionOptions->getLoginOptions()->getExploit()['time'];
     /** @var \PServerCore\Entity\Repository\LoginFailed $repositoryLoginFailed */
     $repositoryLoginFailed = $entityManager->getRepository($class);
     if ($repositoryLoginFailed->getNumberOfFailLogin4Ip($this->ipService->getIp(), $time) >= $maxTries) {
         $class = $this->collectionOptions->getEntityOptions()->getIpBlock();
         /** @var \PServerCore\Entity\IpBlock $ipBlock */
         $ipBlock = new $class();
         $ipBlock->setExpire(DateTimer::getDateTime4TimeStamp(time() + $time));
         $ipBlock->setIp($this->ipService->getIp());
         $entityManager->persist($ipBlock);
         $entityManager->flush();
     }
     return true;
 }