fix logic and tests, update docker CI file
This commit is contained in:
@@ -68,7 +68,7 @@ class AttendanceDay extends BaseModel
|
||||
$q = static::query()
|
||||
->select('id')
|
||||
->where('class_section_id', $classSectionId)
|
||||
->where('date', $date)
|
||||
->whereDate('date', $date)
|
||||
->where(function ($w) {
|
||||
$w->where('status', 'published')
|
||||
->orWhere('status', 'finalized'); // legacy
|
||||
@@ -91,7 +91,7 @@ class AttendanceDay extends BaseModel
|
||||
): ?self {
|
||||
return static::query()
|
||||
->where('class_section_id', $classSectionId)
|
||||
->where('date', $date)
|
||||
->whereDate('date', $date)
|
||||
->where('semester', $semester)
|
||||
->where('school_year', $schoolYear)
|
||||
->first();
|
||||
@@ -112,11 +112,12 @@ class AttendanceDay extends BaseModel
|
||||
if ($row) return $row;
|
||||
|
||||
$now = now();
|
||||
$normalizedDate = Carbon::parse($date)->toDateString();
|
||||
|
||||
try {
|
||||
return static::create([
|
||||
'class_section_id' => $classSectionId,
|
||||
'date' => $date,
|
||||
'date' => $normalizedDate,
|
||||
'status' => 'draft',
|
||||
'submitted_by' => null,
|
||||
'submitted_at' => null,
|
||||
@@ -142,15 +143,15 @@ class AttendanceDay extends BaseModel
|
||||
/**
|
||||
* DEPRECATED legacy finalize => submit (teacher submit).
|
||||
*/
|
||||
public static function finalize(int $id, int $userId): bool
|
||||
public function finalize(int $userId): bool
|
||||
{
|
||||
return static::submit($id, $userId, null);
|
||||
return $this->submit($userId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teacher submit: status => submitted (teacher locked, admin editable).
|
||||
*/
|
||||
public static function submit(int $id, int $userId, ?string $autoPublishAt = null): bool
|
||||
public function submit(int $userId, ?string $autoPublishAt = null): bool
|
||||
{
|
||||
$now = now();
|
||||
|
||||
@@ -165,17 +166,17 @@ class AttendanceDay extends BaseModel
|
||||
$payload['auto_publish_at'] = $autoPublishAt;
|
||||
}
|
||||
|
||||
return static::query()->whereKey($id)->update($payload) >= 0;
|
||||
return static::query()->whereKey($this->id)->update($payload) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin publish (hard lock): status => published.
|
||||
*/
|
||||
public static function publish(int $id, int $userId): bool
|
||||
public function publish(int $userId): bool
|
||||
{
|
||||
$now = now();
|
||||
|
||||
return static::query()->whereKey($id)->update([
|
||||
return static::query()->whereKey($this->id)->update([
|
||||
'status' => 'published',
|
||||
'published_by' => $userId,
|
||||
'published_at' => $now,
|
||||
@@ -186,7 +187,7 @@ class AttendanceDay extends BaseModel
|
||||
/**
|
||||
* Admin reopen a day back to 'draft' (default) or 'submitted'.
|
||||
*/
|
||||
public static function reopen(int $id, int $userId, string $toStatus = 'draft', ?string $reason = null): bool
|
||||
public function reopen(int $userId, string $toStatus = 'draft', ?string $reason = null): bool
|
||||
{
|
||||
if (!in_array($toStatus, ['draft', 'submitted'], true)) {
|
||||
throw new \InvalidArgumentException('toStatus must be "draft" or "submitted".');
|
||||
@@ -194,7 +195,7 @@ class AttendanceDay extends BaseModel
|
||||
|
||||
$now = now();
|
||||
|
||||
return static::query()->whereKey($id)->update([
|
||||
return static::query()->whereKey($this->id)->update([
|
||||
'status' => $toStatus,
|
||||
'reopened_by' => $userId,
|
||||
'reopened_at' => $now,
|
||||
@@ -202,4 +203,4 @@ class AttendanceDay extends BaseModel
|
||||
'updated_at' => $now,
|
||||
]) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user