update api and add more features
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class LevelProgressionResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'current_level_id' => $this->current_level_id !== null ? (int) $this->current_level_id : null,
|
||||
'current_level_name' => (string) ($this->current_level_name ?? ''),
|
||||
'next_level_id' => $this->next_level_id !== null ? (int) $this->next_level_id : null,
|
||||
'next_level_name' => $this->next_level_name,
|
||||
'order_index' => (int) ($this->order_index ?? 0),
|
||||
'is_terminal' => (bool) $this->is_terminal,
|
||||
'is_active' => (bool) $this->is_active,
|
||||
'notes' => $this->notes,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PromotionAuditLogResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'promotion_id' => $this->promotion_id ? (int) $this->promotion_id : null,
|
||||
'student_id' => $this->student_id ? (int) $this->student_id : null,
|
||||
'user_id' => $this->user_id ? (int) $this->user_id : null,
|
||||
'action_type' => $this->action_type,
|
||||
'field' => $this->field,
|
||||
'old_value' => $this->old_value,
|
||||
'new_value' => $this->new_value,
|
||||
'notes' => $this->notes,
|
||||
'performed_at' => optional($this->performed_at)->toDateTimeString(),
|
||||
'created_at' => optional($this->created_at)->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PromotionReminderResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'promotion_id' => (int) ($this->promotion_id ?? 0),
|
||||
'student_id' => $this->student_id ? (int) $this->student_id : null,
|
||||
'parent_id' => $this->parent_id ? (int) $this->parent_id : null,
|
||||
'reminder_type' => $this->reminder_type,
|
||||
'channel' => $this->channel,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'sent_at' => optional($this->sent_at)->toDateTimeString(),
|
||||
'sent_by' => $this->sent_by ? (int) $this->sent_by : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* Admin/list shape for `student_promotion_records`. Accepts either an
|
||||
* Eloquent model or an associative array (so list endpoints can
|
||||
* decorate the row with student/parent context once and pass it
|
||||
* through unchanged).
|
||||
*/
|
||||
class StudentPromotionResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
$r = $this->resource;
|
||||
$get = static function (string $key, $default = null) use ($r) {
|
||||
if (is_array($r)) {
|
||||
return $r[$key] ?? $default;
|
||||
}
|
||||
return $r->{$key} ?? $default;
|
||||
};
|
||||
|
||||
return [
|
||||
'promotion_id' => (int) ($get('promotion_id') ?? 0),
|
||||
'student_id' => (int) ($get('student_id') ?? 0),
|
||||
'student_name' => $get('student_name'),
|
||||
'school_id' => $get('school_id'),
|
||||
'parent_id' => $get('parent_id') ? (int) $get('parent_id') : null,
|
||||
'parent_name' => $get('parent_name'),
|
||||
'parent_email' => $get('parent_email'),
|
||||
'current_school_year' => $get('current_school_year'),
|
||||
'next_school_year' => $get('next_school_year'),
|
||||
'current_level' => $get('current_level') ?? $get('current_level_name'),
|
||||
'promoted_level' => $get('promoted_level') ?? $get('promoted_level_name'),
|
||||
'promotion_status' => $get('promotion_status'),
|
||||
'enrollment_status' => $get('enrollment_status'),
|
||||
'enrollment_deadline' => $get('enrollment_deadline'),
|
||||
'parent_notified_at' => $get('parent_notified_at'),
|
||||
'enrollment_started_at' => $get('enrollment_started_at'),
|
||||
'enrollment_completed_at' => $get('enrollment_completed_at'),
|
||||
'promotion_finalized_at' => $get('promotion_finalized_at'),
|
||||
'final_average' => $get('final_average') !== null ? (float) $get('final_average') : null,
|
||||
'passed_current_level' => $get('passed_current_level'),
|
||||
'checklist' => $get('checklist'),
|
||||
'eligibility_notes' => $get('eligibility_notes'),
|
||||
'enrollment_id' => $get('enrollment_id') ? (int) $get('enrollment_id') : null,
|
||||
'updated_by' => $get('updated_by') ? (int) $get('updated_by') : null,
|
||||
'updated_at' => $get('updated_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user