I need to make a list of software developers from the software description pages.
fields:
categories:
label: Catégories de logiciel
type: tags
options:
type: query
fetch: site.logicielsCat.toStructure
text: "{{ item.name }}"
value: "{{ item.slug }}"
editeur:
label: Editeur
type: text
required: true
width: 3/4
poids:
label: Poids
type: text
required: true
width: 1/4
logiciel:
label: Logiciel
type: text
required: true
width: 3/4
description:
label: Description
type: writer
web:
label: Site Web
type: url
width: 3/4
adresse:
label: Adresse
type: text
cp:
label: Code-postal
type: text
width: 1/4
localite:
label: Localité
type: text
width: 1/2
tel:
label: Tél
type: tel
width: 1/4
Obviously, different software may have been developed by the same developer, and I end up with many duplicates when I extract the complete list.
I’d like to be able to deduplicate this software list to obtain a listing of developers keeping the collection as a Kirby object.
So is there a Kirby-specific method that does the same job as array_unique()?
Sorry for my late reply, in the meantime I’ve had to take on another project.
For now I store in an array all needed data from a collection, then I loop through the original array, then I check if the value for the “editeur” key already exists in a temporary associative array. If it doesn’t exist, add it to the result array and mark it as seen in the temporary array.
$softwares = $kirby->collection("logiciels");
$inputArray = [];
foreach ($softwares as $key => $soft) {
$inputArray[] = [
'editeur' => $soft->editeur(),
'cp' => $soft->cp(),
'ville' => $soft->ville(),
'logiciel' => $soft->logiciel(),
'path' => $key,
];
}
// Array to hold unique results
$uniqueArray = [];
$seen = [];
// Loop through the input array
foreach ($inputArray as $item) {
// Get the editeur value using the value() method
$editeurValue = $item['editeur']->value();
// Check if this editeur has already been seen
if (!in_array($editeurValue, $seen)) {
// Add to unique results
$uniqueArray[] = $item;
// Mark this editeur as seen
$seen[] = $editeurValue;
}
}
// Output the unique array
print_r($uniqueArray);
So I was wondering if there wasn’t a more direct way (using a kirby method) of deduplicating a collection on a given field?
It seems the way I wrote the query for collection is wrong, because I got each page in two versions, the first one is the regular page slug and the second is the path starting with the “content” directory.