Skip to content

Commit

Permalink
Merge pull request #264 from art-institute-of-chicago/fix/map-annotat…
Browse files Browse the repository at this point in the history
…ion-nids

Make map_annotation nids cantor paired ints [MA-156]
  • Loading branch information
nikhiltri authored Mar 1, 2024
2 parents aa7cb02 + 104f47a commit 765b317
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/Models/Transformers/AnnotationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

use A17\Twill\Models\Contracts\TwillModelContract;
use League\Fractal\TransformerAbstract;
use App\Helpers\Util;

class AnnotationTransformer extends TransformerAbstract
{
public function transform(TwillModelContract $annotation)
{
$type = $annotation->types->first();
$category = $type->category;
$nid = Util::cantorPair($annotation->id, $annotation->annotation_type_id);
return [
"$annotation->id:$annotation->annotation_type_id" => [
$nid => [
'title' => $annotation->title,
'status' => "1", // Legacy from Drupal
'nid' => (string) "$annotation->id:$annotation->annotation_type_id", // Legacy from Drupal
'nid' => $nid, // Legacy from Drupal
'type' => 'map_annotation', // Legacy from Drupal
'translations' => [], // TODO Determine what data the mobile app requires
'location' => "$annotation->latitude,$annotation->longitude",
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/AnnotationSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function test_serialize(): void

$this->assertArrayHasKey('map_annontations', $serialized, 'The key is intentionally misspelled for backwards compatibility');
foreach ($serialized['map_annontations'] as $id => $annotation) {
$this->assertStringContainsString(':', $id);
$this->assertArrayHasKey('title', $annotation);
$this->assertArrayHasKey('status', $annotation);
$this->assertArrayHasKey('nid', $annotation);
Expand Down

0 comments on commit 765b317

Please sign in to comment.