false, 'code' => 'invalid_params', 'message' => __('Veuillez renseigner une année ou une plage de dates.', 'esi_crvi_agenda'), 'csv' => null ]; } // Dispatch selon l'entité switch ($entite) { case 'global': $result = self::events_stats($begin, $end, $attributes); break; // case 'intervenant': // $result = self::intervenant_stats($begin, $end, $attributes); // break; // case 'departement': // $result = self::departement_stats($begin, $end, $attributes); // break; // case 'type_intervention': // $result = self::type_intervention_stats($begin, $end, $attributes); // break; // case 'traducteur': // $result = self::traducteur_stats($begin, $end, $attributes); // break; default: return [ 'success' => false, 'code' => 'invalid_params', 'message' => __('Entité non reconnue.', 'esi_crvi_agenda'), 'csv' => null ]; } return $result; } /** * Exemple : Statistiques globales sur les événements. * @param string $begin * @param string $end * @param array $attributes * @return array */ public static function events_stats(string $begin, string $end, array $attributes = []): array { $event_model = new CRVI_Event_Model(); $events = $event_model->get_events_by('date_rdv', $begin, $attributes, $begin, $end); if (empty($events)) { return [ 'success' => false, 'code' => 'no_data', 'message' => __('Aucune donnée trouvée pour la période sélectionnée.', 'esi_crvi_agenda'), 'csv' => null ]; } // Exemple d'en-tête et de lignes (à adapter selon besoins réels) $header = ['ID', 'Date', 'Heure', 'Type', 'Statut', 'Département', 'Type intervention', 'Langue']; $rows = []; foreach ($events as $event) { $rows[] = [ $event['id'] ?? '', $event['date_rdv'] ?? '', $event['heure_rdv'] ?? '', $event['type'] ?? '', $event['statut'] ?? '', $event['departement'] ?? '', $event['type_intervention'] ?? '', $event['langue'] ?? '', ]; } return [ 'success' => true, 'code' => 'success', 'message' => __('Export CSV généré avec succès.', 'esi_crvi_agenda'), 'csv' => [ 'header' => $header, 'rows' => $rows ] ]; } // À compléter : intervenant_stats, departement_stats, etc. //intervenant_stats /* public static function intervenant_stats(string $begin, string $end, array $attributes = []): array { $intervenants = CRVI_Intervenant_Model::all(); $event_model = new CRVI_Event_Model(); $header = [__('Intervenant', 'esi_crvi_agenda'), __('Nombre d\'événements', 'esi_crvi_agenda')]; $rows = []; foreach ($intervenants as $intervenant) { $count = count($event_model->get_events_by('id_intervenant', (string)$intervenant->ID, $attributes, $begin, $end)); if ($count > 0) { $rows[] = [ get_the_title($intervenant->ID), $count ]; } } if (empty($rows)) { return [ 'success' => false, 'code' => 'no_data', 'message' => __('Aucune donnée trouvée pour la période sélectionnée.', 'esi_crvi_agenda'), 'csv' => null ]; } return [ 'success' => true, 'code' => 'success', 'message' => __('Export CSV généré avec succès.', 'esi_crvi_agenda'), 'csv' => [ 'header' => $header, 'rows' => $rows ] ]; } */ //departement_stats public static function departement_stats(string $begin, string $end, array $attributes = []): array { // Récupérer tous les départements (CPT) $departements = \ESI_CRVI_AGENDA\models\CRVI_Departement_Model::all(); $event_model = new \ESI_CRVI_AGENDA\models\CRVI_Event_Model(); $header = [__('Département', 'esi_crvi_agenda'), __('Nombre d\'événements', 'esi_crvi_agenda')]; $rows = []; foreach ($departements as $departement) { $count = count($event_model->get_events_by('departement', (string)$departement->ID, $attributes, $begin, $end)); if ($count > 0) { $rows[] = [ get_the_title($departement->ID), $count ]; } } if (empty($rows)) { return [ 'success' => false, 'code' => 'no_data', 'message' => __('Aucune donnée trouvée pour la période sélectionnée.', 'esi_crvi_agenda'), 'csv' => null ]; } return [ 'success' => true, 'code' => 'success', 'message' => __('Export CSV généré avec succès.', 'esi_crvi_agenda'), 'csv' => [ 'header' => $header, 'rows' => $rows ] ]; } //type_intervention_stats public static function type_intervention_stats(string $begin, string $end, array $attributes = []): array { // Récupérer tous les types d'intervention (CPT) $types = \ESI_CRVI_AGENDA\models\CRVI_Type_Intervention_Model::all(); $event_model = new \ESI_CRVI_AGENDA\models\CRVI_Event_Model(); $header = [__('Type d\'intervention', 'esi_crvi_agenda'), __('Nombre d\'événements', 'esi_crvi_agenda')]; $rows = []; foreach ($types as $type) { $count = count($event_model->get_events_by('type_intervention', (string)$type->ID, $attributes, $begin, $end)); if ($count > 0) { $rows[] = [ get_the_title($type->ID), $count ]; } } if (empty($rows)) { return [ 'success' => false, 'code' => 'no_data', 'message' => __('Aucune donnée trouvée pour la période sélectionnée.', 'esi_crvi_agenda'), 'csv' => null ]; } return [ 'success' => true, 'code' => 'success', 'message' => __('Export CSV généré avec succès.', 'esi_crvi_agenda'), 'csv' => [ 'header' => $header, 'rows' => $rows ] ]; } }