From 074f988f0f8e7601e6543f789efa1fcfc1c457b4 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 1 Dec 2025 18:12:24 +0530 Subject: [PATCH] GWM : relationship array handled --- app/Controllers/EmployeeRestController.php | 109 ++++++++++++--------- 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index eb9b98d..1a816ea 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1361,41 +1361,47 @@ class EmployeeRestController extends AdminController array_push($data,$temp2); - array_push($array->to_be_added_relationship,$temp2['data']['relationship']); - $array->to_be_added_relationship = array_unique($array->to_be_added_relationship); + array_push($array->to_be_added_relationship,['relationship'=>$temp2['data']['relationship'],'age_validation'=>$temp2['data']['age_validation']]); + $array->to_be_added_relationship = array_values( + array_map('unserialize', + array_unique( + array_map('serialize', $array->to_be_added_relationship) + ) + ) + ); } } $array->relationship = []; - foreach ($array->to_be_added_relationship as $value) { - if($value == 'Spouse'){ - array_push($array->relationship,'Spouse'); - }else if($value == 'Child'){ - array_push($array->relationship, 'Son'); - array_push($array->relationship, 'Daughter'); - }else if($value == 'Parent'){ + foreach ($array->to_be_added_relationship as $key => $value) { + if($value['relationship'] == 'Spouse'){ + array_push($array->relationship,['relationship'=>'Spouse','age_validation'=>$value['age_validation']]); + }else if($value['relationship'] == 'Child'){ + array_push($array->relationship, ['relationship'=>'Son','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Daughter','age_validation'=>$value['age_validation']]); + }else if($value['relationship'] == 'Parent'){ $Father = array_search('Father',$array->existing_relationship); $Mother = array_search('Mother',$array->existing_relationship); if ($Father === false && $Mother === false) { - array_push($array->relationship, 'Father'); - array_push($array->relationship, 'Mother'); + array_push($array->relationship, ['relationship'=>'Father','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Mother','age_validation'=>$value['age_validation']]); }else if ($Father !== false && $Mother === false) { - array_push($array->relationship, 'Mother'); + array_push($array->relationship, ['relationship'=>'Mother','age_validation'=>$value['age_validation']]); } else if ($Mother !== false && $Father === false) { - array_push($array->relationship, 'Father'); + array_push($array->relationship, ['relationship'=>'Father','age_validation'=>$value['age_validation']]); } - }else if($value == 'Parent in law'){ + }else if($value['relationship'] == 'Parent in law'){ $FatherinLaw = array_search('Father in Law',$array->existing_relationship); $MotherinLaw = array_search('Mother in Law',$array->existing_relationship); if ($FatherinLaw === false && $MotherinLaw === false) { - array_push($array->relationship, 'Father in Law'); - array_push($array->relationship, 'Mother in Law'); + array_push($array->relationship, ['relationship'=>'Father in Law','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Mother in Law','age_validation'=>$value['age_validation']]); }else if ($FatherinLaw !== false && $MotherinLaw === false) { - array_push($array->relationship, 'Mother in Law'); + array_push($array->relationship, ['relationship'=>'Mother in Law','age_validation'=>$value['age_validation']]); } else if ($MotherinLaw !== false && $FatherinLaw === false) { - array_push($array->relationship, 'Father in Law'); + array_push($array->relationship, ['relationship'=>'Father in Law','age_validation'=>$value['age_validation']]); } } } @@ -1614,41 +1620,48 @@ class EmployeeRestController extends AdminController $temp2['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); array_push($data,$temp2); - array_push($array->to_be_added_relationship,$temp2['data']['relationship']); - $array->to_be_added_relationship = array_unique($array->to_be_added_relationship); + + array_push($array->to_be_added_relationship,['relationship'=>$temp2['data']['relationship'],'age_validation'=>$temp2['data']['age_validation']]); + $array->to_be_added_relationship = array_values( + array_map('unserialize', + array_unique( + array_map('serialize', $array->to_be_added_relationship) + ) + ) + ); } } $array->relationship = []; - foreach ($array->to_be_added_relationship as $value) { - if($value == 'Spouse'){ - array_push($array->relationship,'Spouse'); - }else if($value == 'Child'){ - array_push($array->relationship, 'Son'); - array_push($array->relationship, 'Daughter'); - }else if($value == 'Parent'){ - $Father = array_search('Father',$array->existing_relationship); - $Mother = array_search('Mother',$array->existing_relationship); - if ($Father === false && $Mother === false) { - array_push($array->relationship, 'Father'); - array_push($array->relationship, 'Mother'); - }else if ($Father !== false && $Mother === false) { - array_push($array->relationship, 'Mother'); - } else if ($Mother !== false && $Father === false) { - array_push($array->relationship, 'Father'); - } - }else if($value == 'Parent in law'){ - $FatherinLaw = array_search('Father in Law',$array->existing_relationship); - $MotherinLaw = array_search('Mother in Law',$array->existing_relationship); - if ($FatherinLaw === false && $MotherinLaw === false) { - array_push($array->relationship, 'Father in Law'); - array_push($array->relationship, 'Mother in Law'); - }else if ($FatherinLaw !== false && $MotherinLaw === false) { - array_push($array->relationship, 'Mother in Law'); - } else if ($MotherinLaw !== false && $FatherinLaw === false) { - array_push($array->relationship, 'Father in Law'); - } + foreach ($array->to_be_added_relationship as $key => $value) { + if($value['relationship'] == 'Spouse'){ + array_push($array->relationship,['relationship'=>'Spouse','age_validation'=>$value['age_validation']]); + }else if($value['relationship'] == 'Child'){ + array_push($array->relationship, ['relationship'=>'Son','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Daughter','age_validation'=>$value['age_validation']]); + }else if($value['relationship'] == 'Parent'){ + $Father = array_search('Father',$array->existing_relationship); + $Mother = array_search('Mother',$array->existing_relationship); + if ($Father === false && $Mother === false) { + array_push($array->relationship, ['relationship'=>'Father','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Mother','age_validation'=>$value['age_validation']]); + }else if ($Father !== false && $Mother === false) { + array_push($array->relationship, ['relationship'=>'Mother','age_validation'=>$value['age_validation']]); + } else if ($Mother !== false && $Father === false) { + array_push($array->relationship, ['relationship'=>'Father','age_validation'=>$value['age_validation']]); + } + }else if($value['relationship'] == 'Parent in law'){ + $FatherinLaw = array_search('Father in Law',$array->existing_relationship); + $MotherinLaw = array_search('Mother in Law',$array->existing_relationship); + if ($FatherinLaw === false && $MotherinLaw === false) { + array_push($array->relationship, ['relationship'=>'Father in Law','age_validation'=>$value['age_validation']]); + array_push($array->relationship, ['relationship'=>'Mother in Law','age_validation'=>$value['age_validation']]); + }else if ($FatherinLaw !== false && $MotherinLaw === false) { + array_push($array->relationship, ['relationship'=>'Mother in Law','age_validation'=>$value['age_validation']]); + } else if ($MotherinLaw !== false && $FatherinLaw === false) { + array_push($array->relationship, ['relationship'=>'Father in Law','age_validation'=>$value['age_validation']]); + } } }