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

Make map_annotation nids cantor paired ints [MA-156] #264

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading