コード例 #1
0
 public function setUser(User $user)
 {
     $this[self::USER_ID] = $user->getId();
     $this[self::OLD_NAME] = $user->getProperties()->getName();
     $this[self::DATE_CHANGE] = DbQueryHelper::timestamp2date();
     return $this;
 }
コード例 #2
0
 public function run()
 {
     $config = DI::get()->getConfig();
     $timeOut = $config->onlineMonitoringTimeout;
     // Let it be simple for a while
     $channelId = 1;
     /** @var PropertiesDAO $props */
     foreach (PropertiesDAO::create()->getRegisteredList() as $props) {
         if (!($limit = $props->getOnlineNotificationLimit())) {
             continue;
         }
         $online = OnlineDAO::create();
         if ($online->isUserOnline($channelId, $props->getUserId())) {
             continue;
         }
         $onlineCount = $online->getOnlineCount($channelId);
         if (time() - $timeOut < strtotime($props->getOnlineNotificationLast())) {
             continue;
         }
         if ($onlineCount >= $limit) {
             $user = UserDAO::create()->getById($props->getUserId());
             $list = '';
             foreach ($online->getOnlineList($channelId) as $userId => $userName) {
                 $list .= "<li>{$userName}</li>";
             }
             $msg = "<h2>Достижение заданного онлайна в SocioChat.Me</h2>\n<p>Вы получили данное письмо, потому что пожелали уведомить вас, когда в чате будет более {$limit} человек.</p>\n<p>Сейчас на основном канале общается {$onlineCount} человек</p>\n<ul>{$list}</ul>\n<p><a href=\"" . $config->domain->protocol . $config->domain->web . "\">Присоединяйтесь</a>!</p>";
             $message = MailQueueDAO::create();
             $message->setEmail($user->getEmail())->setTopic('SocioChat.Me - Заходите к нам!')->setMessage($msg);
             $message->save();
             $props->setOnlineNotificationLast(DbQueryHelper::timestamp2date());
             $props->save(false);
         }
     }
 }
コード例 #3
0
 public function clean($ttl)
 {
     $users = SessionDAO::create()->getObsoleteUserIds(DbQueryHelper::timestamp2date(time() - $ttl));
     if (!empty($users)) {
         SessionDAO::create()->dropByUserIdList($users);
         PropertiesDAO::create()->dropByUserIdList($users);
         UserBlacklistDAO::create()->dropByUserIdList($users);
         UserNotesDAO::create()->dropByUserIdList($users);
         UserDAO::create()->dropByUserIdList($users);
     }
 }
コード例 #4
0
 public function lock($key, $expireTime = self::DEFAULT_EXPIRE_TIME)
 {
     if ($this->isLocked($key)) {
         throw new AlreadyLockedException();
     }
     try {
         $locker = LockerDAO::create();
         $locker->setKey($key)->setTimestamp(DbQueryHelper::timestamp2date(time() + $expireTime));
         $locker->save();
     } catch (\PDOException $e) {
         throw new AlreadyLockedException($e->getMessage());
     }
 }
コード例 #5
0
ファイル: UserDAO.php プロジェクト: jackblackjack/sociochat
 public function dropByUserIdList(array $userIds)
 {
     $usersList = DbQueryHelper::commaSeparatedHolders($userIds);
     $this->db->exec("DELETE FROM {$this->dbTable} WHERE id IN ({$usersList})", $userIds);
 }
コード例 #6
0
 /**
  * @param Lang $lang
  * @param Logger $logger
  * @param User $newUserWrapper
  * @param Request $socketRequest
  * @return UserDAO
  */
 private function createNewUser(Lang $lang, Logger $logger, User $newUserWrapper, Request $socketRequest)
 {
     $user = UserDAO::create()->setChatId(1)->setDateRegister(DbQueryHelper::timestamp2date())->setRole(UserRoleEnum::USER)->setBanned(false)->setImprint(null);
     try {
         $user->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getMessage() . ': ' . $e->getTraceAsString(), [__METHOD__]);
     }
     $id = $user->getId();
     $guestName = $lang->getPhrase('Guest') . $id;
     if (PropertiesDAO::create()->getByUserName($guestName)->getName()) {
         $guestName = $lang->getPhrase('Guest') . ' ' . $id;
     }
     $properties = $user->getPropeties();
     $properties->setUserId($user->getId())->setName($guestName)->setSex(SexEnum::create(SexEnum::ANONYM))->setTim(TimEnum::create(TimEnum::ANY))->setBirthday(Rules::LOWEST_YEAR)->setOptions([PropertiesDAO::CENSOR => true])->setOnlineCount(0)->setMusicCount(0)->setWordsCount(0)->setRudeCount(0)->setKarma(0)->setMessagesCount(0)->setSubscription(true);
     try {
         $properties->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getTraceAsString(), [__CLASS__]);
     }
     if ($refUserId = $socketRequest->getCookie('refUserId')) {
         $ref = ReferralDAO::create()->getByUserId($user->getId(), $refUserId);
         if (!$ref) {
             $ref = ReferralDAO::create()->setUserId($user->getId())->setRefUserId($refUserId)->setDateRegister(DbQueryHelper::timestamp2date());
             $ref->save();
             $logger->info('Found referral userId ' . $refUserId . ' for guest userId ' . $user->getId());
         }
     }
     $logger->info("Created new user with id = {$id} for connectionId = {$newUserWrapper->getConnectionId()}", [__CLASS__]);
     return $user;
 }
コード例 #7
0
 public function dropUsedActivations()
 {
     return $this->db->exec("DELETE FROM {$this->dbTable} WHERE " . self::USED . " = :used OR " . self::TIMESTAMP . " < :threshold", ['used' => 'true', 'threshold' => DbQueryHelper::timestamp2date(time() - 3600 * 2)]);
 }
コード例 #8
0
 private function manageKarma(ChainContainer $chain, $mark)
 {
     $operator = $chain->getFrom();
     $request = $chain->getRequest();
     if (!isset($request['user_id'])) {
         RespondError::make($operator, ['user_id' => $operator->getLang()->getPhrase('RequiredPropertyNotSpecified')]);
         return;
     }
     if ($request['user_id'] == $operator->getId()) {
         RespondError::make($operator, ['user_id' => $operator->getLang()->getPhrase('CantDoToYourself')]);
         return;
     }
     if (!$operator->isRegistered()) {
         RespondError::make($operator, ['user_id' => 'Only available for registered user']);
         return;
     }
     if ($operator->getProperties()->getOnlineCount() < 3600) {
         RespondError::make($operator, ['user_id' => $operator->getLang()->getPhrase('OnlineTimeTooLow')]);
         return;
     }
     $users = DI::get()->getUsers();
     $user = $users->getClientById($request['user_id']);
     if (!$user) {
         $properties = PropertiesDAO::create()->getByUserId($request['user_id']);
     } else {
         $properties = $user->getProperties();
     }
     $lastMark = UserKarmaDAO::create()->getLastMarkByEvaluatorId($request['user_id'], $operator->getId());
     if ($lastMark) {
         if (time() - strtotime($lastMark->getDateRegister()) < DI::get()->getConfig()->karmaTimeOut) {
             RespondError::make($operator, ['user_id' => $operator->getLang()->getPhrase('profile.KarmaTimeOut')]);
             return;
         }
     }
     $karma = UserKarmaDAO::create()->getKarmaByUserId($request['user_id']);
     $properties->setKarma($karma + $mark)->save();
     $mark = UserKarmaDAO::create()->setUserId($request['user_id'])->setEvaluator($operator)->setMark($mark)->setDateRegister(DbQueryHelper::timestamp2date());
     $mark->save();
     $chatId = $operator->getChannelId();
     $response = (new MessageResponse())->setGuests($users->getUsersByChatId($chatId))->setChannelId($chatId)->setTime(null);
     DI::get()->getUsers()->setResponse($response)->notify();
 }
コード例 #9
0
 private function checkReferral(User $user)
 {
     $ref = ReferralDAO::create()->getFirstRefByUserId($user->getId());
     if (!$ref) {
         return;
     }
     $users = DI::get()->getUsers();
     if ($refUserOnline = $users->getClientById($ref->getRefUserId())) {
         $refUser = $refUserOnline->getUserDAO();
     } else {
         $refUser = UserDAO::create()->getById($ref->getRefUserId());
     }
     if (!$refUser->getId()) {
         return;
     }
     $mark = UserKarmaDAO::create()->setUserId($refUser->getId())->setEvaluator($user)->setMark(5)->setDateRegister(DbQueryHelper::timestamp2date());
     $mark->save();
     $props = $refUser->getPropeties();
     $props->setKarma($props->getKarma() + 5);
     if ($refUserOnline) {
         $refUserOnline->save();
         $response = (new MessageResponse())->setGuests($users->getUsersByChatId($refUserOnline->getChannelId()))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         $users->setResponse($response)->notify();
         $response = (new MessageResponse())->setMsg(MsgToken::create('profile.referralKarma'))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         (new UserCollection())->attach($refUserOnline)->setResponse($response)->notify(false);
     } else {
         $props->save(false);
     }
     DI::get()->getLogger()->info('Added karma to referral userId ' . $props->getUserId());
 }
コード例 #10
0
 public function __construct()
 {
     parent::__construct([self::EMAIL, self::TOPIC, self::MESSAGE, self::DATE]);
     $this->dbTable = 'mail_queue';
     $this->setDate(DbQueryHelper::timestamp2date());
 }