Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USAGOV-2103: Add fed agency letter pages to the Pub Pages Report #2154

Merged
merged 13 commits into from
Jan 13, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,41 @@ protected function saveNodeRows($out): void {
->execute();

foreach ($nids as $nid) {

// Get DataLayer information on this node
$node = $this->entityTypeManager->getStorage('node')->load($nid);
$row = $this->getNodeRow($node)->toArray();

$row = array_map(fn($col) => trim($col), $row);
fputcsv($out, $row);

$origLanguage = $node->language();
if ($languages = $node->getTranslationLanguages()) {
foreach ($languages as $lang) {
if ($lang->getId() !== $origLanguage->getId()) {
// export translated node
$trNode = $node->getTranslation($lang->getId());
$trRow = $this->getNodeRow($trNode);
$fields = array_map(fn($field) => trim($field), $trRow->toArray());
fputcsv($out, $fields);
}
// Save this row into the spreadsheet
$this->saveNodeRow($out, $node, $row);

// If this is a Directory-Index, add in all letter pages (USAGOV-2103)
if ($row[1] == 'federal_directory_index') {
$baseUrl = $row[2];
$fullBaseUrl = $row[5];
for ($lett = ord('a'); $lett <= ord('z'); $lett++) {
DaleMHFrey marked this conversation as resolved.
Show resolved Hide resolved
$row[2] = $baseUrl . '/' . chr($lett);
$row[5] = $fullBaseUrl . '/' . chr($lett);
$this->saveNodeRow($out, $node, $row);
}
}
}
}

protected function saveNodeRow($out, $node, $row): void {

$row = array_map(fn($col) => trim($col), $row);
fputcsv($out, $row);

$origLanguage = $node->language();
if ($languages = $node->getTranslationLanguages()) {
foreach ($languages as $lang) {
if ($lang->getId() !== $origLanguage->getId()) {
// export translated node
$trNode = $node->getTranslation($lang->getId());
$trRow = $this->getNodeRow($trNode);
$fields = array_map(fn($field) => trim($field), $trRow->toArray());
fputcsv($out, $fields);
}
}
}
Expand Down
Loading