Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Nieto2020/portalhub/llms.txt

Use this file to discover all available pages before exploring further.

The notifications module (modules/notificaciones/) provides a lightweight in-app notification inbox for every user. Notifications are created in two ways: automatically by NotificationService when platform events occur (new appointments, uploaded documents, payment updates), and manually by admins or advisors through the dedicated endpoints. All notifications are stored in the notificaciones table and are only ever visible to their designated recipient.

Notification Record Fields

ColumnTypeDescription
id_notificacionintAuto-increment primary key
id_usuario_destinoint (FK)The user who will see the notification
tipo_eventostringFree-form event category (e.g. "Cita", "Documento", "Pago", "sistema")
mensaje_textostringHuman-readable notification message
leidaboolfalse by default; set to true when the user reads it
fecha_creaciondatetimeTimestamp of insertion

NotificationService

NotificationService.php is a shared PHP class used by other backend modules to fire notifications without repeating database logic. Any module that needs to alert a user simply instantiates the service and calls notify():
class NotificationService {
    private $conexion;

    public function __construct($conexion) {
        $this->conexion = $conexion;
    }

    public function notify($userId, $type, $message) {
        try {
            $stmt = $this->conexion->prepare(
                "INSERT INTO notificaciones (id_usuario_destino, tipo_evento, mensaje_texto)
                 VALUES (?, ?, ?)"
            );
            return $stmt->execute([$userId, $type, $message]);
        } catch (PDOException $e) {
            return false;
        }
    }
}

When Notifications Are Auto-Created

NotificationService::notify() is called automatically in the following scenarios:

New Appointment

When citas/crear.php saves a new appointment, the assigned advisor receives a "Cita" notification: “Se ha programado una nueva cita para el: .

Document Uploaded by Client

When a client uploads a document via documentos/subir.php, their active advisor receives a "Documento" notification with the original filename.

Document Uploaded by Advisor/Admin

When an advisor or admin uploads a document to a client’s record, the client receives a "Documento" notification.

Payment Updates

Payment status changes can trigger a "Pago" notification to the affected client when integrated with pagos/actualizar_estado.php.

Creating a Single Notification (Manual)

Endpoint: POST modules/notificaciones/crear.php Restricted to ROL_ADMIN and ROL_ASESOR. Allows staff to push a targeted notification to any specific user. Required fields:
FieldTypeDescription
id_usuario_destinointRecipient user ID
tipo_eventostringEvent category label
mensaje_textostringNotification message body
{
  "id_usuario_destino": 12,
  "tipo_evento": "Recordatorio",
  "mensaje_texto": "Recuerde que su declaración trimestral vence el 17 de julio."
}

Bulk Broadcast Notifications (Admin Only)

Endpoint: POST modules/notificaciones/crear_masivo.php Only ROL_ADMIN may call this endpoint. It creates an identical notification for every user matching the specified role list inside a single database transaction. The tipo_evento is automatically set to 'sistema' for all bulk notifications. Required fields:
FieldTypeDescription
titulostringShort title prepended to the message
contenidostringBody of the notification
Optional fields:
FieldTypeDescription
rolesint[]Target role IDs (default: [1, 2, 3] — all roles)
The stored mensaje_texto is formatted as:
{titulo}: {contenido}
{
  "titulo": "Actualización de plataforma",
  "contenido": "Se han incorporado mejoras de seguridad. Recuerde actualizar su contraseña.",
  "roles": [3]
}
$conexion->beginTransaction();

$stmt = $conexion->prepare(
    "SELECT id_usuario FROM usuarios WHERE id_rol IN ($placeholders)"
);
$stmt->execute($roles);
$usuarios = $stmt->fetchAll(PDO::FETCH_ASSOC);

$insert = $conexion->prepare(
    "INSERT INTO notificaciones (id_usuario_destino, tipo_evento, mensaje_texto)
     VALUES (?, 'sistema', ?)"
);

foreach ($usuarios as $u) {
    $insert->execute([$u['id_usuario'], $mensaje]);
}

$conexion->commit();
All inserts in crear_masivo.php are wrapped in a transaction. If any insertion fails, rollBack() is called and no partial notifications are persisted.

Listing Notifications

Endpoint: GET modules/notificaciones/listar.php Returns all notifications addressed to the logged-in user (id_usuario_destino = id_usuario), ordered by fecha_creacion DESC. This endpoint powers the portal’s notification bell/inbox. Response item shape:
{
  "id_notificacion": 501,
  "id_usuario_destino": 12,
  "tipo_evento": "Documento",
  "mensaje_texto": "Se ha subido un nuevo documento a su expediente: declaracion_anual.pdf",
  "leida": false,
  "fecha_creacion": "2025-07-15 09:43:01"
}

Marking Notifications as Read

Endpoint: POST modules/notificaciones/marcar_leido.php Accepts an id_notificacion and sets leida = 1 for the matching record. The endpoint verifies ownership (the notification’s id_usuario_destino must match the session user) to prevent users from marking each other’s notifications read.
{
  "id_notificacion": 501
}
Poll listar.php on a short interval (e.g., every 30 seconds) to keep the unread notification badge in the portal header up to date. Combine with marcar_leido.php when the user opens the notification panel to clear the badge count.

Build docs developers (and LLMs) love