40 lines
901 B
PHP
40 lines
901 B
PHP
<?php
|
|
|
|
namespace App\Services\Scheduling\Data;
|
|
|
|
class SchedulingSlot
|
|
{
|
|
public function __construct(
|
|
public readonly int $hari,
|
|
public readonly int $sesi
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Membandingkan apakah dua slot sama (hari & sesi identik).
|
|
*/
|
|
public function equals(SchedulingSlot $other): bool
|
|
{
|
|
return $this->hari === $other->hari && $this->sesi === $other->sesi;
|
|
}
|
|
|
|
/**
|
|
* Mengembalikan string unik untuk keperluan hash/lookup.
|
|
* Contoh: hari=2, sesi=3 → "2-3"
|
|
*/
|
|
public function toKey(): string
|
|
{
|
|
return "{$this->hari}-{$this->sesi}";
|
|
}
|
|
|
|
/**
|
|
* Membuat SchedulingSlot dari string key.
|
|
* Contoh: "2-3" → SchedulingSlot(2, 3)
|
|
*/
|
|
public static function fromKey(string $key): self
|
|
{
|
|
[$hari, $sesi] = explode('-', $key);
|
|
return new self((int) $hari, (int) $sesi);
|
|
}
|
|
}
|