protected function getMockProperties($timId = TimEnum::ILE, $sexId = SexEnum::MALE) { $properties = $this->getMock(PropertiesDAO::class, ['getTim', 'getSex'], [], '', false); $properties->expects($this->any())->method('getTim')->willReturn(TimEnum::create($timId)); $properties->expects($this->any())->method('getSex')->willReturn(SexEnum::create($sexId)); return $properties; }
private static function dualGuestsList(User $user) { $dualUsers = DI::get()->getUsers()->getUsersByChatId($user->getChannelId()); $dual = TimEnum::create(PendingDuals::get()->getDualTim($user->getProperties()->getTim())); foreach ($dualUsers as $n => $partner) { $props = $partner->getProperties(); if ($props->getTim()->getId() != $dual->getId() && $props->getTim()->getId() != TimEnum::ANY) { unset($dualUsers[$n]); } if ($props->getSex()->getId() == $user->getProperties()->getSex()->getId()) { unset($dualUsers[$n]); } } if (empty($dualUsers)) { return; } $collection = new UserCollection(); foreach ($dualUsers as $partner) { $collection->attach($partner); } $response = (new MessageResponse())->setTime(null)->setChannelId($user->getChannelId())->setMsg(MsgToken::create('DualIsWanted', $dual->getShortName())); $collection->setResponse($response)->notify(false); }
/** * @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; }
</div> <div class="col-md-3 btn-vert-block"> <input type="text" class="form-control" placeholder="<?php echo $lang->getPhrase('profile.City'); ?> " id="profile-city"> </div> <div class="col-md-2 btn-vert-block"> <select class="form-control" id="profile-tim"> <option selected disabled><?php echo $lang->getPhrase('profile.TIM'); ?> </option> <?php foreach (TimEnum::getList() as $tim) { ?> <option value="<?php echo $tim->getId(); ?> "><?php echo $tim->getName(); ?> </option> <?php } ?> </select> </div> <div class="col-md-2 btn-vert-block"> <select class="form-control" id="profile-sex">
public function getDualTim(TimEnum $tim) { return isset($this->dualsMap[$tim->getId()]) ? $this->dualsMap[$tim->getId()] : null; }
public function setTim(TimEnum $tim) { $this[self::TIM] = $tim->getId(); return $this; }
private function handleNameChange(User $user, $request) { $name = $request[PropertiesDAO::NAME]; $guestName = $user->getLang()->getPhrase('Guest'); $nameChangeFreq = DI::get()->getConfig()->nameChangeFreq; $isNewbie = mb_strpos($name, $guestName) !== false; $changeLog = NameChangeDAO::create()->getLastByUser($user); $hasNameChanged = $name != $user->getProperties()->getName(); if ($isNewbie) { $newname = str_replace($guestName, TimEnum::create($request[PropertiesDAO::TIM])->getShortName(), $name); $duplUser = PropertiesDAO::create()->getByUserName($newname); if (!($duplUser->getId() && $duplUser->getUserId() != $user->getId())) { $name = $newname; } } elseif ($changeLog && $hasNameChanged && !$this->isExpired($changeLog, $nameChangeFreq)) { RespondError::make($user, $user->getLang()->getPhrase('NameChangePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq))); return; } if ($changeLog = NameChangeDAO::create()->getLastByName($name)) { if ($changeLog->getUserId() != $user->getId()) { if (!$this->isExpired($changeLog, $nameChangeFreq)) { RespondError::make($user, $user->getLang()->getPhrase('NameTakePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq))); return; } } } if ($hasNameChanged && !$isNewbie) { NameChangeDAO::create()->setUser($user)->save(); } }