public function Record::getBrothersKey in Views OAI-PMH 8
Get all brothers for a key in an array
Parameters
$key:
$array:
$delimiter: e.g. > _delimiter e.g. @
Return value
array
1 call to Record::getBrothersKey()
- Record::removeDuplicates in src/
Plugin/ views/ style/ Record.php - Remove all duplicate rows for array considering array keys and key brothers @todo refactor this function to more elegant and faster
File
- src/
Plugin/ views/ style/ Record.php, line 374
Class
- Record
- Plugin annotation @ViewsStyle( id = "views_oai_pmh_record", title = @Translation("OAI-PMH"), help = @Translation("Displays rows in OAI-PMH records."), display_types = {"oai_pmh"} )
Namespace
Drupal\views_oai_pmh\Plugin\views\styleCode
public function getBrothersKey($key, $array, $delimiter, $key_delimiter) {
$parts = explode($delimiter, $key);
$sub_key = "";
$output = [];
if ($delimiter === ">") {
// datacite
if (count($parts) <= 1) {
return $output;
}
if (count($parts) < 3 || strpos($key, $key_delimiter) !== false) {
return $output;
}
// Compose family key (sub_key)
for ($i = 0; $i < count($parts) - 1; $i++) {
if ($sub_key === "") {
$sub_key = $parts[$i];
}
else {
$sub_key = $sub_key . $delimiter . $parts[$i];
}
}
}
else {
// dcc
// Only one sub_key
$sub_key = $parts[0];
}
foreach ($array as $key => $value) {
if (strpos($key, $sub_key) !== false) {
$output[] = [
$key => $value,
];
}
}
// Remove if has only one value
if (count($output) === 1) {
$output = [];
}
return $output;
}