Changeset 2879098
- Timestamp:
- 03/13/2023 12:18:08 PM (3 years ago)
- Location:
- hal/trunk
- Files:
-
- 2 edited
-
constantes.php (modified) (1 diff)
-
wp-hal.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hal/trunk/constantes.php
r2879002 r2879098 7 7 // Constante pour gérer certaines facettes 8 8 define('wphal_delimiter', '_FacetSep_'); 9 define('wphal_delimiter_join', '_JoinSep_'); 9 10 10 11 // Constante pour l'API -
hal/trunk/wp-hal.php
r2879002 r2879098 186 186 $id = wphal_verifSolr($id); 187 187 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); 189 195 $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.mincount=1&facet=true':''; 190 196 … … 470 476 <div class="display" id="wphal-affiliated" style="display: none;"> 471 477 <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)) { 473 480 $content .= '<span id="triauteurs">'; 474 481 $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>'; … … 478 485 $content .= '<div id="wphal-aff">'; 479 486 $r = 0; 480 foreach ($ json->facet_counts->facet_fields->affiliated as $res) {487 foreach ($parsed_facetfield as $author=>$count) { 481 488 $r = $r + 1; 482 489 if ($r > 10) { 483 490 break; 484 491 } 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]."\""); 488 495 }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>'; 492 499 } 493 500 $i = 1; 494 501 $content .= '<div id="affiliateduite" style="display:none;">'; 495 foreach ($ json->facet_counts->facet_fields->affiliated as $res) {502 foreach ($parsed_facetfield as $author=>$count) { 496 503 if ($r < 10) { 497 504 break; … … 500 507 $i = $i + 1; 501 508 } 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]."\""); 505 512 }else{ 506 $q = "authIdPerson_i:$name[ 2]";513 $q = "authIdPerson_i:$name[1]"; 507 514 } 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>'; 509 516 } 510 517 } … … 1001 1008 * 1002 1009 * @param array $option_choix 1003 * @param int $structID to buid prefixed facet1010 * @param array $structIDs to build prefixed facet 1004 1011 * @return array 1005 1012 */ 1006 function wphal_buildfacet($option_choix, $structID =0)1013 function wphal_buildfacet($option_choix, $structIDs) 1007 1014 { 1008 1015 $facetQuery = []; … … 1038 1045 if ($option == 'affiliated') { 1039 1046 $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 } 1042 1051 } 1043 1052 } … … 1045 1054 return $facetQuery; 1046 1055 } 1056 1047 1057 function wphal_verifSolr($values){ 1048 1058 $verifsolr = explode(',',$values); … … 1064 1074 1065 1075 return $solrsql; 1076 } 1077 1078 1079 /** 1080 * parses the affiliation facet 1081 * 1082 * @return array 1083 */ 1084 function 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; 1066 1100 } 1067 1101
Note: See TracChangeset
for help on using the changeset viewer.