<?php

namespace App\Models;

use CodeIgniter\Model;

class UsersModel extends Model
 {
    protected $table            = 'users';
    protected $primaryKey       = 'id';
    protected $allowedFields    = ['email', 'mot_de_passe','status', 'id_personnel'];
    protected $useTimestamps    = true; // Active les champs created_at et updated_at

public function getUserEtEnfantData($email)
{
    return $this->select('users.*, 
                          personnel.nom,
                          users.status, 
                          personnel.prenom, 
                          personnel.telephone, 
                          personnel.matricule, 
                          users.email, 
                          structure.NOM_STRUCTURE,
                          enfant.id AS enfant_id,
                          enfant.nom AS enf_nom, 
                          enfant.prenom AS enf_prenom, 
                          enfant.sexe, 
                          enfant.age, 
                          enfant.type_parent')
                ->join('personnel', 'personnel.id = users.id_personnel')
                ->join('enfant', 'personnel.id = enfant.id_personnel', 'left')
                ->join('structure', 'structure.ID_STRUCTURE = personnel.ID_STRUCTURE')
                ->where('users.email', $email)
                ->first();
}
 }