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();
 }
 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());
 }