API.php 6.95 KiB
<?php
class API_EducationNationale{
    /**
     * API URL
     * @var string
     */
    const API_URL = 'https://data.education.gouv.fr/api/records/1.0/search';
    /**
    * Datasets
    * @var array
    const DATASETS = [
        'fr-en-adresse-et-geolocalisation-etablissements-premier-et-second-degre' => "Établissements premier et second degré",
        'fr-en-annuaire-education' => "Annuaire de l'éducation ",
        // 'fr-en-ecoles-labellisees-30-minutes-d-activite-physique-quotidienne-30-apq' => "Écoles labellisées «30 minutes d'activité physique quotidienne» (30'APQ)",
        // 'fr-en-etablissements-labellises-euroscol' => "name" => "Établissements labellisés Euroscol ",
    /**
    * Datasets
    * @var array
    const DATASETS_MAPPING = [
        'fr-en-adresse-et-geolocalisation-etablissements-premier-et-second-degre' => [
            "name" => "Établissements premier et second degré",
            "datasrc" => [
                "organization_name" => "appellation_officielle",
                "school_type" => "nature_uai_libe",
                "epsg_code" => "epsg",
                "external_identifier" => "numero_uai",
                "academy_code" => "code_academie",
                "academy_name" => "libelle_academie",
                "sector_code" => "secteur_prive_libelle_type_contrat",
                "sector" => "secteur_public_prive_libe",
                "status" => "etat_etablissement_libe",
                "opening_date" => "date_ouverture",
            'addressdatasrc' => [
                "geo_code_1" => "latitude",
                "geo_code_2" => "longitude",
                "street_address" => "adresse_uai",
                "postal_code" => "code_postal_uai",
                "city" => "localite_acheminement_uai",
        'fr-en-annuaire-education' => [
            "name" => "Annuaire de l'éducation ",
            "datasrc" => [
                "organization_name" => "nom_etablissement",
                "school_type" => "libelle_nature",
                "epsg_code" => "epsg_origine",
                "external_identifier" => "identifiant_de_l_etablissement",
                "academy_code" => "code_academie",
                "academy_name" => "libelle_academie",
                "sector_code" => "type_contrat_prive",
                "sector" => "statut_public_prive",
                "status" => "etat",
                "opening_date" => "date_ouverture",
            'addressdatasrc' => [
                "geo_code_1" => "latitude",
                "geo_code_2" => "longitude",
                "street_address" => "adresse_1",
                "postal_code" => "code_postal",
                "city" => "nom_commune",
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// 'fr-en-ecoles-labellisees-30-minutes-d-activite-physique-quotidienne-30-apq' => [ // "name" => "Écoles labellisées «30 minutes d'activité physique quotidienne» (30'APQ)", // "datasrc" => [ // "organization_name" => "", // "school_type" => "", // "latitude" => "", // "longitude" => "", // "address" => "", // "postal_code" => "", // "city" => "", // "epsg_code" => "", // "identifier" => "", // "academy_code" => "", // "academy_name" => "", // "sector_code" => "", // "sector" => "", // "status" => "", // "opening_date" => "", // ], // ], // 'fr-en-etablissements-labellises-euroscol' => [ // "name" => "Établissements labellisés Euroscol ", // "datasrc" => [ // "organization_name" => "", // "school_type" => "", // "latitude" => "", // "longitude" => "", // "address" => "", // "postal_code" => "", // "city" => "", // "epsg_code" => "", // "identifier" => "", // "academy_code" => "", // "academy_name" => "", // "sector_code" => "", // "sector" => "", // "status" => "", // "opening_date" => "", // ], // ], ]; public static function Call(array $params){ $url = SELF::API_URL.'?'.http_build_query($params); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_USERAGENT, 'WP-EXPERT Plugin API'); curl_setopt($curl, CURLOPT_REFERER, get_permalink()?:site_url()); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept-Language: fr,en-US;q=0.5")); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); $json = curl_exec($curl); return json_decode($json); } public static function fields() { return [ 'rows'=>[ 'name' => 'rows', 'title' => 'Rows (limit)', 'html_type' => 'Number', 'data_type' => 'Integer', 'type' => CRM_Utils_Type::T_INT, ], 'start'=>[ 'name' => 'start',
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
'title' => 'Start (offset)', 'html_type' => 'Number', 'data_type' => 'Integer', 'type' => CRM_Utils_Type::T_INT, ], 'q'=>[ 'name' => 'q', 'title' => 'Query', 'description' => 'A query string to search for. use "quotes" for exact match.', ], 'dataset'=>[ 'name' => 'dataset', 'title' => 'Dataset', 'data_type' => 'String', 'html_type' => 'Select', 'multiple' => false, 'required' => true, 'api.required' => true, 'options'=>SELF::DATASETS, 'choices'=>SELF::DATASETS, 'values'=>SELF::DATASETS, ], ]; } public static function public_fields(){ return [ 'organization_name'=>[ 'name' => 'organization_name', 'title' => 'Name', 'description' => 'A query string to search for.', ], 'street_address'=>[ 'name' => 'street_address', 'title' => 'Street address', ], 'postal_code'=>[ 'name' => 'postal_code', 'title' => 'Postal code', ], 'city'=>[ 'name' => 'city', 'title' => 'City', ], ]; } public static function REST(){ echo json_encode(civicrm_api3('educationNationale', 'get', $_GET)); } }