/** * get users by user login names except me * * @param Array $loginNames * @return Array */ protected function getUsersByUserLoginNamesExceptMe(array $loginNames) { foreach ($loginNames as $key => $loginName) { $loginNames[$key] = str_replace('\\\\', '\\', $loginNames[$key]); $loginNames[$key] = str_replace("\\'", "'", $loginNames[$key]); } $objsUserProfile = UserProfile::getUserProfilesByUsername($loginNames); $objsUser = array(); foreach ($objsUserProfile as $oUserProfile) { if (empty($oUserProfile)) { continue; } $oUser = $oUserProfile->getDecoratedObject(); if ($oUser->userID && $oUser->userID != $this->oUser->userID) { $objsUser[] = $oUser; } } return $objsUser; }
/** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['sum'])) { $this->sum = (int) $_POST['sum']; } if (isset($_POST['reason'])) { $this->reason = StringUtil::trim($_POST['reason']); } if (isset($_POST['username'])) { $this->usernames = StringUtil::trim($_POST['username']); } if (isset($_POST['isModerativ']) && $_POST['isModerativ'] == 1 && WCF::getSession()->getPermission('mod.jcoins.canModTransfer')) { $this->isModerativ = 1; } if (count(explode(',', $this->usernames)) > 0) { $users = explode(',', $this->usernames); $this->user = UserProfile::getUserProfilesByUsername(ArrayUtil::trim(explode(',', $this->usernames))); } }
/** * Validates the participants. * * @param string $participants * @param string $field * @param array<integer> $existingParticipants * @return array $result */ public static function validateParticipants($participants, $field = 'participants', array $existingParticipants = array()) { $result = array(); $error = array(); // loop through participants and check their settings $participantList = UserProfile::getUserProfilesByUsername(ArrayUtil::trim(explode(',', $participants))); // load user storage at once to avoid multiple queries $userIDs = array(); foreach ($participantList as $user) { if ($user) { $userIDs[] = $user->userID; } } UserStorageHandler::getInstance()->loadStorage($userIDs); foreach ($participantList as $participant => $user) { try { if ($user === null) { throw new UserInputException($field, 'notFound'); } // user is author if ($user->userID == WCF::getUser()->userID) { throw new UserInputException($field, 'isAuthor'); } else { if (in_array($user->userID, $existingParticipants)) { throw new UserInputException($field, 'duplicate'); } } // validate user self::validateParticipant($user, $field); // no error $existingParticipants[] = $result[] = $user->userID; } catch (UserInputException $e) { $error[] = array('type' => $e->getType(), 'username' => $participant); } } if (!empty($error)) { throw new UserInputException($field, $error); } return $result; }