Skip to content

Commit

Permalink
add technology and category as multi items
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Andersson committed Oct 8, 2024
1 parent f16606a commit 7e8c4e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/Transforms/StratsysTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,21 @@ public function transform(array $data): array
// Remove first 10 characters (Which is always "Inga data ")
$performance = trim(substr($row["Effektmal_FargNamn"] ?? "", 10));
$challenges = trim($row["Initiativ_Utmaningar"] ?? "");
$categories = trim($row["Omrade_Namn"] ?? "");
$technologies = trim($row["Transformation_Namn"] ?? "");

if ($key === false) {
$row["Effektmal_FargNamn"] = $this->append([], $performance);
$row["Initiativ_Utmaningar"] = $this->append([], $challenges);
$row["Omrade_Namn"] = $this->append([], $categories);
$row["Transformation_Namn"] = $this->append([], $technologies);
$lookup[] = $row;
} else {
// Append to array
$lookup[$key]["Effektmal_FargNamn"] = $this->append($lookup[$key]["Effektmal_FargNamn"], $performance);
$lookup[$key]["Initiativ_Utmaningar"] = $this->append($lookup[$key]["Initiativ_Utmaningar"], $challenges);
$lookup[$key]["Omrade_Namn"] = $this->append($lookup[$key]["Omrade_Namn"], $categories);
$lookup[$key]["Transformation_Namn"] = $this->append($lookup[$key]["Transformation_Namn"], $technologies);
}
});
// Expand merged strings
Expand All @@ -139,11 +145,18 @@ public function transform(array $data): array
->alternateName($row["Initiativ_Kontaktperson"] ?? "");
$project->employee($contact);

$categories = array_map(function ($category) {
return Schema::propertyValue()->name('category')->value($category);
}, $row["Omrade_Namn"]);
$technologies = array_map(function ($technology) {
return Schema::propertyValue()->name('technology')->value($technology);
}, $row["Transformation_Namn"]);

$project->setProperty('@meta', [
Schema::propertyValue()->name('technology')->value($row["Transformation_Namn"] ?? ""),
...$categories,
...$technologies,
Schema::propertyValue()->name('status')->value($row["Initiativ_Status"] ?? "N/A"),
Schema::propertyValue()->name('progress')->value($this->getProgress($row["Initiativ_Status"] ?? "0")), // phpcs:ignore
Schema::propertyValue()->name('category')->value($row["Omrade_Namn"] ?? ""),
]);
$project->setProperty('@version', md5(json_encode($project->toArray())));
$output[] = $project->toArray();
Expand Down
12 changes: 6 additions & 6 deletions tests/Transforms/StratsysTransformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function testStratsysTransform(): void
"alternateName" => "Initiativ_Kontaktperson"
],
"@meta" => [
[
"@type" => "PropertyValue",
"name" => "category",
"value" => "Omrade_Namn"
],
[
"@type" => "PropertyValue",
"name" => "technology",
Expand All @@ -121,14 +126,9 @@ public function testStratsysTransform(): void
"@type" => "PropertyValue",
"name" => "progress",
"value" => 0
],
[
"@type" => "PropertyValue",
"name" => "category",
"value" => "Omrade_Namn"
]
],
"@version" => "c6ae4e6b3fe52e84fdace1b520066c8b"
"@version" => "48a485116d4c77d547cad1da7bf28f45"
]
], $this->model->transform($this->data));
}
Expand Down

0 comments on commit 7e8c4e2

Please sign in to comment.