From 84844046f1dcc1b85ccce8a5777fe5c66284f647 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 27 Oct 2021 08:26:19 +0000 Subject: [PATCH] Add limit to number of locations to be stored. #632 --- src/Controller/APIController.php | 7 ++++++- src/Entity/CustomerMetadata.php | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 37388f8b..09e58a5f 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3650,8 +3650,13 @@ class APIController extends Controller implements LoggedController } else { - // TODO: limit locations to 6. If more than 6, pop the first one out + // limit locations to 6. If more than 6, pop the first one out // add location to existing customer meta + $meta_count = count($c_meta->getAllMetaInfo()); + + if ($meta_count >= 6) + $c_meta->popMetaInfo(); + $c_meta->addMetaInfo($name, $loc_info); } diff --git a/src/Entity/CustomerMetadata.php b/src/Entity/CustomerMetadata.php index c3fe1509..5ef9d518 100644 --- a/src/Entity/CustomerMetadata.php +++ b/src/Entity/CustomerMetadata.php @@ -76,4 +76,12 @@ class CustomerMetadata { return $this->meta_info; } + + public function popMetaInfo() + { + if (count($this->meta_info) > 0) + { + array_shift($this->meta_info); + } + } }