From df9073685ac0ebeef2bf784033599fda2527520d Mon Sep 17 00:00:00 2001 From: Muhammad Aji Muharrom Date: Fri, 9 Aug 2019 15:18:18 +0700 Subject: [PATCH 1/2] Menambahkan kode untuk menghandle akun dengan > 1 role --- SSO/SSO.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/SSO/SSO.php b/SSO/SSO.php index b8d119f..826cc63 100644 --- a/SSO/SSO.php +++ b/SSO/SSO.php @@ -127,10 +127,22 @@ public static function getUser() { $user->npm = $details['npm']; $user->org_code = $details['kd_org']; - $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code]; - $user->faculty = $data['faculty']; - $user->study_program = $data['study_program']; - $user->educational_program = $data['educational_program']; + if( !is_array($user->org_code) ) { + $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code]; + $user->faculty = $data['faculty']; + $user->study_program = $data['study_program']; + $user->educational_program = $data['educational_program']; + } else { + $user->faculty = array(); + $user->study_program = array(); + $user->educational_program = array(); + foreach( $user->org_code as $org_code ) { + $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$org_code]; + array_push($user->faculty, $data['faculty']); + array_push($user->study_program, $data['study_program']); + array_push($user->educational_program, $data['educational_program']); + } + } } else if ($user->role === 'staff') { $user->nip = $details['nip']; @@ -166,4 +178,4 @@ private static function init() { phpCAS::setNoCasServerValidation(); } -} \ No newline at end of file +} From 13667ee54ab4419573fc5cec7bb28bfa92cdefbb Mon Sep 17 00:00:00 2001 From: Muhammad Aji Muharrom Date: Mon, 6 Jul 2020 22:40:35 +0700 Subject: [PATCH 2/2] Give additional properties to user object When more than 1 `kd_org` is present for a single user, additional faculty, study_program, and educational_program are stored in properties named after their plural forms, as arrays. This is done to ensure type consistency of existing properties. --- SSO/SSO.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/SSO/SSO.php b/SSO/SSO.php index 826cc63..208f51c 100644 --- a/SSO/SSO.php +++ b/SSO/SSO.php @@ -126,21 +126,26 @@ public static function getUser() { if ($user->role === 'mahasiswa') { $user->npm = $details['npm']; $user->org_code = $details['kd_org']; - + if( !is_array($user->org_code) ) { $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code]; $user->faculty = $data['faculty']; $user->study_program = $data['study_program']; $user->educational_program = $data['educational_program']; } else { - $user->faculty = array(); - $user->study_program = array(); - $user->educational_program = array(); + $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code[0]]; + $user->faculty = $data['faculty']; + $user->study_program = $data['study_program']; + $user->educational_program = $data['educational_program']; + + $user->faculties = array(); + $user->study_programs = array(); + $user->educational_programs = array(); foreach( $user->org_code as $org_code ) { $data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$org_code]; - array_push($user->faculty, $data['faculty']); - array_push($user->study_program, $data['study_program']); - array_push($user->educational_program, $data['educational_program']); + array_push($user->faculties, $data['faculty']); + array_push($user->study_programs, $data['study_program']); + array_push($user->educational_programs, $data['educational_program']); } } }