exam recurring add daily + TorrentDeleted event

This commit is contained in:
lgb
2024-04-24 14:45:30 +08:00
parent 45a27fae46
commit 52c3365873
6 changed files with 48 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class TorrentDeleted
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public int $torrentId;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(int $torrentId)
{
$this->torrentId = $torrentId;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@@ -65,6 +65,7 @@ class Exam extends NexusModel
self::FILTER_USER_REGISTER_DAYS_RANGE => ['name' => 'User register days range'],
];
const RECURRING_DAILY = "Daily";
const RECURRING_WEEKLY = "Weekly";
const RECURRING_MONTHLY = "Monthly";
@@ -93,6 +94,7 @@ class Exam extends NexusModel
public static function listRecurringOptions(): array
{
return [
self::RECURRING_DAILY => nexus_trans("exam.recurring_daily"),
self::RECURRING_WEEKLY => nexus_trans("exam.recurring_weekly"),
self::RECURRING_MONTHLY => nexus_trans("exam.recurring_monthly"),
];
@@ -215,6 +217,8 @@ class Exam extends NexusModel
return $time->startOfWeek();
} elseif ($recurring == self::RECURRING_MONTHLY) {
return $time->startOfMonth();
} elseif ($recurring == self::RECURRING_DAILY) {
return $time->startOfDay();
}
throw new \RuntimeException("Invalid recurring: $recurring");
}
@@ -226,6 +230,8 @@ class Exam extends NexusModel
return $time->endOfWeek();
} elseif ($recurring == self::RECURRING_MONTHLY) {
return $time->endOfMonth();
} elseif ($recurring == self::RECURRING_DAILY) {
return $time->endOfDay();
}
throw new \RuntimeException("Invalid recurring: $recurring");
}