diff --git a/includes/Http/Controllers/Api/Shop/PurchaseCollection.php b/includes/Http/Controllers/Api/Shop/PurchaseCollection.php index 1cdd06d5c..0e08be686 100644 --- a/includes/Http/Controllers/Api/Shop/PurchaseCollection.php +++ b/includes/Http/Controllers/Api/Shop/PurchaseCollection.php @@ -40,7 +40,7 @@ public function post( $purchase = $purchaseFactory ->create($user, get_ip($request), get_platform($request)) ->setServiceId($serviceModule->service->getId()) - ->setDescription( + ->setTransferDescription( $lang->t("payment_for_service", $serviceModule->service->getNameI18n()) ); diff --git a/includes/Http/Services/PurchaseService.php b/includes/Http/Services/PurchaseService.php index 27b4543e4..c86e89f17 100644 --- a/includes/Http/Services/PurchaseService.php +++ b/includes/Http/Services/PurchaseService.php @@ -56,7 +56,7 @@ public function purchase( Server $server, array $body, $platform - ) { + ): PaymentResult { $type = as_int(array_get($body, "type")); $authData = trim(array_get($body, "auth_data")); $password = array_get($body, "password"); @@ -72,7 +72,7 @@ public function purchase( $purchase = (new Purchase($this->auth->user(), $ip, $platform)) ->setServiceId($serviceModule->service->getId()) - ->setDescription( + ->setTransferDescription( $this->lang->t("payment_for_service", $serviceModule->service->getNameI18n()) ) ->setEmail($email) @@ -109,7 +109,7 @@ public function purchase( private function getPaymentOption( PaymentMethod $paymentMethod = null, $paymentPlatformId = null - ) { + ): PaymentOption { if (PaymentMethod::SMS()->equals($paymentMethod)) { return new PaymentOption(PaymentMethod::SMS(), $paymentPlatformId); } diff --git a/includes/Http/Validation/Validator.php b/includes/Http/Validation/Validator.php index 5f6670426..57a42f847 100644 --- a/includes/Http/Validation/Validator.php +++ b/includes/Http/Validation/Validator.php @@ -14,7 +14,7 @@ public function __construct(array $data, array $rules) $this->rules = $rules; } - public function validate() + public function validate(): WarningBag { $warnings = new WarningBag(); @@ -43,7 +43,7 @@ public function validate() return $warnings; } - public function validateOrFail() + public function validateOrFail(): array { $warnings = $this->validate(); @@ -54,7 +54,7 @@ public function validateOrFail() return $this->validated(); } - public function validated() + public function validated(): array { return collect(array_keys($this->rules)) ->flatMap( @@ -65,17 +65,17 @@ public function validated() ->all(); } - public function extendRules(array $rules) + public function extendRules(array $rules): void { $this->rules = array_merge_recursive($this->rules, $rules); } - public function extendData(array $data) + public function extendData(array $data): void { $this->data = array_merge($this->data, $data); } - public function getData($attribute) + public function getData($attribute): mixed { return array_get($this->data, $attribute); } diff --git a/includes/Models/Purchase.php b/includes/Models/Purchase.php index b8d114cf0..375d46493 100644 --- a/includes/Models/Purchase.php +++ b/includes/Models/Purchase.php @@ -15,21 +15,19 @@ class Purchase const ORDER_QUANTITY = "quantity"; const ORDER_SERVER = "server"; - /** @var string */ - private $id; + private string $id; /** * ID of row from ss_services table * * @var string|null */ - private $serviceId; + private ?string $serviceId = null; /** @var User */ public $user; - /** @var string|null */ - private $email; + private ?string $email = null; /** * List of available payment platforms @@ -51,10 +49,12 @@ class Purchase /** @var PromoCode|null */ private $promoCode = null; + private ?string $comment = null; + /** * Purchase description ( useful for transfer payments ) */ - private ?string $description; + private ?string $transferDescription = null; /** * Platform from which the purchase was made @@ -100,7 +100,7 @@ public function getServiceId() /** * @param string $serviceId - * @return static + * @return self */ public function setServiceId($serviceId): self { @@ -119,7 +119,7 @@ public function getOrder($key) /** * @param array $order - * @return static + * @return self */ public function setOrder(array $order): self { @@ -146,7 +146,7 @@ public function getPayment($key) /** * @param array $payment - * @return static + * @return self */ public function setPayment(array $payment): self { @@ -169,7 +169,7 @@ public function getEmail(): ?string /** * @param string $email - * @return static + * @return self */ public function setEmail($email): self { @@ -177,18 +177,29 @@ public function setEmail($email): self return $this; } - public function getDescription(): ?string + public function getComment(): ?string + { + return $this->comment; + } + + public function setComment($comment): self + { + $this->comment = $comment; + return $this; + } + + public function getTransferDescription(): ?string { - return $this->description; + return $this->transferDescription; } /** - * @param string $description - * @return static + * @param string $transferDescription + * @return self */ - public function setDescription($description): self + public function setTransferDescription($transferDescription): self { - $this->description = $description; + $this->transferDescription = $transferDescription; return $this; } @@ -209,7 +220,7 @@ public function getPaymentSelect(): PaymentSelect /** * @param Price $price - * @return static + * @return self */ public function setUsingPrice(Price $price): self { @@ -252,7 +263,7 @@ public function getPromoCode(): ?PromoCode /** * @param PromoCode|null $promoCode - * @return static + * @return self */ public function setPromoCode(PromoCode $promoCode = null): self { @@ -272,7 +283,7 @@ public function getPaymentOption(): ?PaymentOption /** * @param PaymentOption $paymentOption - * @return static + * @return self */ public function setPaymentOption(PaymentOption $paymentOption): self { diff --git a/includes/Models/UserService.php b/includes/Models/UserService.php index 106dbe327..cd4c1220d 100644 --- a/includes/Models/UserService.php +++ b/includes/Models/UserService.php @@ -6,18 +6,20 @@ class UserService private int $id; private string $serviceId; private ?int $userId; + private string $comment; /** * Timestamp or -1 when forever */ private int $expire; - public function __construct($id, $serviceId, $userId, $expire) + public function __construct($id, $serviceId, $userId, $expire, $comment) { $this->id = $id; $this->serviceId = $serviceId; $this->userId = $userId; $this->expire = $expire; + $this->comment = $comment; } public function getId(): int @@ -44,4 +46,9 @@ public function isForever(): bool { return $this->expire === -1; } + + public function getComment(): string + { + return $this->comment; + } } diff --git a/includes/Payment/General/PaymentOption.php b/includes/Payment/General/PaymentOption.php index 7d7e90a61..df878573c 100644 --- a/includes/Payment/General/PaymentOption.php +++ b/includes/Payment/General/PaymentOption.php @@ -12,27 +12,17 @@ public function __construct(PaymentMethod $paymentMethod, $paymentPlatformId = n $this->paymentPlatformId = $paymentPlatformId; } - /** - * @return PaymentMethod - */ - public function getPaymentMethod() + public function getPaymentMethod(): PaymentMethod { return $this->paymentMethod; } - /** - * @return int|null - */ - public function getPaymentPlatformId() + public function getPaymentPlatformId(): ?int { return $this->paymentPlatformId; } - /** - * @param PaymentOption $paymentOption - * @return bool - */ - public function equal(PaymentOption $paymentOption) + public function equal(PaymentOption $paymentOption): bool { return $this->getPaymentPlatformId() === $paymentOption->getPaymentPlatformId() && $this->getPaymentMethod()->equals($paymentOption->getPaymentMethod()); diff --git a/includes/Repositories/UserServiceRepository.php b/includes/Repositories/UserServiceRepository.php index ec0307e8d..41c611342 100644 --- a/includes/Repositories/UserServiceRepository.php +++ b/includes/Repositories/UserServiceRepository.php @@ -16,25 +16,33 @@ public function __construct(Database $db) * @param string $serviceId * @param int|null $seconds * @param int|null $userId + * @param string|null $comment * @return int */ - public function create($serviceId, $seconds, $userId): int + public function create($serviceId, $seconds, $userId, $comment): int { $statement = $this->db->statement( - "INSERT INTO `ss_user_service` (`service_id`, `expire`, `user_id`) " . - "VALUES (?, IF(? IS NULL, '-1', UNIX_TIMESTAMP() + ?), ?)" + "INSERT INTO `ss_user_service` (`service_id`, `expire`, `user_id`, `comment`) " . + "VALUES (?, IF(? IS NULL, '-1', UNIX_TIMESTAMP() + ?), ?, ?)" ); - $statement->execute([$serviceId, $seconds, $seconds, $userId ?: 0]); + $statement->execute([$serviceId, $seconds, $seconds, $userId ?: 0, $comment ?: ""]); return $this->db->lastId(); } - public function createFixedExpire($serviceId, $expiresAt, $userId): int + /** + * @param string $serviceId + * @param int $expiresAt + * @param int|null $userId + * @param string|null $comment + * @return int + */ + public function createFixedExpire($serviceId, $expiresAt, $userId, $comment): int { $statement = $this->db->statement( - "INSERT INTO `ss_user_service` (`service_id`, `expire`, `user_id`) " . - "VALUES (?, ?, ?)" + "INSERT INTO `ss_user_service` (`service_id`, `expire`, `user_id`, `comment`) " . + "VALUES (?, ?, ?, ?)" ); - $statement->execute([$serviceId, $expiresAt, $userId ?: 0]); + $statement->execute([$serviceId, $expiresAt, $userId ?: 0, $comment ?: ""]); return $this->db->lastId(); } @@ -84,11 +92,11 @@ public function update($id, array $data): int public function updateWithModule($table, $userServiceId, array $data): int { $baseData = collect($data)->filter( - fn($value, $key) => in_array($key, ["user_id", "service_id", "expire"], true) + fn($value, $key) => in_array($key, ["user_id", "service_id", "expire", "comment"], true) ); $moduleData = collect($data)->filter( - fn($value, $key) => !in_array($key, ["user_id", "expire"], true) + fn($value, $key) => !in_array($key, ["user_id", "expire", "comment"], true) ); $affected = $this->update($userServiceId, $baseData->all()); diff --git a/includes/ServiceModules/ChargeWallet/ChargeWalletServiceModule.php b/includes/ServiceModules/ChargeWallet/ChargeWalletServiceModule.php index 9bdfdd836..fba627388 100644 --- a/includes/ServiceModules/ChargeWallet/ChargeWalletServiceModule.php +++ b/includes/ServiceModules/ChargeWallet/ChargeWalletServiceModule.php @@ -62,7 +62,7 @@ public function __construct( $this->walletPaymentService = $walletPaymentService; } - public function purchaseFormGet(array $query) + public function purchaseFormGet(array $query): string { $paymentMethodOptions = []; $paymentMethodBodies = []; @@ -90,7 +90,7 @@ public function purchaseFormGet(array $query) /** * @return PaymentOption[] */ - private function getPaymentOptions() + private function getPaymentOptions(): array { $output = []; @@ -115,7 +115,7 @@ private function getPaymentOptions() return $output; } - public function purchaseFormValidate(Purchase $purchase, array $body) + public function purchaseFormValidate(Purchase $purchase, array $body): void { if (!$this->auth->check()) { throw new UnauthorizedException(); @@ -141,7 +141,7 @@ public function purchaseFormValidate(Purchase $purchase, array $body) $this->chargeWalletFactory->create($paymentMethod)->setup($purchase, $body); } - public function orderDetails(Purchase $purchase) + public function orderDetails(Purchase $purchase): string { $paymentMethod = $this->chargeWalletFactory->create( $purchase->getPaymentOption()->getPaymentMethod() @@ -156,7 +156,7 @@ public function orderDetails(Purchase $purchase) ); } - public function purchase(Purchase $purchase) + public function purchase(Purchase $purchase): int { $this->walletPaymentService->chargeWallet( $purchase->user, diff --git a/includes/ServiceModules/ExtraFlags/ExtraFlagType.php b/includes/ServiceModules/ExtraFlags/ExtraFlagType.php index 880f7cd86..eabac2531 100644 --- a/includes/ServiceModules/ExtraFlags/ExtraFlagType.php +++ b/includes/ServiceModules/ExtraFlags/ExtraFlagType.php @@ -10,7 +10,7 @@ class ExtraFlagType const TYPE_SID = 1 << 2; const ALL = [self::TYPE_NICK, self::TYPE_IP, self::TYPE_SID]; - public static function getTypeName($value) + public static function getTypeName($value): string { /** @var TranslationManager $translationManager */ $translationManager = app()->make(TranslationManager::class); diff --git a/includes/ServiceModules/ExtraFlags/ExtraFlagUserService.php b/includes/ServiceModules/ExtraFlags/ExtraFlagUserService.php index 6ae0f1076..fc4df9463 100644 --- a/includes/ServiceModules/ExtraFlags/ExtraFlagUserService.php +++ b/includes/ServiceModules/ExtraFlags/ExtraFlagUserService.php @@ -15,12 +15,13 @@ public function __construct( $serviceId, $userId, $expire, + $comment, $serverId, $type, $authData, $password ) { - parent::__construct($id, $serviceId, $userId, $expire); + parent::__construct($id, $serviceId, $userId, $expire, $comment); $this->serverId = $serverId; $this->type = $type; diff --git a/includes/ServiceModules/ExtraFlags/ExtraFlagUserServiceRepository.php b/includes/ServiceModules/ExtraFlags/ExtraFlagUserServiceRepository.php index 7baffa3f4..46a514c68 100644 --- a/includes/ServiceModules/ExtraFlags/ExtraFlagUserServiceRepository.php +++ b/includes/ServiceModules/ExtraFlags/ExtraFlagUserServiceRepository.php @@ -27,7 +27,7 @@ public function find(array $data): ?ExtraFlagUserService * @return ExtraFlagUserService * @throws EntityNotFoundException */ - public function findOrFail(array $data) + public function findOrFail(array $data): ExtraFlagUserService { $models = $this->findAll($data); if (empty($models)) { @@ -41,7 +41,7 @@ public function findOrFail(array $data) * @param array $data * @return ExtraFlagUserService[] */ - public function findAll(array $data) + public function findAll(array $data): array { [$params, $values] = map_to_params($data); $params = implode(" AND ", $params); @@ -60,9 +60,22 @@ public function findAll(array $data) ->all(); } - public function create($serviceId, $userId, $seconds, $serverId, $type, $authData, $password) - { - $userServiceId = $this->userServiceRepository->create($serviceId, $seconds, $userId); + public function create( + $serviceId, + $userId, + $seconds, + $serverId, + $type, + $authData, + $password, + $comment + ): ExtraFlagUserService { + $userServiceId = $this->userServiceRepository->create( + $serviceId, + $seconds, + $userId, + $comment + ); $table = ExtraFlagsServiceModule::USER_SERVICE_TABLE; $statement = $this->db->statement( @@ -74,7 +87,7 @@ public function create($serviceId, $userId, $seconds, $serverId, $type, $authDat return $this->get($userServiceId); } - public function get($id) + public function get($id): ?ExtraFlagUserService { if ($id) { $table = ExtraFlagsServiceModule::USER_SERVICE_TABLE; @@ -99,7 +112,7 @@ public function get($id) * @param int $type * @param string $authData */ - public function updatePassword($password, $serverId, $type, $authData) + public function updatePassword($password, $serverId, $type, $authData): void { $table = ExtraFlagsServiceModule::USER_SERVICE_TABLE; $this->db @@ -113,13 +126,14 @@ public function updatePassword($password, $serverId, $type, $authData) ->execute([$password, $serverId, $type, $authData]); } - public function mapToModel(array $data) + public function mapToModel(array $data): ExtraFlagUserService { return new ExtraFlagUserService( as_int($data["id"]), as_string($data["service_id"]), as_int($data["user_id"]), as_int($data["expire"]), + as_string($data["comment"]), as_int($data["server_id"]), as_int($data["type"]), as_string($data["auth_data"]), diff --git a/includes/ServiceModules/ExtraFlags/ExtraFlagsServiceModule.php b/includes/ServiceModules/ExtraFlags/ExtraFlagsServiceModule.php index 076284f72..6339ad863 100644 --- a/includes/ServiceModules/ExtraFlags/ExtraFlagsServiceModule.php +++ b/includes/ServiceModules/ExtraFlags/ExtraFlagsServiceModule.php @@ -71,6 +71,7 @@ use App\View\Html\HeadCell; use App\View\Html\NoneText; use App\View\Html\Option; +use App\View\Html\PreWrapCell; use App\View\Html\ServerRef; use App\View\Html\ServiceRef; use App\View\Html\Structure; @@ -169,7 +170,7 @@ public function mapToUserService(array $data): ExtraFlagUserService return $this->extraFlagUserServiceRepository->mapToModel($data); } - public function serviceAdminExtraFieldsGet() + public function serviceAdminExtraFieldsGet(): string { // WEB $webSelYes = selected($this->showOnWeb()); @@ -192,7 +193,7 @@ public function serviceAdminExtraFieldsGet() ); } - public function serviceAdminManagePre(Validator $validator) + public function serviceAdminManagePre(Validator $validator): void { $validator->extendRules([ "flags" => [new RequiredRule(), new MaxLengthRule(25), new UniqueFlagsRule()], @@ -201,9 +202,9 @@ public function serviceAdminManagePre(Validator $validator) ]); } - public function serviceAdminManagePost(array $body) + public function serviceAdminManagePost(array $body): array { - // Przygotowujemy do zapisu ( suma bitowa ), które typy zostały wybrane + // We prepare for writing (bit sum) which types have been selected $types = 0; foreach ($body["type"] as $type) { $types |= $type; @@ -224,12 +225,12 @@ public function serviceAdminManagePost(array $body) // ---------------------------------------------------------------------------------- // ### Wyświetlanie usług użytkowników w PA - public function userServiceAdminDisplayTitleGet() + public function userServiceAdminDisplayTitleGet(): string { return $this->lang->t("extra_flags"); } - public function userServiceAdminDisplayGet(Request $request) + public function userServiceAdminDisplayGet(Request $request): Wrapper { $pagination = $this->paginationFactory->create($request); $queryParticle = new QueryParticle(); @@ -246,19 +247,28 @@ public function userServiceAdminDisplayGet(Request $request) $where = $queryParticle->isEmpty() ? "" : "WHERE {$queryParticle} "; $statement = $this->db->statement( - "SELECT SQL_CALC_FOUND_ROWS " . - "us.id AS `id`, us.user_id AS `user_id`, u.username AS `username`, " . - "srv.id AS `server_id`, srv.name AS `server_name`, " . - "s.id AS `service_id`, s.name AS `service_name`, " . - "usef.type AS `type`, usef.auth_data AS `auth_data`, us.expire AS `expire` " . - "FROM `ss_user_service` AS us " . - "INNER JOIN `{$this->getUserServiceTable()}` AS usef ON usef.us_id = us.id " . - "LEFT JOIN `ss_services` AS s ON s.id = usef.service_id " . - "LEFT JOIN `ss_servers` AS srv ON srv.id = usef.server_id " . - "LEFT JOIN `ss_users` AS u ON u.uid = us.user_id " . - $where . - "ORDER BY us.id DESC " . - "LIMIT ?, ?" + <<getUserServiceTable()}` AS usef ON usef.us_id = us.id + LEFT JOIN `ss_services` AS s ON s.id = usef.service_id + LEFT JOIN `ss_servers` AS srv ON srv.id = usef.server_id + LEFT JOIN `ss_users` AS u ON u.uid = us.user_id + {$where} + ORDER BY us.id DESC + LIMIT ?, ? +EOF ); $statement->execute(array_merge($queryParticle->params(), $pagination->getSqlLimit())); $rowsCount = $this->db->query("SELECT FOUND_ROWS()")->fetchColumn(); @@ -276,6 +286,7 @@ public function userServiceAdminDisplayGet(Request $request) ->addCell(new Cell(new ServiceRef($row["service_id"], $row["service_name"]))) ->addCell(new Cell($row["auth_data"])) ->addCell(new ExpirationCell($row["expire"])) + ->addCell(new PreWrapCell($row["comment"])) ->setDeleteAction(can(Permission::MANAGE_USER_SERVICES())) ->setEditAction(can(Permission::MANAGE_USER_SERVICES())); }) @@ -296,13 +307,14 @@ public function userServiceAdminDisplayGet(Request $request) ) ) ->addHeadCell(new HeadCell($this->lang->t("expires"))) + ->addHeadCell(new HeadCell($this->lang->t("comment"))) ->addBodyRows($bodyRows) ->enablePagination("/admin/user_service", $pagination, $rowsCount); return (new Wrapper())->enableSearch()->setTable($table); } - public function purchaseFormGet(array $query) + public function purchaseFormGet(array $query): string { $types = collect(ExtraFlagType::ALL) ->filter(fn($type) => $this->service->getTypes() & $type) @@ -326,7 +338,7 @@ public function purchaseFormGet(array $query) ]); } - public function purchaseFormValidate(Purchase $purchase, array $body) + public function purchaseFormValidate(Purchase $purchase, array $body): void { $quantity = as_int(array_get($body, "quantity")); $serverId = as_int(array_get($body, "server_id")); @@ -368,7 +380,7 @@ public function purchaseFormValidate(Purchase $purchase, array $body) } } - public function purchaseDataValidate(Purchase $purchase) + public function purchaseDataValidate(Purchase $purchase): Validator { $server = $this->serverManager->get($purchase->getOrder(Purchase::ORDER_SERVER)); @@ -423,7 +435,7 @@ public function purchaseDataValidate(Purchase $purchase) ); } - public function orderDetails(Purchase $purchase) + public function orderDetails(Purchase $purchase): string { $server = $this->serverManager->get($purchase->getOrder(Purchase::ORDER_SERVER)); $typeName = $this->getTypeName($purchase->getOrder("type")); @@ -461,7 +473,7 @@ public function orderDetails(Purchase $purchase) ); } - public function purchase(Purchase $purchase) + public function purchase(Purchase $purchase): int { $this->playerFlagService->addPlayerFlags( $this->service->getId(), @@ -470,7 +482,8 @@ public function purchase(Purchase $purchase) $purchase->getOrder("type"), $purchase->getOrder("auth_data"), $purchase->getOrder("password"), - $purchase->user->getId() + $purchase->user->getId(), + $purchase->getComment() ); $promoCode = $purchase->getPromoCode(); @@ -568,7 +581,7 @@ public function purchaseInfo($action, Transaction $transaction) // ---------------------------------------------------------------------------------- // ### Zarządzanie usługami użytkowników przez admina - public function userServiceAdminAddFormGet() + public function userServiceAdminAddFormGet(): string { $types = $this->getTypeOptions($this->service->getTypes()); $servers = $this->getServerOptions(); @@ -579,7 +592,7 @@ public function userServiceAdminAddFormGet() ); } - public function userServiceAdminAdd(Request $request) + public function userServiceAdminAdd(Request $request): void { $forever = (bool) $request->request->get("forever"); @@ -590,6 +603,7 @@ public function userServiceAdminAdd(Request $request) "user_id" => as_int($request->request->get("user_id")), ]), [ + "comment" => [], "email" => [new EmailRule()], "password" => [new ExtraFlagPasswordRule()], "quantity" => $forever @@ -623,21 +637,22 @@ public function userServiceAdminAdd(Request $request) "password" => $validated["password"], Purchase::ORDER_QUANTITY => $forever ? null : $validated["quantity"], ]) - ->setEmail($validated["email"]); + ->setEmail($validated["email"]) + ->setComment($validated["comment"]); $boughtServiceId = $this->purchase($purchase); $this->logger->logWithActor("log_user_service_added", $boughtServiceId); } - public function userServiceAdminEditFormGet(UserService $userService) + public function userServiceAdminEditFormGet(UserService $userService): string { assert($userService instanceof ExtraFlagUserService); $services = collect($this->serviceManager->all()) ->filter(function (Service $service) { $serviceModule = $this->serviceModuleManager->getEmpty($service->getModule()); - // Usługę możemy zmienić tylko na taka, która korzysta z tego samego modułu. - // Inaczej to nie ma sensu, lepiej ją usunąć i dodać nową + // We can only change the service to one that uses the same module. + // It doesn't make sense otherwise, better remove it and add a new one return $serviceModule && $this->getModuleId() === $serviceModule->getModuleId(); }) ->map( @@ -688,12 +703,10 @@ public function userServiceAdminEditFormGet(UserService $userService) $servers = $this->getServerOptions($userService->getServerId()); - // Pobranie hasła if (strlen($userService->getPassword())) { $password = "********"; } - // Zamiana daty if ($userService->isForever()) { $userServiceExpire = ""; $checked["forever"] = "checked"; @@ -717,6 +730,7 @@ public function userServiceAdminEditFormGet(UserService $userService) "checked", "userServiceExpire" ) + [ + "comment" => $userService->getComment(), "moduleId" => $this->getModuleId(), "userServiceId" => $userService->getId(), "userServiceUserId" => $userService->getUserId() ?: "", @@ -724,7 +738,7 @@ public function userServiceAdminEditFormGet(UserService $userService) ); } - public function userServiceAdminEdit(array $body, UserService $userService) + public function userServiceAdminEdit(array $body, UserService $userService): bool { assert($userService instanceof ExtraFlagUserService); @@ -736,6 +750,7 @@ public function userServiceAdminEdit(array $body, UserService $userService) "user_id" => as_int(array_get($body, "user_id")), ]), [ + "comment" => [], "expire" => $forever ? [] : [new RequiredRule(), new DateTimeRule()], "server_id" => [new RequiredRule(), new ServerExistsRule()], "user_id" => [new UserExistsRule()], @@ -775,7 +790,7 @@ private function verifyUserServiceData(Validator $validator) ]); } - public function userServiceDeletePost(UserService $userService) + public function userServiceDeletePost(UserService $userService): void { assert($userService instanceof ExtraFlagUserService); @@ -789,7 +804,7 @@ public function userServiceDeletePost(UserService $userService) // ---------------------------------------------------------------------------------- // ### Edytowanie usług przez użytkownika - public function userOwnServiceEditFormGet(UserService $userService) + public function userOwnServiceEditFormGet(UserService $userService): string { assert($userService instanceof ExtraFlagUserService); @@ -862,7 +877,7 @@ public function userOwnServiceEditFormGet(UserService $userService) ); } - public function userOwnServiceInfoGet(UserService $userService, $buttonEdit) + public function userOwnServiceInfoGet(UserService $userService, $buttonEdit): string { assert($userService instanceof ExtraFlagUserService); @@ -906,12 +921,7 @@ public function userOwnServiceEdit(Request $request, UserService $userService) // ---------------------------------------------------------------------------------- // ### Dodatkowe funkcje przydatne przy zarządzaniu usługami użytkowników - /** - * @param ExtraFlagUserService $userService - * @param array $data - * @return bool - */ - private function userServiceEdit(ExtraFlagUserService $userService, array $data) + private function userServiceEdit(ExtraFlagUserService $userService, array $data): bool { $expire = array_key_exists("expire", $data) ? as_int($data["expire"]) @@ -934,7 +944,9 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) $shouldPasswordBeUpdated = !!strlen($password); } - $set = []; + if (array_key_exists("comment", $data)) { + $set["comment"] = (string) $data["comment"]; + } if ($shouldPasswordBeUpdated) { $set["password"] = $password; @@ -948,7 +960,7 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) $set["expire"] = -1; } - // Sprawdzenie czy nie ma już takiej usługi + // Check if the same user service doesn't exist $statement = $this->db->statement( "SELECT * FROM `ss_user_service` AS us " . "INNER JOIN `{$this->getUserServiceTable()}` AS usef ON us.id = usef.us_id " . @@ -965,8 +977,6 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) if ($existingUserServiceData) { $existingUserService = $this->mapToUserService($existingUserServiceData); - // Since $shouldUidBeUpdated is false we can assume that it is action done via ACP - // not by "user own service edit" $canManageThisUserService = !$shouldUserBeUpdated && $userService->getUserId() != $existingUserService->getUserId(); @@ -977,14 +987,17 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) ]); } + // Since $shouldUserBeUpdated is false we can assume that it is action done via ACP + // not by "user own service edit" + $this->userServiceRepository->delete($userService->getId()); - // Dodajemy expire if ($expire) { $set["expire"] = new Expression("( `expire` - UNIX_TIMESTAMP() + $expire )"); } - // Aktualizujemy usługę, która już istnieje w bazie i ma takie same dane jak nasze nowe + // Let's update a user service that already exists in the database + // and has the same data $affected = $this->userServiceRepository->updateWithModule( $this->getUserServiceTable(), $existingUserService->getId(), @@ -1007,7 +1020,7 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) ); } - // Ustaw jednakowe hasła, żeby potem nie było problemów z różnymi hasłami + // Set the same passwords to avoid problems with different passwords later if ($shouldPasswordBeUpdated) { $this->db ->statement( @@ -1018,25 +1031,25 @@ private function userServiceEdit(ExtraFlagUserService $userService, array $data) ->execute([$password, $serverId, $type, $authData]); } - // Przelicz flagi tylko wtedy, gdy coś się zmieniło + // Only recalculate flags when something has changed if (!$affected) { return false; } - // Odśwież flagi gracza ( przed zmiana danych ) + // Refresh player flags (before changing data) $this->playerFlagService->recalculatePlayerFlags( $userService->getServerId(), $userService->getType(), $userService->getAuthData() ); - // Odśwież flagi gracza ( już po edycji ) + // Refresh player flags (after editing) $this->playerFlagService->recalculatePlayerFlags($serverId, $type, $authData); return true; } - public function serviceTakeOverFormGet() + public function serviceTakeOverFormGet(): string { $types = $this->getTypeOptions($this->service->getTypes()); $servers = $this->getServerOptions(); @@ -1047,7 +1060,7 @@ public function serviceTakeOverFormGet() ); } - public function serviceTakeOver(array $body) + public function serviceTakeOver(array $body): array { try { $paymentMethodId = new PaymentMethod(array_get($body, "payment_method")); @@ -1122,7 +1135,7 @@ public function serviceTakeOver(array $body) * @param int|null $selectedServerId * @return string */ - private function getServerOptions($selectedServerId = null) + private function getServerOptions($selectedServerId = null): string { return collect($this->serverManager->all()) ->filter( @@ -1162,7 +1175,7 @@ private function getTypeOptions($availableTypes, $selectedTypes = 0) * @param int $serverId * @return string */ - private function pricesForServer($serverId) + private function pricesForServer($serverId): string { $server = $this->serverManager->get($serverId); $service = $this->service; @@ -1182,7 +1195,7 @@ private function pricesForServer($serverId) ); } - public function actionExecute($action, array $body) + public function actionExecute($action, array $body): string { switch ($action) { case "prices_for_server": diff --git a/includes/ServiceModules/ExtraFlags/PlayerFlagService.php b/includes/ServiceModules/ExtraFlags/PlayerFlagService.php index ada9583ff..f30c143d5 100644 --- a/includes/ServiceModules/ExtraFlags/PlayerFlagService.php +++ b/includes/ServiceModules/ExtraFlags/PlayerFlagService.php @@ -36,6 +36,7 @@ public function __construct( * @param string $authData * @param string|null $password * @param int|null $userId + * @param string|null $comment * @return void */ public function addPlayerFlags( @@ -45,8 +46,9 @@ public function addPlayerFlags( $type, $authData, $password, - $userId - ) { + $userId, + $comment = null + ): void { $authData = trim($authData); $password = strlen($password) ? $password : ""; $table = ExtraFlagsServiceModule::USER_SERVICE_TABLE; @@ -76,6 +78,7 @@ public function addPlayerFlags( "user_id" => $userId, "password" => $password, "expire" => $expire, + "comment" => trim($userService->getComment() . "\n---\n" . $comment), ]); } else { $this->extraFlagUserServiceRepository->create( @@ -85,7 +88,8 @@ public function addPlayerFlags( $serverId, $type, $authData, - $password + $password, + $comment ); } diff --git a/includes/ServiceModules/Interfaces/IServiceActionExecute.php b/includes/ServiceModules/Interfaces/IServiceActionExecute.php index 248e16dfd..8f0936dd8 100644 --- a/includes/ServiceModules/Interfaces/IServiceActionExecute.php +++ b/includes/ServiceModules/Interfaces/IServiceActionExecute.php @@ -11,5 +11,5 @@ interface IServiceActionExecute * * @return string */ - public function actionExecute($action, array $body); + public function actionExecute($action, array $body): string; } diff --git a/includes/ServiceModules/Interfaces/IServiceAdminManage.php b/includes/ServiceModules/Interfaces/IServiceAdminManage.php index 6ce97307a..c26b8f8d9 100644 --- a/includes/ServiceModules/Interfaces/IServiceAdminManage.php +++ b/includes/ServiceModules/Interfaces/IServiceAdminManage.php @@ -4,32 +4,31 @@ use App\Http\Validation\Validator; /** - * Obsługa dodawania nowych usług w PA - * (Ten interfejs powinien być implementowany w klasie *Simple modułu usługi) + * Support for adding new services in ACP */ interface IServiceAdminManage { /** - * Metoda wywoływana przy edytowaniu lub dodawaniu usługi w PA - * Powinna zwracać dodatkowe pola do uzupełnienia + * Method called when editing or adding a service in ACP + * Should return additional fields to be filled * * @return string */ - public function serviceAdminExtraFieldsGet(); + public function serviceAdminExtraFieldsGet(): string; /** - * Metoda testuje dane przesłane przez formularz podczas dodawania nowej usługi w PA + * The method tests the data submitted using the form when adding a new service in ACP * * @param Validator $validator */ - public function serviceAdminManagePre(Validator $validator); + public function serviceAdminManagePre(Validator $validator): void; /** - * Metoda zostaje wywołana po tym, jak weryfikacja danych - * przesłanych w formularzu dodania nowej usługi w PA przebiegła bezproblemowo + * Called after verification of + * data sent in the form for adding a new service in ACP went smoothly * * @param array $body * @return array */ - public function serviceAdminManagePost(array $body); + public function serviceAdminManagePost(array $body): array; } diff --git a/includes/ServiceModules/Interfaces/IServiceCreate.php b/includes/ServiceModules/Interfaces/IServiceCreate.php index 916181b9c..8e7f160f4 100644 --- a/includes/ServiceModules/Interfaces/IServiceCreate.php +++ b/includes/ServiceModules/Interfaces/IServiceCreate.php @@ -2,8 +2,8 @@ namespace App\ServiceModules\Interfaces; /** - * Jeżeli moduł usługi implementuje ten interfejs, to oznacza to, że - * będzie możliwe tworzenie nowych usług obsługiwanych przez ten moduł + * If the service module implements this interface, it means that + * it will be possible to create new services supported by this service module */ interface IServiceCreate { diff --git a/includes/ServiceModules/Interfaces/IServicePurchase.php b/includes/ServiceModules/Interfaces/IServicePurchase.php index b19a99b23..81283a6a9 100644 --- a/includes/ServiceModules/Interfaces/IServicePurchase.php +++ b/includes/ServiceModules/Interfaces/IServicePurchase.php @@ -11,5 +11,5 @@ interface IServicePurchase * @param Purchase $purchase * @return int ID of the BoughtService */ - public function purchase(Purchase $purchase); + public function purchase(Purchase $purchase): int; } diff --git a/includes/ServiceModules/Interfaces/IServicePurchaseExternal.php b/includes/ServiceModules/Interfaces/IServicePurchaseExternal.php index 808d275f9..16095e8a2 100644 --- a/includes/ServiceModules/Interfaces/IServicePurchaseExternal.php +++ b/includes/ServiceModules/Interfaces/IServicePurchaseExternal.php @@ -16,5 +16,5 @@ interface IServicePurchaseExternal extends IServicePurchase * @param Purchase $purchase * @return Validator */ - public function purchaseDataValidate(Purchase $purchase); + public function purchaseDataValidate(Purchase $purchase): Validator; } diff --git a/includes/ServiceModules/Interfaces/IServicePurchaseWeb.php b/includes/ServiceModules/Interfaces/IServicePurchaseWeb.php index 32f6b5d4a..560ca04a5 100644 --- a/includes/ServiceModules/Interfaces/IServicePurchaseWeb.php +++ b/includes/ServiceModules/Interfaces/IServicePurchaseWeb.php @@ -5,47 +5,44 @@ use App\Models\Transaction; /** - * Możliwość zakupu usługi przez stronę WWWW - * Implementacja tego interfejsu powinna pociągnąć za sobą implementacje interfejsu: - * IServicePurchase + * Possibility to purchase the service via the website */ interface IServicePurchaseWeb extends IServicePurchase { /** - * Metoda powinna zwracać formularz zakupu w postaci stringa + * Returns a purchase fom * * @param array $query - * @return string - Formularz zakupu + * @return string */ - public function purchaseFormGet(array $query); + public function purchaseFormGet(array $query): string; /** - * Metoda wywoływana, gdy użytkownik wprowadzi dane w formularzu zakupu - * i trzeba sprawdzić, czy są one prawidłowe + * Method called when the data provided by a user in the purchase form + * needs to be validated * * @param Purchase $purchase * @param array $body */ - public function purchaseFormValidate(Purchase $purchase, array $body); + public function purchaseFormValidate(Purchase $purchase, array $body): void; /** - * Metoda zwraca szczegóły zamówienia, wyświetlane podczas zakupu usługi, przed płatnością. + * Returns the order details, displayed when purchasing the service, before payment. * * @param Purchase $purchase - * - * @return string Szczegóły zamówienia + * @return string */ - public function orderDetails(Purchase $purchase); + public function orderDetails(Purchase $purchase): string; /** - * Metoda formatuje i zwraca informacje o zakupionej usłudze, zaraz po jej zakupie. + * Formats and returns information about the purchased service. * - * @param string $action Do czego zostaną te dane użyte ( email, web, payment_log ) - * email - wiadomość wysłana na maila o zakupie usługi - * web - informacje wyświetlone na stronie WWW zaraz po zakupie - * payment_log - wpis w historii płatności + * @param string $action What will the data be used for (email, web, payment_log) + * email - a message sent to the email about the purchase of the service + * web - information displayed on the website right after the purchase + * payment_log - entry in the payment history * @param Transaction $transaction - * @return string|array Informacje o zakupionej usłudze + * @return string|array */ public function purchaseInfo($action, Transaction $transaction); } diff --git a/includes/ServiceModules/Interfaces/IServiceTakeOver.php b/includes/ServiceModules/Interfaces/IServiceTakeOver.php index 78ace7f23..4fae44bb8 100644 --- a/includes/ServiceModules/Interfaces/IServiceTakeOver.php +++ b/includes/ServiceModules/Interfaces/IServiceTakeOver.php @@ -2,27 +2,27 @@ namespace App\ServiceModules\Interfaces; /** - * Obsługa przejmowania usług przez użytkowników + * Support for service take over by a user */ interface IServiceTakeOver { /** - * Zwraca formularz przejęcia usługi + * Generates a service takeover form * * @return string */ - public function serviceTakeOverFormGet(); + public function serviceTakeOverFormGet(): string; /** - * Sprawdza poprawność danych wprowadzonych w formularzu przejęcia usługi - * a jeżeli wszystko jest ok, to ją przejmuje + * Checks the correctness of the data entered in the service takeover form + * and if everything is ok, it takes over * * @param array $body * * @return array - * status => id wiadomości - * text => treść wiadomości - * positive => czy udało się przejąć usługę + * status => message id + * text => message body + * positive => whether the service took over */ - public function serviceTakeOver(array $body); + public function serviceTakeOver(array $body): array; } diff --git a/includes/ServiceModules/Interfaces/IServiceUserOwnServices.php b/includes/ServiceModules/Interfaces/IServiceUserOwnServices.php index e90da52d7..1aa1051f9 100644 --- a/includes/ServiceModules/Interfaces/IServiceUserOwnServices.php +++ b/includes/ServiceModules/Interfaces/IServiceUserOwnServices.php @@ -4,20 +4,19 @@ use App\Models\UserService; /** - * Obsługa wyświetlania użytkownikowi jego usług + * Support for displaying its services to the user */ interface IServiceUserOwnServices { /** - * Metoda powinna zwrócić informacje o usłudze użytkownika. - * Są one następnie wyświetlane na stronie user_own_services + * The method should return information about the user service. + * These are then displayed on the user_own_services page * * @param UserService $userService - * @param string $buttonEdit String przycisku do edycji usługi - * (jeżeli moduł ma mieć mozliwość edycji usług przez użytkownika, - * musisz ten przycisk umieścić w informacjach o usłudze) - * - * @return string Informacje o usłudze + * @param string $buttonEdit Button to edit the service + * (if the module is to be able to edit services by the user, + * you must include this button in the service information) + * @return string */ - public function userOwnServiceInfoGet(UserService $userService, $buttonEdit); + public function userOwnServiceInfoGet(UserService $userService, $buttonEdit): string; } diff --git a/includes/ServiceModules/Interfaces/IServiceUserOwnServicesEdit.php b/includes/ServiceModules/Interfaces/IServiceUserOwnServicesEdit.php index 034485b11..06d15eeed 100644 --- a/includes/ServiceModules/Interfaces/IServiceUserOwnServicesEdit.php +++ b/includes/ServiceModules/Interfaces/IServiceUserOwnServicesEdit.php @@ -15,7 +15,7 @@ interface IServiceUserOwnServicesEdit * @param UserService $userService * @return string */ - public function userOwnServiceEditFormGet(UserService $userService); + public function userOwnServiceEditFormGet(UserService $userService): string; /** * Validate form and edit user service diff --git a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminAdd.php b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminAdd.php index a1646eecb..2320515ee 100644 --- a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminAdd.php +++ b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminAdd.php @@ -13,12 +13,12 @@ interface IServiceUserServiceAdminAdd * * @param Request $request */ - public function userServiceAdminAdd(Request $request); + public function userServiceAdminAdd(Request $request): void; /** * Provide additional user service add form fields * * @return string */ - public function userServiceAdminAddFormGet(); + public function userServiceAdminAddFormGet(): string; } diff --git a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminDisplay.php b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminDisplay.php index 3ccedcd21..627ffca25 100644 --- a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminDisplay.php +++ b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminDisplay.php @@ -14,13 +14,13 @@ interface IServiceUserServiceAdminDisplay * * @return string */ - public function userServiceAdminDisplayTitleGet(); + public function userServiceAdminDisplayTitleGet(): string; /** * Provides list of users' services * * @param Request $request - * @return Wrapper | string + * @return Wrapper */ - public function userServiceAdminDisplayGet(Request $request); + public function userServiceAdminDisplayGet(Request $request): Wrapper; } diff --git a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminEdit.php b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminEdit.php index 13e7541f7..d3ae84b06 100644 --- a/includes/ServiceModules/Interfaces/IServiceUserServiceAdminEdit.php +++ b/includes/ServiceModules/Interfaces/IServiceUserServiceAdminEdit.php @@ -4,27 +4,25 @@ use App\Models\UserService; /** - * Obsługa edycji usług użytkownika w PA + * Support for editing user services in ACP */ interface IServiceUserServiceAdminEdit { /** - * Metoda sprawdza dane formularza podczas edycji usługi użytkownika w PA - * i gdy wszystko jest okej, to ją edytuje. + * The method checks the form data when editing the user service in ACP + * and when everything is fine, it edits it. * * @param array $body - * @param UserService $userService Obecne dane edytowanej usługi + * @param UserService $userService Current data of the edited service * @return bool */ - public function userServiceAdminEdit(array $body, UserService $userService); + public function userServiceAdminEdit(array $body, UserService $userService): bool; /** - * Metoda powinna zwrócić dodatkowe pola usługi - * podczas jej edycji w PA + * The method should return additional service fields during its edition in ACP * * @param UserService $userService - * * @return string */ - public function userServiceAdminEditFormGet(UserService $userService); + public function userServiceAdminEditFormGet(UserService $userService): string; } diff --git a/includes/ServiceModules/MybbExtraGroups/MybbExtraGroupsServiceModule.php b/includes/ServiceModules/MybbExtraGroups/MybbExtraGroupsServiceModule.php index 3f05c4b1e..e4826a5f3 100644 --- a/includes/ServiceModules/MybbExtraGroups/MybbExtraGroupsServiceModule.php +++ b/includes/ServiceModules/MybbExtraGroups/MybbExtraGroupsServiceModule.php @@ -47,6 +47,7 @@ use App\View\Html\ExpirationCell; use App\View\Html\HeadCell; use App\View\Html\NoneText; +use App\View\Html\PreWrapCell; use App\View\Html\Structure; use App\View\Html\UserRef; use App\View\Html\Wrapper; @@ -155,7 +156,7 @@ public function mapToUserService(array $data): MybbUserService return $this->mybbUserServiceRepository->mapToModel($data); } - public function serviceAdminExtraFieldsGet() + public function serviceAdminExtraFieldsGet(): string { if ($this->showOnWeb()) { $webSelYes = "selected"; @@ -177,7 +178,7 @@ public function serviceAdminExtraFieldsGet() ]); } - public function serviceAdminManagePre(Validator $validator) + public function serviceAdminManagePre(Validator $validator): void { $validator->extendRules([ "db_host" => [new RequiredRule()], @@ -189,7 +190,7 @@ public function serviceAdminManagePre(Validator $validator) ]); } - public function serviceAdminManagePost(array $body) + public function serviceAdminManagePost(array $body): array { $mybbGroups = explode(",", $body["mybb_groups"]); foreach ($mybbGroups as $key => $group) { @@ -213,12 +214,12 @@ public function serviceAdminManagePost(array $body) ]; } - public function userServiceAdminDisplayTitleGet() + public function userServiceAdminDisplayTitleGet(): string { return $this->lang->t("mybb_groups"); } - public function userServiceAdminDisplayGet(Request $request) + public function userServiceAdminDisplayGet(Request $request): Wrapper { $pagination = $this->paginationFactory->create($request); $queryParticle = new QueryParticle(); @@ -235,15 +236,25 @@ public function userServiceAdminDisplayGet(Request $request) $where = $queryParticle->isEmpty() ? "" : "WHERE {$queryParticle} "; $statement = $this->db->statement( - "SELECT SQL_CALC_FOUND_ROWS us.id, us.user_id, u.username, " . - "s.id AS `service_id`, s.name AS `service`, us.expire, usmeg.mybb_uid " . - "FROM `ss_user_service` AS us " . - "INNER JOIN `{$this->getUserServiceTable()}` AS usmeg ON usmeg.us_id = us.id " . - "LEFT JOIN `ss_services` AS s ON s.id = usmeg.service_id " . - "LEFT JOIN `ss_users` AS u ON u.uid = us.user_id " . - $where . - "ORDER BY us.id DESC " . - "LIMIT ?, ?" + <<getUserServiceTable()}` AS usmeg ON usmeg.us_id = us.id + LEFT JOIN `ss_services` AS s ON s.id = usmeg.service_id + LEFT JOIN `ss_users` AS u ON u.uid = us.user_id + {$where} + ORDER BY us.id DESC + LIMIT ?, ? + EOF ); $statement->execute(array_merge($queryParticle->params(), $pagination->getSqlLimit())); $rowsCount = $this->db->query("SELECT FOUND_ROWS()")->fetchColumn(); @@ -260,6 +271,7 @@ public function userServiceAdminDisplayGet(Request $request) ->addCell(new Cell($row["service"])) ->addCell(new Cell($row["mybb_uid"])) ->addCell(new ExpirationCell($row["expire"])) + ->addCell(new PreWrapCell($row["comment"])) ->setDeleteAction(can(Permission::MANAGE_USER_SERVICES())) ->setEditAction(false); }) @@ -271,13 +283,14 @@ public function userServiceAdminDisplayGet(Request $request) ->addHeadCell(new HeadCell($this->lang->t("service"))) ->addHeadCell(new HeadCell($this->lang->t("mybb_user"))) ->addHeadCell(new HeadCell($this->lang->t("expires"))) + ->addHeadCell(new HeadCell($this->lang->t("comment"))) ->addBodyRows($bodyRows) ->enablePagination("/admin/user_service", $pagination, $rowsCount); return (new Wrapper())->enableSearch()->setTable($table); } - public function purchaseFormGet(array $query) + public function purchaseFormGet(array $query): string { $quantities = collect($this->purchasePriceService->getServicePrices($this->service)) ->map( @@ -298,7 +311,7 @@ public function purchaseFormGet(array $query) ]); } - public function purchaseFormValidate(Purchase $purchase, array $body) + public function purchaseFormValidate(Purchase $purchase, array $body): void { $validator = new Validator( [ @@ -337,7 +350,7 @@ public function purchaseFormValidate(Purchase $purchase, array $body) } } - public function orderDetails(Purchase $purchase) + public function orderDetails(Purchase $purchase): string { $email = $purchase->getEmail() ?: $this->lang->t("none"); $username = $purchase->getOrder("username"); @@ -353,11 +366,10 @@ public function orderDetails(Purchase $purchase) ); } - public function purchase(Purchase $purchase) + public function purchase(Purchase $purchase): int { $mybbUser = $this->findMybbUser($purchase->getOrder("username")); - // Nie znaleziono użytkownika o takich danych jak podane podczas zakupu if (!$mybbUser) { $this->logger->log( "log_mybb_purchase_no_user", @@ -372,7 +384,8 @@ public function purchase(Purchase $purchase) $this->service->getId(), $purchase->user->getId(), $quantity, - $mybbUser->getUid() + $mybbUser->getUid(), + $purchase->getComment() ); foreach ($this->groups as $group) { @@ -444,7 +457,7 @@ public function purchaseInfo($action, Transaction $transaction) return ""; } - public function userServiceDelete(UserService $userService, $who) + public function userServiceDelete(UserService $userService, $who): bool { try { $this->mybbRepository->connectDb(); @@ -458,7 +471,7 @@ public function userServiceDelete(UserService $userService, $who) } } - public function userServiceDeletePost(UserService $userService) + public function userServiceDeletePost(UserService $userService): void { assert($userService instanceof MybbUserService); @@ -507,13 +520,7 @@ public function userServiceDeletePost(UserService $userService) $this->saveMybbUser($mybbUser); } - /** - * Metoda powinna zwrócić dodatkowe pola do uzupełnienia przez admina - * podczas dodawania usługi użytkownikowi - * - * @return string - */ - public function userServiceAdminAddFormGet() + public function userServiceAdminAddFormGet(): string { return $this->template->renderNoComments( "admin/services/mybb_extra_groups/user_service_admin_add", @@ -521,7 +528,7 @@ public function userServiceAdminAddFormGet() ); } - public function userServiceAdminAdd(Request $request) + public function userServiceAdminAdd(Request $request): void { $admin = $this->auth->user(); $forever = (bool) $request->request->get("forever"); @@ -531,6 +538,7 @@ public function userServiceAdminAdd(Request $request) "quantity" => as_int($request->request->get("quantity")), ]), [ + "comment" => [], "quantity" => $forever ? [] : [new RequiredRule(), new NumberRule(), new MinValueRule(0)], @@ -563,7 +571,8 @@ public function userServiceAdminAdd(Request $request) "username" => $validated["mybb_username"], Purchase::ORDER_QUANTITY => $forever ? null : $validated["quantity"], ]) - ->setEmail($validated["email"]); + ->setEmail($validated["email"]) + ->setComment($validated["comment"]); $boughtServiceId = $this->purchase($purchase); $this->logger->logWithActor( @@ -574,7 +583,7 @@ public function userServiceAdminAdd(Request $request) ); } - public function userOwnServiceInfoGet(UserService $userService, $buttonEdit) + public function userOwnServiceInfoGet(UserService $userService, $buttonEdit): string { assert($userService instanceof MybbUserService); @@ -596,7 +605,7 @@ public function userOwnServiceInfoGet(UserService $userService, $buttonEdit) * @param string|int $userId Int - by uid, String - by username * @return MybbUser|null */ - private function findMybbUser($userId) + private function findMybbUser($userId): ?MybbUser { if (is_integer($userId)) { $rawMybbUser = $this->mybbRepository->getUserByUid($userId); diff --git a/includes/ServiceModules/MybbExtraGroups/MybbRepositoryFactory.php b/includes/ServiceModules/MybbExtraGroups/MybbRepositoryFactory.php index d739f9c3d..4a9ad9c41 100644 --- a/includes/ServiceModules/MybbExtraGroups/MybbRepositoryFactory.php +++ b/includes/ServiceModules/MybbExtraGroups/MybbRepositoryFactory.php @@ -3,7 +3,7 @@ class MybbRepositoryFactory { - public function create($host, $port, $username, $password, $database) + public function create($host, $port, $username, $password, $database): MybbRepository { return new MybbRepository($host, $port, $username, $password, $database); } diff --git a/includes/ServiceModules/MybbExtraGroups/MybbUserGroupRepository.php b/includes/ServiceModules/MybbExtraGroups/MybbUserGroupRepository.php index 974dbd69c..4eebcee30 100644 --- a/includes/ServiceModules/MybbExtraGroups/MybbUserGroupRepository.php +++ b/includes/ServiceModules/MybbExtraGroups/MybbUserGroupRepository.php @@ -13,7 +13,7 @@ public function __construct(Database $db) $this->db = $db; } - public function createMany(array $rows) + public function createMany(array $rows): void { if (!$rows) { return; @@ -49,7 +49,7 @@ public function createMany(array $rows) /** * @param int $id */ - public function delete($id) + public function delete($id): void { $this->db->statement("DELETE FROM `ss_mybb_user_group` WHERE `uid` = ?")->execute([$id]); } @@ -58,7 +58,7 @@ public function delete($id) * @param int $id * @return array */ - public function findGroupsExpiration($id) + public function findGroupsExpiration($id): array { $statement = $this->db->statement( "SELECT `gid`, UNIX_TIMESTAMP(`expire`) - UNIX_TIMESTAMP() AS `expire`, `was_before` FROM `ss_mybb_user_group` " . diff --git a/includes/ServiceModules/MybbExtraGroups/MybbUserService.php b/includes/ServiceModules/MybbExtraGroups/MybbUserService.php index 4aaffe094..318412d3d 100644 --- a/includes/ServiceModules/MybbExtraGroups/MybbUserService.php +++ b/includes/ServiceModules/MybbExtraGroups/MybbUserService.php @@ -7,9 +7,9 @@ class MybbUserService extends UserService { private int $mybbUid; - public function __construct($id, $serviceId, $userId, $expire, $mybbUid) + public function __construct($id, $serviceId, $userId, $expire, $comment, $mybbUid) { - parent::__construct($id, $serviceId, $userId, $expire); + parent::__construct($id, $serviceId, $userId, $expire, $comment); $this->mybbUid = $mybbUid; } diff --git a/includes/ServiceModules/MybbExtraGroups/MybbUserServiceRepository.php b/includes/ServiceModules/MybbExtraGroups/MybbUserServiceRepository.php index 9d42c1d21..23b1b86c5 100644 --- a/includes/ServiceModules/MybbExtraGroups/MybbUserServiceRepository.php +++ b/includes/ServiceModules/MybbExtraGroups/MybbUserServiceRepository.php @@ -21,38 +21,37 @@ public function __construct(Database $db, UserServiceRepository $userServiceRepo * @param int $userId * @param int|null $seconds * @param int $mybbUid - * @return MybbUserService|null + * @param string|null $comment + * @return MybbUserService */ - public function create($serviceId, $userId, $seconds, $mybbUid) + public function create($serviceId, $userId, $seconds, $mybbUid, $comment): MybbUserService { $table = MybbExtraGroupsServiceModule::USER_SERVICE_TABLE; + $userService = $this->findByServiceIdAndMybbUid($serviceId, $mybbUid); - // Dodajemy usługę gracza do listy usług - // Jeżeli już istnieje dokładnie taka sama, to ją przedłużamy - $statement = $this->db->statement( - "SELECT `us_id` FROM `{$table}` WHERE `service_id` = ? AND `mybb_uid` = ?" - ); - $statement->execute([$serviceId, $mybbUid]); - - if ($statement->rowCount()) { - $row = $statement->fetch(); - $userServiceId = $row["us_id"]; - - $this->userServiceRepository->updateWithModule($table, $userServiceId, [ + if ($userService) { + $this->userServiceRepository->updateWithModule($table, $userService->getId(), [ "user_id" => $userId, "mybb_uid" => $mybbUid, "expire" => $seconds === null ? null : new Expression("`expire` + $seconds"), + "comment" => trim($userService->getComment() . "\n---\n" . $comment), ]); - } else { - $userServiceId = $this->userServiceRepository->create($serviceId, $seconds, $userId); - $this->db - ->statement( - "INSERT INTO `{$table}` (`us_id`, `service_id`, `mybb_uid`) VALUES (?, ?, ?)" - ) - ->execute([$userServiceId, $serviceId, $mybbUid]); + return $userService; } + $userServiceId = $this->userServiceRepository->create( + $serviceId, + $seconds, + $userId, + $comment + ); + $this->db + ->statement( + "INSERT INTO `{$table}` (`us_id`, `service_id`, `mybb_uid`) VALUES (?, ?, ?)" + ) + ->execute([$userServiceId, $serviceId, $mybbUid]); + return $this->get($userServiceId); } @@ -60,7 +59,7 @@ public function create($serviceId, $userId, $seconds, $mybbUid) * @param $id * @return MybbUserService|null */ - public function get($id) + public function get($id): ?MybbUserService { if ($id) { $table = MybbExtraGroupsServiceModule::USER_SERVICE_TABLE; @@ -79,6 +78,21 @@ public function get($id) return null; } + public function findByServiceIdAndMybbUid($serviceId, $mybbUid): ?MybbUserService + { + $table = MybbExtraGroupsServiceModule::USER_SERVICE_TABLE; + $statement = $this->db->statement( + "SELECT `us_id` FROM `{$table}` WHERE `service_id` = ? AND `mybb_uid` = ?" + ); + $statement->execute([$serviceId, $mybbUid]); + + if ($data = $statement->fetch()) { + return $this->mapToModel($data); + } + + return null; + } + public function mapToModel(array $data): MybbUserService { return new MybbUserService( @@ -86,6 +100,7 @@ public function mapToModel(array $data): MybbUserService as_string($data["service_id"]), as_int($data["user_id"]), as_int($data["expire"]), + as_string($data["comment"]), as_int($data["mybb_uid"]) ); } diff --git a/includes/ServiceModules/Other/OtherServiceModule.php b/includes/ServiceModules/Other/OtherServiceModule.php index a76b40eee..4842a2dfa 100644 --- a/includes/ServiceModules/Other/OtherServiceModule.php +++ b/includes/ServiceModules/Other/OtherServiceModule.php @@ -35,7 +35,7 @@ public function __construct( $this->boughtServiceService = $boughtServiceService; } - public function purchaseDataValidate(Purchase $purchase) + public function purchaseDataValidate(Purchase $purchase): Validator { return new Validator( [ @@ -53,7 +53,7 @@ public function purchaseDataValidate(Purchase $purchase) ); } - public function purchase(Purchase $purchase) + public function purchase(Purchase $purchase): int { $promoCode = $purchase->getPromoCode(); @@ -72,17 +72,17 @@ public function purchase(Purchase $purchase) ); } - public function serviceAdminManagePost(array $body) + public function serviceAdminManagePost(array $body): array { return []; } - public function serviceAdminExtraFieldsGet() + public function serviceAdminExtraFieldsGet(): string { return ""; } - public function serviceAdminManagePre(Validator $validator) + public function serviceAdminManagePre(Validator $validator): void { // } diff --git a/includes/ServiceModules/ServiceModule.php b/includes/ServiceModules/ServiceModule.php index a4273b78b..d461266be 100644 --- a/includes/ServiceModules/ServiceModule.php +++ b/includes/ServiceModules/ServiceModule.php @@ -38,7 +38,8 @@ public function mapToUserService(array $data): UserService as_int($data["id"]), as_string($data["service_id"]), as_int($data["user_id"]), - as_int($data["expire"]) + as_int($data["expire"]), + as_string($data["comment"]) ); } @@ -47,7 +48,7 @@ public function mapToUserService(array $data): UserService * * @param int $serviceId ID usługi */ - public function serviceDelete($serviceId) + public function serviceDelete($serviceId): void { // } @@ -60,7 +61,7 @@ public function serviceDelete($serviceId) * * @return bool */ - public function userServiceDelete(UserService $userService, $who) + public function userServiceDelete(UserService $userService, $who): bool { return true; } @@ -70,7 +71,7 @@ public function userServiceDelete(UserService $userService, $who) * * @param UserService $userService */ - public function userServiceDeletePost(UserService $userService) + public function userServiceDeletePost(UserService $userService): void { // } @@ -78,10 +79,10 @@ public function userServiceDeletePost(UserService $userService) /** * Metoda powinna zwrócić, czy usługa ma być wyświetlana na stronie WWW. */ - public function showOnWeb() + public function showOnWeb(): bool { if ($this->service !== null) { - return array_get($this->service->getData(), "web", false); + return (bool) array_get($this->service->getData(), "web", false); } return false; @@ -94,23 +95,23 @@ public function showOnWeb() * * @return string Description */ - public function descriptionLongGet() + public function descriptionLongGet(): string { $templatePath = $this->serviceDescriptionService->getTemplatePath($this->service->getId()); return $this->template->render($templatePath, [], true, false); } - public function descriptionShortGet() + public function descriptionShortGet(): string { return $this->service->getDescriptionI18n(); } - public function getModuleId() + public function getModuleId(): string { return $this::MODULE_ID; } - protected function getUserServiceTable() + protected function getUserServiceTable(): string { return $this::USER_SERVICE_TABLE; } diff --git a/includes/Verification/PaymentModules/CashBill.php b/includes/Verification/PaymentModules/CashBill.php index bc36041a4..f128f9777 100644 --- a/includes/Verification/PaymentModules/CashBill.php +++ b/includes/Verification/PaymentModules/CashBill.php @@ -85,7 +85,7 @@ public function prepareTransfer(Money $price, Purchase $purchase) "method" => "POST", "data" => [ "service" => $this->getService(), - "desc" => $purchase->getDescription(), + "desc" => $purchase->getTransferDescription(), "forname" => $purchase->user->getForename(), "surname" => $purchase->user->getSurname(), "email" => $purchase->getEmail(), @@ -94,7 +94,7 @@ public function prepareTransfer(Money $price, Purchase $purchase) "sign" => md5( $this->getService() . $price->asPrice() . - $purchase->getDescription() . + $purchase->getTransferDescription() . $userData . $purchase->user->getForename() . $purchase->user->getSurname() . diff --git a/includes/Verification/PaymentModules/MicroSMS.php b/includes/Verification/PaymentModules/MicroSMS.php index 82a5da572..553c47006 100644 --- a/includes/Verification/PaymentModules/MicroSMS.php +++ b/includes/Verification/PaymentModules/MicroSMS.php @@ -114,7 +114,7 @@ public function prepareTransfer(Money $price, Purchase $purchase) "/api/ipn/transfer/{$this->paymentPlatform->getId()}" ), "return_url" => $this->url->to("/page/payment_success"), - "description" => $purchase->getDescription(), + "description" => $purchase->getTransferDescription(), ], ]; } diff --git a/includes/Verification/PaymentModules/PayPal.php b/includes/Verification/PaymentModules/PayPal.php index e9915ae8f..2344b2f41 100644 --- a/includes/Verification/PaymentModules/PayPal.php +++ b/includes/Verification/PaymentModules/PayPal.php @@ -74,7 +74,7 @@ public function prepareTransfer(Money $price, Purchase $purchase) "currency_code" => $this->settings->getCurrency(), "value" => $price->asPrice(), ], - "description" => $purchase->getDescription(), + "description" => $purchase->getTransferDescription(), "custom_id" => $purchase->getId(), ], ], diff --git a/includes/Verification/PaymentModules/TPay.php b/includes/Verification/PaymentModules/TPay.php index f56c2c490..c8601cc5e 100644 --- a/includes/Verification/PaymentModules/TPay.php +++ b/includes/Verification/PaymentModules/TPay.php @@ -32,7 +32,7 @@ public function prepareTransfer(Money $price, Purchase $purchase) "data" => [ "id" => $this->getAccountId(), "kwota" => $price->asPrice(), - "opis" => $purchase->getDescription(), + "opis" => $purchase->getTransferDescription(), "crc" => $crc, "md5sum" => md5($this->getAccountId() . $price->asPrice() . $crc . $this->getKey()), "imie" => $purchase->user->getForename(), diff --git a/includes/View/Html/BodyRow.php b/includes/View/Html/BodyRow.php index ffcde1243..9a4490cf7 100644 --- a/includes/View/Html/BodyRow.php +++ b/includes/View/Html/BodyRow.php @@ -15,7 +15,7 @@ class BodyRow extends Row private bool $editAction = false; private bool $deleteAction = false; - public function toHtml() + public function toHtml(): string { // Zachowujemy poprzedni stan, aby go przywrocic $oldContents = $this->contents; diff --git a/includes/View/Html/DOMElement.php b/includes/View/Html/DOMElement.php index f89590e23..1136ad2d5 100644 --- a/includes/View/Html/DOMElement.php +++ b/includes/View/Html/DOMElement.php @@ -33,7 +33,7 @@ public function __construct($tag, $content = null, array $params = []) } } - public function toHtml() + public function toHtml(): string { $oldParams = $this->params; diff --git a/includes/View/Html/I_ToHtml.php b/includes/View/Html/I_ToHtml.php index 4c5d8bb34..1f314ebfe 100644 --- a/includes/View/Html/I_ToHtml.php +++ b/includes/View/Html/I_ToHtml.php @@ -3,10 +3,5 @@ interface I_ToHtml { - /** - * Tworzy kod html elementu - * - * @return string - */ - public function toHtml(); + public function toHtml(): string; } diff --git a/includes/View/Html/PlainText.php b/includes/View/Html/PlainText.php index f701e2d2e..812fd8022 100644 --- a/includes/View/Html/PlainText.php +++ b/includes/View/Html/PlainText.php @@ -13,7 +13,7 @@ public function __construct($text) $this->text = (string) $text; } - public function toHtml() + public function toHtml(): string { return htmlspecialchars($this->text); } diff --git a/includes/View/Html/PreWrapCell.php b/includes/View/Html/PreWrapCell.php new file mode 100644 index 000000000..06e0eb93d --- /dev/null +++ b/includes/View/Html/PreWrapCell.php @@ -0,0 +1,13 @@ +text = (string) $text; } - public function toHtml() + public function toHtml(): string { return $this->text; } diff --git a/includes/View/Html/Structure.php b/includes/View/Html/Structure.php index 64ce2d520..ac7e97e49 100644 --- a/includes/View/Html/Structure.php +++ b/includes/View/Html/Structure.php @@ -20,7 +20,7 @@ public function __construct($content = null) $this->addClass("table is-fullwidth is-hoverable"); } - public function toHtml() + public function toHtml(): string { /** @var TranslationManager $translationManager */ $translationManager = app()->make(TranslationManager::class); diff --git a/includes/View/Html/Wrapper.php b/includes/View/Html/Wrapper.php index 31b4e1194..74a9067a5 100644 --- a/includes/View/Html/Wrapper.php +++ b/includes/View/Html/Wrapper.php @@ -19,7 +19,7 @@ public function __construct() $this->addClass("table-structure"); } - public function toHtml() + public function toHtml(): string { /** @var Template $template */ $template = app()->make(Template::class); @@ -57,56 +57,39 @@ public function toHtml() return $output; } - /** - * @return string - */ - public function getTitle() + public function getTitle(): ?string { return $this->title; } /** * @param string $title - * @return $this + * @return self */ - public function setTitle($title) + public function setTitle($title): self { $this->title = $title; return $this; } - /** - * @param DOMElement $element - * @return $this - */ - public function addButton($element) + public function addButton(DOMElement $element): self { $this->buttons[] = $element; return $this; } - /** - * @return $this - */ - public function enableSearch() + public function enableSearch(): self { $this->search = true; return $this; } - /** - * @return Structure - */ - public function getTable() + public function getTable(): ?Structure { return $this->table; } - /** - * @param Structure $table - * @return $this - */ - public function setTable($table) + public function setTable(Structure $table): self { $this->table = $table; return $this; diff --git a/includes/View/Pages/Admin/PageAdmin.php b/includes/View/Pages/Admin/PageAdmin.php index 82269a5ac..eddfddb78 100644 --- a/includes/View/Pages/Admin/PageAdmin.php +++ b/includes/View/Pages/Admin/PageAdmin.php @@ -20,10 +20,7 @@ public function getPrivilege() return Permission::ACP(); } - /** - * @return string - */ - public function getPagePath() + public function getPagePath(): string { return "/admin/{$this->getId()}"; } diff --git a/includes/View/Pages/Admin/PageAdminUserService.php b/includes/View/Pages/Admin/PageAdminUserService.php index c7492b8c1..bd25de994 100644 --- a/includes/View/Pages/Admin/PageAdminUserService.php +++ b/includes/View/Pages/Admin/PageAdminUserService.php @@ -69,25 +69,18 @@ public function getContent(Request $request) return $this->lang->t("no_subpage"); } - $wrapper = $serviceModule->userServiceAdminDisplayGet($request); - - if (get_class($wrapper) !== Wrapper::class) { - return $wrapper; - } - - $wrapper->setTitle($this->getTitle($request)); - $wrapper->addButton($this->createModuleSelectBox($subPage)); - - if (can(Permission::MANAGE_USER_SERVICES())) { - $button = (new Input()) - ->setParam("id", "user_service_button_add") - ->setParam("type", "button") - ->addClass("button is-small") - ->setParam("value", $this->lang->t("add_service")); - $wrapper->addButton($button); - } - - return $wrapper; + return $serviceModule + ->userServiceAdminDisplayGet($request) + ->setTitle($this->getTitle($request)) + ->addButton($this->createModuleSelectBox($subPage)) + ->when(can(Permission::MANAGE_USER_SERVICES()), function (Wrapper $wrapper) { + $button = (new Input()) + ->setParam("id", "user_service_button_add") + ->setParam("type", "button") + ->addClass("button is-small") + ->setParam("value", $this->lang->t("add_service")); + $wrapper->addButton($button); + }); } public function getActionBox($boxId, array $query) @@ -116,22 +109,21 @@ public function getActionBox($boxId, array $query) case "edit": $userService = $this->userServiceService->findOne($query["id"]); - $serviceModuleId = 0; - $formData = $this->lang->t("service_edit_unable"); - - if ($userService) { - $serviceModule = $this->serviceModuleManager->get($userService->getServiceId()); + if (!$userService) { + throw new EntityNotFoundException(); + } - if ($serviceModule instanceof IServiceUserServiceAdminEdit) { - $serviceModuleId = $serviceModule->getModuleId(); - $formData = $serviceModule->userServiceAdminEditFormGet($userService); - } + $serviceModule = $this->serviceModuleManager->get($userService->getServiceId()); + if (!($serviceModule instanceof IServiceUserServiceAdminEdit)) { + throw new EntityNotFoundException(); } - return $this->template->render( - "admin/action_boxes/user_service_edit", - compact("serviceModuleId", "formData") - ); + return $this->template->render("admin/action_boxes/user_service_edit", [ + "comment" => $userService->getComment(), + "formData" => $serviceModule->userServiceAdminEditFormGet($userService), + "serviceModuleId" => $serviceModule->getModuleId(), + "userServiceId" => $userService->getId(), + ]); default: throw new EntityNotFoundException(); diff --git a/includes/View/Pages/Page.php b/includes/View/Pages/Page.php index 00f06d793..7675d6f70 100644 --- a/includes/View/Pages/Page.php +++ b/includes/View/Pages/Page.php @@ -43,7 +43,7 @@ public function getId() return $this::PAGE_ID; } - public function getPagePath() + public function getPagePath(): string { return "/page/{$this->getId()}"; } diff --git a/includes/functions.php b/includes/functions.php index 409abcf80..8f3dc46d1 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -574,7 +574,7 @@ function as_datetime($value): ?DateTime * @param string|int|DateTime|null $value * @return string */ -function as_date_string($value) +function as_date_string($value): string { $date = as_datetime($value); return $date ? $date->format("Y-m-d") : ""; @@ -583,9 +583,9 @@ function as_date_string($value) /** * @param int|string|DateTime|null $value * @param string $format - * @return string + * @return string|null */ -function as_datetime_string($value, $format = "") +function as_datetime_string($value, $format = ""): ?string { if (!strlen($format)) { /** @var Settings $settings */ @@ -601,7 +601,7 @@ function as_datetime_string($value, $format = "") * @param int|string|DateTime|null $value * @return string */ -function as_expiration_date_string($value) +function as_expiration_date_string($value): string { if ($value === -1 || $value === null) { return __("never"); @@ -614,9 +614,9 @@ function as_expiration_date_string($value) * @param int|string|DateTime|null $value * @return string */ -function as_expiration_datetime_string($value) +function as_expiration_datetime_string($value): ?string { - if ($value === -1 || $value === null) { + if ($value === -1 || $value === "-1" || $value === null) { return __("never"); } @@ -627,7 +627,7 @@ function as_expiration_datetime_string($value) * @param DateTime|null $date * @return string|null */ -function serialize_date($date) +function serialize_date($date): ?string { return $date ? $date->format("Y-m-d H:i:s") : null; } @@ -636,7 +636,7 @@ function serialize_date($date) * @param string|float $value * @return int|null */ -function price_to_int($value) +function price_to_int($value): ?int { if ($value === null || $value === "") { return null; @@ -650,7 +650,7 @@ function price_to_int($value) * @param Permission[] $permissions * @return array */ -function as_permission_list($permissions) +function as_permission_list($permissions): array { return collect($permissions) ->map(function ($permission) { @@ -669,7 +669,7 @@ function as_permission_list($permissions) * @param mixed $value * @return bool */ - function is_iterable($value) + function is_iterable($value): bool { return is_array($value) || $value instanceof Traversable; } @@ -678,7 +678,7 @@ function is_iterable($value) /** * @return bool */ -function is_debug() +function is_debug(): bool { $debug = getenv("APP_DEBUG"); return $debug === "1" || $debug === "true" || $debug === 1; @@ -695,7 +695,7 @@ function is_testing() /** * @return bool */ -function is_demo() +function is_demo(): bool { return getenv("APP_ENV") === "demo"; } @@ -704,7 +704,7 @@ function is_demo() * @param mixed $value * @return bool */ -function has_value($value) +function has_value($value): bool { if (is_array($value) || is_object($value)) { return !!$value; @@ -717,7 +717,7 @@ function has_value($value) * @param string $text * @param array $data */ -function log_info($text, array $data = []) +function log_info($text, array $data = []): void { /** @var FileLogger $logger */ $logger = app()->make(FileLogger::class); @@ -753,7 +753,7 @@ function map_to_params($data) * @param mixed $items * @return array */ -function to_array($items) +function to_array($items): array { if ($items instanceof Traversable) { return iterator_to_array($items); diff --git a/migrations/2021_02_06_122300_add_user_service_comment_column.php b/migrations/2021_02_06_122300_add_user_service_comment_column.php new file mode 100644 index 000000000..e12659534 --- /dev/null +++ b/migrations/2021_02_06_122300_add_user_service_comment_column.php @@ -0,0 +1,11 @@ +db->query("ALTER TABLE `ss_user_service` ADD `comment` TEXT NOT NULL"); + } +} diff --git a/src/js/admin/pages/user_service/main.ts b/src/js/admin/pages/user_service/main.ts index 97775735e..c47e5f628 100644 --- a/src/js/admin/pages/user_service/main.ts +++ b/src/js/admin/pages/user_service/main.ts @@ -80,10 +80,10 @@ $(document).delegate("[id^=delete_row_]", "click", function () { $.ajax({ type: "DELETE", url: buildUrl("/api/admin/user_services/" + userServiceId), - complete: function () { + complete() { loader.hide(); }, - success: function (content) { + success(content) { if (!content.return_id) { return sthWentWrong(); } @@ -117,10 +117,10 @@ $(document).delegate(".table-structure .delete_row", "click", function () { $.ajax({ type: "DELETE", url: buildUrl("/api/admin/user_services/" + userServiceId), - complete: function () { + complete() { loader.hide(); }, - success: function (content) { + success(content) { if (!content.return_id) { return sthWentWrong(); } @@ -150,10 +150,10 @@ $(document).delegate("#form_user_service_add", "submit", function (e) { type: "POST", url: buildUrl("/api/admin/services/" + serviceId + "/user_services"), data: $(this).serialize(), - complete: function () { + complete() { loader.hide(); }, - success: function (content) { + success(content) { removeFormWarnings(); if (!content.return_id) { @@ -184,10 +184,10 @@ $(document).delegate("#form_user_service_edit", "submit", function (e) { type: "PUT", url: buildUrl("/api/admin/user_services/" + userServiceId), data: $(this).serialize(), - complete: function () { + complete() { loader.hide(); }, - success: function (content) { + success(content) { removeFormWarnings(); if (!content.return_id) { diff --git a/src/stylesheets/admin/admin.scss b/src/stylesheets/admin/admin.scss index 83e588b24..0208c7f2a 100644 --- a/src/stylesheets/admin/admin.scss +++ b/src/stylesheets/admin/admin.scss @@ -92,6 +92,10 @@ h4 { white-space: nowrap; } + [headers="prewrap"] { + white-space: pre-wrap; + } + [headers="actions"] { overflow: initial; } diff --git a/tests/Feature/Http/Api/Admin/UserServiceCollectionExtraFlagTest.php b/tests/Feature/Http/Api/Admin/UserServiceCollectionExtraFlagTest.php index 92b526af2..d8475f445 100644 --- a/tests/Feature/Http/Api/Admin/UserServiceCollectionExtraFlagTest.php +++ b/tests/Feature/Http/Api/Admin/UserServiceCollectionExtraFlagTest.php @@ -33,11 +33,12 @@ public function add_user_service() // when $response = $this->post("/api/admin/services/vip/user_services", [ - "type" => ExtraFlagType::TYPE_NICK, "auth_data" => "michal", + "comment" => "my comment", "password" => "abc123", "quantity" => "5", "server_id" => $server->getId(), + "type" => ExtraFlagType::TYPE_NICK, ]); // then @@ -56,6 +57,7 @@ public function add_user_service() $this->assertSame($server->getId(), $userService->getServerId()); $this->assertSame(0, $userService->getUserId()); $this->assertAlmostSameTimestamp($expectedExpire, $userService->getExpire()); + $this->assertEquals("my comment", $userService->getComment()); $playerFlag = $this->playerFlagRepository->getByCredentials( $server->getId(), @@ -79,24 +81,27 @@ public function adding_the_same_user_service_twice_prolongs_it() // when $this->post("/api/admin/services/vip/user_services", [ - "type" => (string) ExtraFlagType::TYPE_NICK, "auth_data" => "michal", + "comment" => "foo", "password" => "abc123", "quantity" => "5", "server_id" => $server->getId(), + "type" => (string) ExtraFlagType::TYPE_NICK, ]); $this->post("/api/admin/services/vip/user_services", [ - "type" => (string) ExtraFlagType::TYPE_NICK, "auth_data" => "michal", + "comment" => "bar", "password" => "abc123", "quantity" => "6", "server_id" => $server->getId(), + "type" => (string) ExtraFlagType::TYPE_NICK, ]); // then $userServices = $this->userServiceService->find(); $this->assertCount(1, $userServices); $this->assertAlmostSameTimestamp($expectedExpire, $userServices[0]->getExpire()); + $this->assertEquals("foo\n---\nbar", $userServices[0]->getComment()); $playerFlag = $this->playerFlagRepository->getByCredentials( $server->getId(), diff --git a/tests/Feature/Http/Api/Admin/UserServiceCollectionMybbTest.php b/tests/Feature/Http/Api/Admin/UserServiceCollectionMybbTest.php index b5947a7ce..cfaa6d7ed 100644 --- a/tests/Feature/Http/Api/Admin/UserServiceCollectionMybbTest.php +++ b/tests/Feature/Http/Api/Admin/UserServiceCollectionMybbTest.php @@ -40,6 +40,7 @@ public function add_user_service() // when $response = $this->post("/api/admin/services/{$service->getId()}/user_services", [ + "comment" => "foo", "mybb_username" => "example", "quantity" => "5", ]); @@ -55,6 +56,7 @@ public function add_user_service() $this->assertSame($service->getId(), $userService->getServiceId()); $this->assertSame(1, $userService->getMybbUid()); $this->assertSame(0, $userService->getUserId()); + $this->assertSame("foo", $userService->getComment()); $this->assertAlmostSameTimestamp($expectedExpire, $userService->getExpire()); } } diff --git a/tests/Feature/Http/Api/Admin/UserServiceResourceTest.php b/tests/Feature/Http/Api/Admin/UserServiceResourceTest.php index b6cff2dda..c020627bd 100644 --- a/tests/Feature/Http/Api/Admin/UserServiceResourceTest.php +++ b/tests/Feature/Http/Api/Admin/UserServiceResourceTest.php @@ -32,6 +32,7 @@ public function updates_user_service() $server = $this->factory->server(); $userService = $this->factory->extraFlagUserService([ + "comment" => "foo", "server_id" => $server->getId(), ]); $expireTimestamp = time() + 24321; @@ -39,10 +40,11 @@ public function updates_user_service() // when $response = $this->put("/api/admin/user_services/{$userService->getId()}", [ "auth_data" => "STEAM_1:1:21984552", - "type" => ExtraFlagType::TYPE_SID, + "comment" => "bar", "expire" => as_datetime_string($expireTimestamp, "Y-m-d H:i:s"), "server_id" => $server->getId(), "service_id" => "vip", + "type" => ExtraFlagType::TYPE_SID, "user_id" => $user->getId(), ]); @@ -56,6 +58,7 @@ public function updates_user_service() $this->assertSame("", $freshUserService->getPassword()); $this->assertSame($user->getId(), $freshUserService->getUserId()); $this->assertSame($expireTimestamp, $freshUserService->getExpire()); + $this->assertSame("bar", $freshUserService->getComment()); $playerFlag = $this->playerFlagRepository->getByCredentials( $server->getId(), ExtraFlagType::TYPE_SID, diff --git a/tests/Feature/Payment/General/PurchaseSerializerTest.php b/tests/Feature/Payment/General/PurchaseSerializerTest.php index 0e22eaf3a..adb8df35d 100644 --- a/tests/Feature/Payment/General/PurchaseSerializerTest.php +++ b/tests/Feature/Payment/General/PurchaseSerializerTest.php @@ -113,7 +113,7 @@ private function createComplexPurchase() ]) ->setServiceId("vip") ->setEmail("example@example.com") - ->setDescription("example"); + ->setTransferDescription("example"); $purchase ->getPaymentSelect() diff --git a/tests/Feature/Payment/TransferPaymentServiceTest.php b/tests/Feature/Payment/TransferPaymentServiceTest.php index 27173fdc5..15552462c 100644 --- a/tests/Feature/Payment/TransferPaymentServiceTest.php +++ b/tests/Feature/Payment/TransferPaymentServiceTest.php @@ -66,7 +66,7 @@ public function pays_with_transfer() ) ->setUsingPrice($price) ->setServiceId($serviceModule->service->getId()) - ->setDescription("Description"); + ->setTransferDescription("Description"); $purchase->getPaymentSelect()->setTransferPaymentPlatforms([$paymentPlatform->getId()]); diff --git a/tests/Psr4/Factory.php b/tests/Psr4/Factory.php index a0ddcd802..73b819ed6 100644 --- a/tests/Psr4/Factory.php +++ b/tests/Psr4/Factory.php @@ -330,13 +330,14 @@ public function extraFlagUserService(array $attributes = []): ExtraFlagUserServi { $attributes = array_merge( [ - "service_id" => "vip", - "user_id" => null, + "auth_data" => "my_nickname", + "comment" => null, + "password" => "pokll12", "seconds" => 35 * 24 * 60 * 60, "server_id" => null, + "service_id" => "vip", "type" => ExtraFlagType::TYPE_NICK, - "auth_data" => "my_nickname", - "password" => "pokll12", + "user_id" => null, ], $attributes ); @@ -348,7 +349,8 @@ public function extraFlagUserService(array $attributes = []): ExtraFlagUserServi $attributes["server_id"], $attributes["type"], $attributes["auth_data"], - $attributes["password"] + $attributes["password"], + $attributes["comment"] ); } @@ -356,10 +358,11 @@ public function mybbUserService(array $attributes = []): MybbUserService { $attributes = array_merge( [ + "comment" => null, + "mybb_uid" => 1, + "seconds" => 35 * 24 * 60 * 60, "service_id" => fn() => $this->mybbService()->getId(), "user_id" => null, - "seconds" => 35 * 24 * 60 * 60, - "mybb_uid" => 1, ], $attributes ); @@ -368,7 +371,8 @@ public function mybbUserService(array $attributes = []): MybbUserService resolve($attributes["service_id"]), $attributes["user_id"], $attributes["seconds"], - $attributes["mybb_uid"] + $attributes["mybb_uid"], + $attributes["comment"] ); } diff --git a/themes/fusion/admin/action_boxes/user_service_add.html b/themes/fusion/admin/action_boxes/user_service_add.html index 28754a141..6c89ec907 100644 --- a/themes/fusion/admin/action_boxes/user_service_add.html +++ b/themes/fusion/admin/action_boxes/user_service_add.html @@ -1,18 +1,18 @@
-
{$lang->t('add_user_service')}
+
{{ __('add_user_service') }}
+ + + + + + + + + + + diff --git a/themes/fusion/admin/action_boxes/user_service_edit.html b/themes/fusion/admin/action_boxes/user_service_edit.html index 9b2569c03..c90f57a81 100644 --- a/themes/fusion/admin/action_boxes/user_service_edit.html +++ b/themes/fusion/admin/action_boxes/user_service_edit.html @@ -1,5 +1,49 @@ -
{$lang->t('edit_user_service')}
+
{{ __('edit_user_service') }}
- {$formData} +
- +
@@ -20,13 +20,36 @@
+ + +
+
+ +
+
+
- +
+ + + + + + + + + + + {!! $formData !!} + + + + + + + + + + + + + + + + + + + +
ID{{ $userServiceId }}
+ + +
+
+ +
+
+
+ + +
diff --git a/themes/fusion/admin/services/extra_flags/user_service_admin_add.html b/themes/fusion/admin/services/extra_flags/user_service_admin_add.html index 20eeb5405..9d41abf16 100644 --- a/themes/fusion/admin/services/extra_flags/user_service_admin_add.html +++ b/themes/fusion/admin/services/extra_flags/user_service_admin_add.html @@ -1,7 +1,7 @@ - +
@@ -13,15 +13,15 @@ - +
@@ -91,7 +91,7 @@ - +
@@ -132,15 +132,15 @@ - +
@@ -149,7 +149,7 @@ - +
@@ -162,7 +162,7 @@ />
diff --git a/themes/fusion/admin/services/extra_flags/user_service_admin_edit.html b/themes/fusion/admin/services/extra_flags/user_service_admin_edit.html index 5fc1400e8..538657bed 100644 --- a/themes/fusion/admin/services/extra_flags/user_service_admin_edit.html +++ b/themes/fusion/admin/services/extra_flags/user_service_admin_edit.html @@ -1,169 +1,153 @@ - - - - - - - - - - - - + + + - - - - + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - -
ID{{ $userServiceId }}
- - -
-
- -
+
+ + +
+
+
-
- - -
-
-
- -
+
+
+ + +
+
+
+
-
- - -
-
- -
+
+
+ + +
+
+
-
- - -
-
- -
+
+
+ + +
+
+
-
- - -
-
- -
+
+
+ + +
+
+
-
- - -
-
- -
+
+
+ + +
+
+
-
- - -
-
-
- -
+
+
+ + +
+
+
+
-
- - -
-
-
- -
+
+
+ + +
+
+
+
-
- - -
-
- -
+
+
+ + +
+
+
- -
- - -
+
+ + + + diff --git a/themes/fusion/admin/services/mybb_extra_groups/user_service_admin_add.html b/themes/fusion/admin/services/mybb_extra_groups/user_service_admin_add.html index 84615102a..6e679aa60 100644 --- a/themes/fusion/admin/services/mybb_extra_groups/user_service_admin_add.html +++ b/themes/fusion/admin/services/mybb_extra_groups/user_service_admin_add.html @@ -1,7 +1,7 @@ - +
@@ -13,7 +13,7 @@ - +
@@ -30,7 +30,7 @@ - +
@@ -51,7 +51,7 @@ - +
@@ -62,7 +62,7 @@ diff --git a/translations/english/admin/general.php b/translations/english/admin/general.php index 2371e6409..f6523023c 100644 --- a/translations/english/admin/general.php +++ b/translations/english/admin/general.php @@ -29,6 +29,7 @@ "charge" => "Charge", "choose_sms_price" => "Choose SMS price", "code" => "Code", + "comment" => "Comment", "confirm" => "Confirm", "confirm_remove_server" => 'Do you really want to remove server \n{0}?', "create" => "Create", @@ -216,7 +217,6 @@ "service_added" => 'Service added successfully.
Set service prices in tab Pricing
Whereas in tab Servers set servers on which you can buy this service.
', "service_edit" => "Service edited successfully.", - "service_edit_unable" => "This service cannot be edited.", "service_no_edit" => "Service not edited.", "service_servers_hint" => "List of servers where you can purchase this service", "services" => "Services", diff --git a/translations/polish/admin/general.php b/translations/polish/admin/general.php index 13758e720..defb9b9de 100644 --- a/translations/polish/admin/general.php +++ b/translations/polish/admin/general.php @@ -29,6 +29,7 @@ "charge" => "Doładuj", "choose_sms_price" => "Wybierz koszt SMSa", "code" => "Kod", + "comment" => "Komentarz", "confirm" => "Zatwierdź", "confirm_remove_server" => 'Na pewno chcesz usunąć serwer\n{0}?', "create" => "Utwórz", @@ -219,7 +220,6 @@ "service_added" => 'Usługa została prawidłowo dodana.
Ustaw teraz ceny usługi w zakładce Cennik
Natomiast w zakładce Serwery ustal na których serwerach będzie można tę usługę zakupić.
', "service_edit" => "Usługa została prawidłowo wyedytowana.", - "service_edit_unable" => "Tej usługi nie da rady się edytować.", "service_no_edit" => "Usługa nie została wyedytowana.", "service_servers_hint" => "Lista serwerów na których można zakupić tę usługę", "services" => "Usługi",