'success'|'error'|'info'|'warning', 'message' => '...'] */ public static function get_pending_messages(): array { $session_id = Session::get_session_id(); if ($session_id === null) { return []; } // Delete expired messages (older than 1 minute) Flash_Alert_Model::where('session_id', $session_id) ->where('created_at', '<', now()->subMinute()) ->delete(); // Get all pending flash alerts for this session $alerts = Flash_Alert_Model::where('session_id', $session_id) ->orderBy('created_at', 'asc') ->get(); if ($alerts->isEmpty()) { return []; } // Delete the alerts now that we're retrieving them Flash_Alert_Model::where('session_id', $session_id) ->delete(); // Convert to client format $messages = []; foreach ($alerts as $alert) { $messages[] = [ 'type' => $alert->get_type_string(), 'message' => $alert->message, ]; } return $messages; } /** * Create a flash message in the database * * @param string $message The message text * @param int $type_id The type ID (use Flash_Alert_Model constants) * @return void */ protected static function _create_message(string $message, int $type_id): void { $session_id = Session::get_session_id(); if ($session_id === null) { return; } $flash_alert = new Flash_Alert_Model(); $flash_alert->session_id = $session_id; $flash_alert->type_id = $type_id; $flash_alert->message = $message; $flash_alert->created_at = now(); $flash_alert->save(); } }