Plugin Directory

Changeset 2879098


Ignore:
Timestamp:
03/13/2023 12:18:08 PM (3 years ago)
Author:
ccsd
Message:

fix query when affiliated author choice is selected

Location:
hal/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • hal/trunk/constantes.php

    r2879002 r2879098  
    77// Constante pour gérer certaines facettes
    88define('wphal_delimiter', '_FacetSep_');
     9define('wphal_delimiter_join', '_JoinSep_');
    910
    1011// Constante pour l'API
  • hal/trunk/wp-hal.php

    r2879002 r2879098  
    186186            $id = wphal_verifSolr($id);
    187187
    188             $facets = wphal_buildfacet($option_choix, $type=="structId_i"?$id:0);
     188            // in case the type is struct we need to split in order to build facet and display it back
     189            $structIDs =[];
     190            if($type=="structId_i"){
     191                $structIDs = explode(' OR ', $id);
     192            }
     193
     194            $facets = wphal_buildfacet($option_choix, $structIDs);
    189195            $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.mincount=1&facet=true':'';
    190196
     
    470476        <div class="display" id="wphal-affiliated" style="display: none;">
    471477            <h3 class="wphal-titre">' . __('Auteurs affiliés', 'wp-hal') . '</h3>';
    472             if (isset($json->facet_counts->facet_fields->affiliated) && !is_null($json->facet_counts->facet_fields->affiliated) && !empty($json->facet_counts->facet_fields->affiliated)) {
     478            $parsed_facetfield = wphal_parse_affiliation_facet($json->facet_counts->facet_fields, $structIDs);
     479            if (!empty($parsed_facetfield)) {
    473480                $content .= '<span id="triauteurs">';
    474481                $content .= '<button type="button" class="trial" id="triaff" onclick="toggleSort(this, true, \'wphal-aff\', \'affiliateduite\', \'triaff\'); return false;" style="font-size:16px;  text-decoration: none;" >Tri Alphabétique</button>';
     
    478485                $content .= '<div id="wphal-aff">';
    479486                $r = 0;
    480                 foreach ($json->facet_counts->facet_fields->affiliated as $res) {
     487                foreach ($parsed_facetfield as $author=>$count) {
    481488                    $r = $r + 1;
    482489                    if ($r > 10) {
    483490                        break;
    484491                    }
    485                     $name = explode(wphal_delimiter, $res[0]);
    486                     if($name[2] == 0){
    487                         $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[3]."\"");
     492                    $name = explode(wphal_delimiter, $author);
     493                    if($name[1] == 0){
     494                        $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\"");
    488495                    }else{
    489                         $q = "authIdPerson_i:$name[2]";
    490                     }
    491                     $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[3] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
     496                        $q = "authIdPerson_i:$name[1]";
     497                    }
     498                    $content .= '<li class="metadata" data-percentage="' . $count . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[2] . '</a><span class="wphal-nbmetadata">' . $count . '</span></li>';
    492499                }
    493500                $i = 1;
    494501                $content .= '<div id="affiliateduite" style="display:none;">';
    495                 foreach ($json->facet_counts->facet_fields->affiliated as $res) {
     502                foreach ($parsed_facetfield as $author=>$count) {
    496503                    if ($r < 10) {
    497504                        break;
     
    500507                        $i = $i + 1;
    501508                    } else {
    502                         $name = explode(wphal_delimiter, $res[0]);
    503                         if($name[2] == 0){
    504                             $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[3]."\"");
     509                        $name = explode(wphal_delimiter, $author);
     510                        if($name[1] == 0){
     511                            $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\"");
    505512                        }else{
    506                             $q = "authIdPerson_i:$name[2]";
     513                            $q = "authIdPerson_i:$name[1]";
    507514                        }
    508                         $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[3] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
     515                        $content .= '<li class="metadata" data-percentage="' . $count . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[2] . '</a><span class="wphal-nbmetadata">' . $count . '</span></li>';
    509516                    }
    510517                }
     
    10011008 *
    10021009 * @param array $option_choix
    1003  * @param int $structID to buid prefixed facet
     1010 * @param array $structIDs to build prefixed facet
    10041011 * @return array
    10051012 */
    1006 function wphal_buildfacet($option_choix, $structID=0)
     1013function wphal_buildfacet($option_choix, $structIDs)
    10071014{
    10081015    $facetQuery = [];
     
    10381045            if ($option == 'affiliated') {
    10391046                $facetField = 'structHasAuthIdHalPersonid_s';
    1040                 $facetPrefix = $structID . wphal_delimiter;
    1041                 $facetQuery[] = '&facet.field={!key=affiliated+facet.prefix=' . urlencode($facetPrefix) . '}' . urlencode($facetField);
     1047                foreach($structIDs as $k => $structID){
     1048                    $facetPrefix = $structID . wphal_delimiter;
     1049                    $facetQuery[] = '&facet.field={!key=affiliated_' . $k . '+facet.prefix=' . urlencode($facetPrefix) . '}' . urlencode($facetField);
     1050                }
    10421051            }
    10431052        }
     
    10451054    return $facetQuery;
    10461055}
     1056
    10471057function wphal_verifSolr($values){
    10481058    $verifsolr = explode(',',$values);
     
    10641074
    10651075    return $solrsql;
     1076}
     1077
     1078
     1079/**
     1080 * parses the affiliation facet
     1081 *
     1082 * @return array
     1083 */
     1084function wphal_parse_affiliation_facet($facet_fields, $structIDs)
     1085{
     1086    $result=[];
     1087    foreach($structIDs as $k => $structID){
     1088        if(isset($facet_fields->{'affiliated_'.$k}) && !empty($facet_fields->{'affiliated_'.$k})){
     1089            foreach($facet_fields->{'affiliated_'.$k} as $r){
     1090                $t = explode(wphal_delimiter_join, $r[0]);
     1091                if (isset($result[$t[1]])){
     1092                    $result[$t[1]] = $r[1];
     1093                }else {
     1094                    $result[$t[1]] += $r[1];
     1095                }
     1096            }
     1097        }
     1098    }
     1099    return $result;
    10661100}
    10671101
Note: See TracChangeset for help on using the changeset viewer.