Skip to content

Commit

Permalink
fix(*): fix the condition if the data is already present then not pus…
Browse files Browse the repository at this point in the history
…h the data
  • Loading branch information
Ayush8923 committed Aug 25, 2024
1 parent c54dcef commit b1ee19e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions classes/model/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,33 @@ 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
];
}
}
}
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;
}
}
Expand Down

0 comments on commit b1ee19e

Please sign in to comment.