Commit faff979b authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

Ajout ROR

parent efb628e5
Loading
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -65,6 +65,47 @@ class SiretController extends AbstractOscarController implements UseLoggerServic
                        $response->setVariables(['erreur' => $e->getMessage()]);
                        return $response;
                    }
                } else if ($action_json->action == "recherche-ror") {

                    $curl = curl_init();
                    $url = 'https://api.ror.org/v2/organizations?query=' . urlencode($action_json->search);
                    curl_setopt($curl, CURLOPT_URL, $url);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                    $return = curl_exec($curl);
                    $errno = curl_errno($curl);
                    if ($errno != 0) {
                      curl_close($curl);
                      $response = new Response();
                      $response->setStatusCode(Response::STATUS_CODE_500);
                      $response->setContent(curl_error($curl));
                      return $response;
                    }
                    $resultStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
                    if ($resultStatus != 200) {
                      curl_close($curl);
                      $response = new Response();
                      $response->setStatusCode(Response::STATUS_CODE_500);
                      $response->setContent($return);
                      return $response;
                    }
                    curl_close($curl);
          
                    $countries = $this->getEntityManager()->getRepository(\Oscar\Entity\Country3166::class)->allKeyByAlpha2();

                    $response_decode = json_decode($return, true);
                    for ($i = 0; $i < count($response_decode['items']); $i++) {
                        for ($j = 0; $j < count($response_decode['items'][$i]['locations']); $j++) {
                            $code = $response_decode['items'][$i]['locations'][$j]['geonames_details']['country_code'];
                            if (array_key_exists($code, $countries)) {
                                $response_decode['items'][$i]['locations'][$j]['geonames_details']['country_name_fr'] = $countries[$code]->getFr();
                            }
                        }
                    }

                    $response = new JsonModel();
                    $response->setVariables($response_decode);
                    return $response;
          
                }
            }

+8 −3
Original line number Diff line number Diff line
@@ -494,9 +494,14 @@
                    document.getElementsByName('street2')[0].value = urlParams.get('street2');
                    document.getElementsByName('zipCode')[0].value = urlParams.get('zipCode');
                    document.getElementsByName('city')[0].value = urlParams.get('city');
                    document.getElementsByName('country')[0].value = 'France';
                    document.getElementsByName('country')[0].nextSibling.firstChild.firstChild.firstChild.setAttribute('title', 'France');
                    document.getElementsByName('country')[0].nextSibling.firstChild.firstChild.firstChild.innerText = 'France';

                    let country = urlParams.get('country');
                    if (!country || country.trim() == '') {
                        country = 'France';
                    }
                    document.getElementsByName('country')[0].value = country;
                    document.getElementsByName('country')[0].nextSibling.firstChild.firstChild.firstChild.setAttribute('title', country);
                    document.getElementsByName('country')[0].nextSibling.firstChild.firstChild.firstChild.innerText = country;
                }, 100);
            }
        });
+281 −0
Original line number Diff line number Diff line
@@ -37,6 +37,63 @@
        </div>
      </template>
    </div>

    <h2>Research Organization Registry (<a href="https://ror.org/">ROR</a>)</h2>
    <form @submit.prevent="rorrechercher" style="background: white; padding: 1em;">
      <label for="ror-search-term">Saisissez un identifiant ROR ou le nom d'une organization :</label>
      <input style="margin-left: 1em;" id="ror-search-term" type="text" maxlength="1000" v-model="rorSearch" />
      <input style="margin-left: 1em;" class="btn btn-default" type="submit" value="🔍 Rechercher" />
      <span v-if="rorResponse && rorResponse.number_of_results == 0" style="margin-left: 1em; color: rgb(169, 68, 66);">La recherche n'a retourné aucun résultat.</span>
      <span v-if="rorResponse && rorResponse.number_of_results == 1" style="margin-left: 1em;">La recherche a retourné un résultat.</span>
      <span v-if="rorResponse && rorResponse.number_of_results > 1" style="margin-left: 1em;">La recherche a retourné {{ rorResponse.number_of_results }} résultats.</span>
      <span v-if="rorResponse && rorResponse.number_of_results > 20"> Seuls les 20 premiers sont affichés.</span>
    </form>

    <div v-if="rorResponse">
      <template v-for="i in rorResponse.items">
        <div class="card">
          <div style="display: flex; justify-content: space-between;">
            <div>
              <template v-for="n in i.names">
                <h3 v-if="n.types.includes('ror_display')" class="bold">{{ n.value }}</h3>
              </template>
            </div>

            <a :href="urlOrganizationNew + rorQueryString(i)" style="border: 1px solid #ccc; padding: 0.5em; color: #333;">➕ Pré-remplir une fiche de création d'organisation avec ces données</a>
          </div>

          <div><span style="font-weight: bold;">Identifiant ROR :</span> <a style="color: #1F7F67; font-weight: bolder;" :href="i.id">{{ i.id }}</a></div>
          <div><span style="font-weight: bold;">Types</span> : {{ i.types.join(", ") }}</div>
          <div style="font-weight: bold;">Autres noms :</div>
          <ul>
            <template v-for="n in i.names">
              <li v-if="!n.types.includes('label')" :class="{ bold: n.types.includes('label') }">{{ n.value }}</li>
            </template>      
          </ul>
          <div style="font-weight: bold;">Lieux :</div>
          <ul>
            <template v-for="l in i.locations">
              <li>{{ l.geonames_details.name }} (GeoNames ID <a :href="'https://www.geonames.org/' + l.geonames_id">{{ l.geonames_id }}</a>), {{ l.geonames_details.country_name }}</li>
            </template>      
          </ul>
          <div><span style="font-weight: bold;">Site web</span> :
            <template v-for="l in i.links">
              <a v-if="l.type == 'website'" :href="l.value">{{ l.value }}</a>
            </template>
          </div>
          <div style="font-weight: bold;">Autres identifiants :</div>
          <ul>
            <template v-for="e in i.external_ids">
              <li v-if="e.type == 'wikidata'">Wikidata: <a :href="'https://www.wikidata.org/wiki/' + e.all[0]">{{ e.all[0] }}</a></li>
              <li v-else-if="e.type == 'isni'">ISNI: <a :href="'http://isni.org/isni/' + e.all[0].replace(/\s/g, '')">{{ e.all[0] }}</a></li>
              <li v-else-if="e.type == 'fundref'">Crossref Funder ID: <a :href="'https://api.crossref.org/funders/' + e.all[0]">{{ e.all[0] }}</a></li>
              <li v-else>{{ e.type}}: {{ e.all[0] }}</li>
            </template>      
          </ul>
        </div>
      </template>
    </div>

</template>
<script>

@@ -68,6 +125,8 @@ export default {
      error: null,
      sireneSearch: null,
      sireneResponse: null,
      rorSearch: null,
      rorResponse: null,
    }
  },

@@ -93,6 +152,228 @@ export default {
      });
    },

    rorrechercher(e) {
      this.loading = "Recherche ROR";
      axios.post(this.urlSiretApi, { action: "recherche-ror", search: this.rorSearch }).then(
        (response) => {
          this.rorResponse = response.data;
        }, err => {
          this.handlerError(AxiosMessage.manageErrorResponse(err));
        }
      ).finally(() => { 
          this.loading = '';
      });
    },

    rorQueryString(rorResponse) {

      let shortName = '';
      for (let i = 0; i < rorResponse.names.length; i++) {
        if (rorResponse.names[i].lang != 'fr' && rorResponse.names[i].lang != null) {
          continue;
        }
        for (let j = 0; j < rorResponse.names[i].types.length; j++) {
          if (rorResponse.names[i].types[j] == 'acronym') {
            shortName = rorResponse.names[i].value;
            break;
          }
        }
        if (shortName != '') {
          break;
        }
      }
      if (shortName == '') {
        for (let i = 0; i < rorResponse.names.length; i++) {
          if (rorResponse.names[i].lang != 'fr') {
            continue;
          }
          if (shortName == '' || rorResponse.names[i].value.length < shortName.length) {
            shortName = rorResponse.names[i].value;
          }
        }
      }
      if (shortName == '') {
        for (let i = 0; i < rorResponse.names.length; i++) {
          if (rorResponse.names[i].lang != 'en') {
            continue;
          }
          for (let j = 0; j < rorResponse.names[i].types.length; j++) {
            if (rorResponse.names[i].types[j] == 'acronym') {
              shortName = rorResponse.names[i].value;
              break;
            }
          }
          if (shortName != '') {
            break;
          }
        }
        if (shortName == '') {
          for (let i = 0; i < rorResponse.names.length; i++) {
            if (rorResponse.names[i].lang != 'en') {
              continue;
            }
            if (shortName == '' || rorResponse.names[i].value.length < shortName.length) {
              shortName = rorResponse.names[i].value;
            }
          }
        }
      }
      if (shortName == '') {
        for (let i = 0; i < rorResponse.names.length; i++) {
          for (let j = 0; j < rorResponse.names[i].types.length; j++) {
            if (rorResponse.names[i].types[j] == 'acronym') {
              shortName = rorResponse.names[i].value;
              break;
            }
          }
          if (shortName != '') {
            break;
          }
        }
        if (shortName == '') {
          for (let i = 0; i < rorResponse.names.length; i++) {
            if (shortName == '' || rorResponse.names[i].value.length < shortName.length) {
              shortName = rorResponse.names[i].value;
            }
          }
        }
      }


      let fullName = '';
      for (let i = 0; i < rorResponse.names.length; i++) {
        if (rorResponse.names[i].lang != 'fr') {
          continue;
        }
        for (let j = 0; j < rorResponse.names[i].types.length; j++) {
          if (rorResponse.names[i].types[j] == 'label' || rorResponse.names[i].types[j] == 'ror_display') {
            fullName = rorResponse.names[i].value;
            break;
          }
        }
        if (fullName != '') {
          break;
        }
      }
      if (fullName.length <= shortName.length) {
        for (let i = 0; i < rorResponse.names.length; i++) {
          if (rorResponse.names[i].lang != 'fr') {
            continue;
          }
          for (let j = 0; j < rorResponse.names[i].types.length; j++) {
            if (rorResponse.names[i].types[j] == 'alias') {
              if (rorResponse.names[i].value.length > fullName.length) {
                fullName = rorResponse.names[i].value;
              }
            }
          }
        }
      }
      if (fullName == '') {
        for (let i = 0; i < rorResponse.names.length; i++) {
          if (rorResponse.names[i].lang != 'en') {
            continue;
          }
          for (let j = 0; j < rorResponse.names[i].types.length; j++) {
            if (rorResponse.names[i].types[j] == 'label' || rorResponse.names[i].types[j] == 'ror_display') {
              fullName = rorResponse.names[i].value;
              break;
            }
          }
          if (fullName != '') {
            break;
          }
        }
        if (fullName.length <= shortName.length) {
          for (let i = 0; i < rorResponse.names.length; i++) {
            if (rorResponse.names[i].lang != 'en') {
              continue;
            }
            for (let j = 0; j < rorResponse.names[i].types.length; j++) {
              if (rorResponse.names[i].types[j] == 'alias') {
                if (rorResponse.names[i].value.length > fullName.length) {
                  fullName = rorResponse.names[i].value;
                }
              }
            }
          }
        }
      }
      if (fullName == '') {
        for (let i = 0; i < rorResponse.names.length; i++) {
          for (let j = 0; j < rorResponse.names[i].types.length; j++) {
            if (rorResponse.names[i].types[j] == 'label' || rorResponse.names[i].types[j] == 'ror_display') {
              fullName = rorResponse.names[i].value;
              break;
            }
          }
          if (fullName != '') {
            break;
          }
        }
        if (fullName.length <= shortName.length) {
          for (let i = 0; i < rorResponse.names.length; i++) {
            for (let j = 0; j < rorResponse.names[i].types.length; j++) {
              if (rorResponse.names[i].types[j] == 'alias') {
                if (rorResponse.names[i].value.length > fullName.length) {
                  fullName = rorResponse.names[i].value;
                }
              }
            }
          }
        }
      }

      let countryName = '';
      for (let i = 0; i < rorResponse.locations.length; i++) {
        if (rorResponse.locations[i].geonames_details.country_name_fr) {
          countryName = rorResponse.locations[i].geonames_details.country_name_fr;
          break;
        }
      }

      let city = '';
      for (let i = 0; i < rorResponse.locations.length; i++) {
        city = rorResponse.locations[i].geonames_details.name;
        break;
      }
      
      if (fullName == '' && shortName == '' && countryName == '' && city == '') {
        return '';
      }

      let queryString = '';
      if (fullName != '') {
        queryString += '?fullName=' + fullName;
      }
      if (shortName != '') {
        if (queryString == '') {
          queryString += '?';
        } else {
          queryString += '&';
        }
        queryString += 'shortName=' + shortName;
      }
      if (countryName != '') {
        if (queryString == '') {
          queryString += '?';
        } else {
          queryString += '&';
        }
        queryString += 'country=' + countryName;
      }
      if (city != '') {
        if (queryString == '') {
          queryString += '?';
        } else {
          queryString += '&';
        }
        queryString += 'city=' + city;
      }

      return queryString;
    }

  },

  mounted() {