You've already forked Atomcms-edit
33 lines
961 B
PHP
Executable File
33 lines
961 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\User;
|
|
use App\Services\RconService;
|
|
|
|
class SendFurniture
|
|
{
|
|
public function __construct(private readonly RconService $rcon) {}
|
|
|
|
/**
|
|
* @param array<int, array{item_id: int, amount: int}> $furniture
|
|
*/
|
|
public function execute(User $user, array $furniture): void
|
|
{
|
|
foreach ($furniture as $furni) {
|
|
if ($this->rcon->isConnected) {
|
|
for ($i = 0; $i < $furni['amount']; $i++) {
|
|
$hotelName = setting('hotel_name');
|
|
$this->rcon->sendGift($user, $furni['item_id'], 'Thank you for supporting ' . (is_scalar($hotelName) ? (string) $hotelName : ''));
|
|
}
|
|
} else {
|
|
for ($i = 0; $i < $furni['amount']; $i++) {
|
|
$user->items()->create([
|
|
'item_id' => $furni['item_id'],
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|