From b1ee19e3e3af2e1c20cfe85ea32e996328e8d072 Mon Sep 17 00:00:00 2001 From: Ayush8923 Date: Mon, 26 Aug 2024 01:13:09 +0530 Subject: [PATCH] fix(*): fix the condition if the data is already present then not push the data --- classes/model/survey.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/classes/model/survey.php b/classes/model/survey.php index 2f381749fc4..f1edb733015 100644 --- a/classes/model/survey.php +++ b/classes/model/survey.php @@ -284,14 +284,16 @@ public static function get_survey_data($surveyId) { $newcategoryslug = $questioncategory->slug; $newcategorylabel = $questioncategory->label; - if (!self::interpretation_exists($response['surveyData']['interpretations'], $newcategoryslug, $newcategorylabel)) { + $newinterpretation = [ + "catgororySlug" => $newcategoryslug, + "text" => '', + "range" => '', + "description" => '', + ]; + + if (!self::interpretation_exists($response['surveyData']['interpretations'], $newcategoryslug, $newinterpretation)) { $response['surveyData']['interpretations'][] = [ - $newcategorylabel => [ - "catgororySlug" => $newcategoryslug, - "text" => '', - "range" => '', - "description" => '', - ] + $newcategorylabel => $newinterpretation ]; } } @@ -299,11 +301,16 @@ public static function get_survey_data($surveyId) { return $response; } - public static function interpretation_exists($surveydatainterpretations, $categoryslug, $categorylabel) { + public static function interpretation_exists($surveydatainterpretations, $categoryslug, $newinterpretation) { foreach ($surveydatainterpretations as $item) { - if (isset($item[$categorylabel])) { - $existingitem = $item[$categorylabel]; - if ($existingitem['catgororySlug'] === $categoryslug) { + if (isset($item[$categoryslug])) { + $existingitem = $item[$categoryslug]; + if ( + $existingitem['catgororySlug'] === $newinterpretation['catgororySlug'] && + $existingitem['text'] === $newinterpretation['text'] && + $existingitem['range'] === $newinterpretation['range'] && + $existingitem['description'] === $newinterpretation['description'] + ) { return true; } }