Code Duplication    Length = 47-47 lines in 4 locations

app/PrivilegeUtil.php 4 locations

@@ 897-943 (lines=47) @@
894
			$modShareWritePermission['ROLE'] = $roleWritePer;
895
896
			//Retreiving from the grp2role sharing
897
			foreach (static::getDatashare('group2role', $modTabId, $currentUserRoles) as $row) {
898
				$shareGrpId = (int) $row['share_groupid'];
899
				$shareIdGrps = [];
900
				$shareIdGrps[] = $shareGrpId;
901
				if ((int) $row['permission'] === 1) {
902
					if ($modDefOrgShare === 3) {
903
						if (!isset($grpReadPer[$shareGrpId])) {
904
							$usersByGroup = static::getUsersByGroup($shareGrpId, true);
905
							$grpReadPer[$shareGrpId] = $usersByGroup['users'];
906
							foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
907
								if (!isset($grpReadPer[$subgrpid])) {
908
									$grpReadPer[$subgrpid] = $subgrpusers;
909
								}
910
								if (!in_array($subgrpid, $shareIdGrps)) {
911
									$shareIdGrps[] = $subgrpid;
912
								}
913
							}
914
						}
915
					}
916
					if (!isset($grpWritePer[$shareGrpId])) {
917
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
918
						$grpWritePer[$shareGrpId] = $usersByGroup['users'];
919
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
920
							if (!isset($grpWritePer[$subgrpid])) {
921
								$grpWritePer[$subgrpid] = $subgrpusers;
922
							}
923
							if (!in_array($subgrpid, $shareIdGrps)) {
924
								$shareIdGrps[] = $subgrpid;
925
							}
926
						}
927
					}
928
				} elseif ((int) $row['permission'] === 0 && $modDefOrgShare === 3) {
929
					if (!isset($grpReadPer[$shareGrpId])) {
930
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
931
						$grpReadPer[$shareGrpId] = $usersByGroup['users'];
932
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
933
							if (!isset($grpReadPer[$subgrpid])) {
934
								$grpReadPer[$subgrpid] = $subgrpusers;
935
							}
936
							if (!in_array($subgrpid, $shareIdGrps)) {
937
								$shareIdGrps[] = $subgrpid;
938
							}
939
						}
940
					}
941
				}
942
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
943
			}
944
			//Retreiving from the grp2rs sharing
945
			foreach (static::getDatashare('group2rs', $modTabId, $parRoleList) as $row) {
946
				$shareGrpId = (int) $row['share_groupid'];
@@ 945-991 (lines=47) @@
942
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
943
			}
944
			//Retreiving from the grp2rs sharing
945
			foreach (static::getDatashare('group2rs', $modTabId, $parRoleList) as $row) {
946
				$shareGrpId = (int) $row['share_groupid'];
947
				$shareIdGrps = [];
948
				$shareIdGrps[] = $shareGrpId;
949
				if ((int) $row['permission'] === 1) {
950
					if ($modDefOrgShare === 3) {
951
						if (!isset($grpReadPer[$shareGrpId])) {
952
							$usersByGroup = static::getUsersByGroup($shareGrpId, true);
953
							$grpReadPer[$shareGrpId] = $usersByGroup['users'];
954
							foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
955
								if (!isset($grpReadPer[$subgrpid])) {
956
									$grpReadPer[$subgrpid] = $subgrpusers;
957
								}
958
								if (!in_array($subgrpid, $shareIdGrps)) {
959
									$shareIdGrps[] = $subgrpid;
960
								}
961
							}
962
						}
963
					}
964
					if (!isset($grpWritePer[$shareGrpId])) {
965
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
966
						$grpWritePer[$shareGrpId] = $usersByGroup['users'];
967
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
968
							if (!isset($grpWritePer[$subgrpid])) {
969
								$grpWritePer[$subgrpid] = $subgrpusers;
970
							}
971
							if (!in_array($subgrpid, $shareIdGrps)) {
972
								$shareIdGrps[] = $subgrpid;
973
							}
974
						}
975
					}
976
				} elseif ((int) $row['permission'] === 0 && $modDefOrgShare === 3) {
977
					if (!isset($grpReadPer[$shareGrpId])) {
978
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
979
						$grpReadPer[$shareGrpId] = $usersByGroup['users'];
980
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
981
							if (!isset($grpReadPer[$subgrpid])) {
982
								$grpReadPer[$subgrpid] = $subgrpusers;
983
							}
984
							if (!in_array($subgrpid, $shareIdGrps)) {
985
								$shareIdGrps[] = $subgrpid;
986
							}
987
						}
988
					}
989
				}
990
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
991
			}
992
			//Retreiving from the grp2us sharing
993
			foreach (static::getDatashare('group2user', $modTabId, $userid) as $row) {
994
				$shareGrpId = (int) $row['share_groupid'];
@@ 993-1039 (lines=47) @@
990
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
991
			}
992
			//Retreiving from the grp2us sharing
993
			foreach (static::getDatashare('group2user', $modTabId, $userid) as $row) {
994
				$shareGrpId = (int) $row['share_groupid'];
995
				$shareIdGrps = [];
996
				$shareIdGrps[] = $shareGrpId;
997
				if ((int) $row['permission'] === 1) {
998
					if ($modDefOrgShare === 3) {
999
						if (!isset($grpReadPer[$shareGrpId])) {
1000
							$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1001
							$grpReadPer[$shareGrpId] = $usersByGroup['users'];
1002
							foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1003
								if (!isset($grpReadPer[$subgrpid])) {
1004
									$grpReadPer[$subgrpid] = $subgrpusers;
1005
								}
1006
								if (!in_array($subgrpid, $shareIdGrps)) {
1007
									$shareIdGrps[] = $subgrpid;
1008
								}
1009
							}
1010
						}
1011
					}
1012
					if (!isset($grpWritePer[$shareGrpId])) {
1013
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1014
						$grpWritePer[$shareGrpId] = $usersByGroup['users'];
1015
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1016
							if (!isset($grpWritePer[$subgrpid])) {
1017
								$grpWritePer[$subgrpid] = $subgrpusers;
1018
							}
1019
							if (!in_array($subgrpid, $shareIdGrps)) {
1020
								$shareIdGrps[] = $subgrpid;
1021
							}
1022
						}
1023
					}
1024
				} elseif ((int) $row['permission'] === 0 && $modDefOrgShare === 3) {
1025
					if (!isset($grpReadPer[$shareGrpId])) {
1026
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1027
						$grpReadPer[$shareGrpId] = $usersByGroup['users'];
1028
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1029
							if (!isset($grpReadPer[$subgrpid])) {
1030
								$grpReadPer[$subgrpid] = $subgrpusers;
1031
							}
1032
							if (!in_array($subgrpid, $shareIdGrps)) {
1033
								$shareIdGrps[] = $subgrpid;
1034
							}
1035
						}
1036
					}
1037
				}
1038
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
1039
			}
1040
			//Retreiving from the grp2grp sharing
1041
			foreach (static::getDatashare('group2group', $modTabId, $groupList) as $row) {
1042
				$shareGrpId = (int) $row['share_groupid'];
@@ 1041-1087 (lines=47) @@
1038
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
1039
			}
1040
			//Retreiving from the grp2grp sharing
1041
			foreach (static::getDatashare('group2group', $modTabId, $groupList) as $row) {
1042
				$shareGrpId = (int) $row['share_groupid'];
1043
				$shareIdGrps = [];
1044
				$shareIdGrps[] = $shareGrpId;
1045
				if ((int) $row['permission'] === 1) {
1046
					if ($modDefOrgShare === 3) {
1047
						if (!isset($grpReadPer[$shareGrpId])) {
1048
							$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1049
							$grpReadPer[$shareGrpId] = $usersByGroup['users'];
1050
							foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1051
								if (!isset($grpReadPer[$subgrpid])) {
1052
									$grpReadPer[$subgrpid] = $subgrpusers;
1053
								}
1054
								if (!in_array($subgrpid, $shareIdGrps)) {
1055
									$shareIdGrps[] = $subgrpid;
1056
								}
1057
							}
1058
						}
1059
					}
1060
					if (!isset($grpWritePer[$shareGrpId])) {
1061
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1062
						$grpWritePer[$shareGrpId] = $usersByGroup['users'];
1063
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1064
							if (!isset($grpWritePer[$subgrpid])) {
1065
								$grpWritePer[$subgrpid] = $subgrpusers;
1066
							}
1067
							if (!in_array($subgrpid, $shareIdGrps)) {
1068
								$shareIdGrps[] = $subgrpid;
1069
							}
1070
						}
1071
					}
1072
				} elseif ((int) $row['permission'] === 0 && $modDefOrgShare === 3) {
1073
					if (!isset($grpReadPer[$shareGrpId])) {
1074
						$usersByGroup = static::getUsersByGroup($shareGrpId, true);
1075
						$grpReadPer[$shareGrpId] = $usersByGroup['users'];
1076
						foreach ($usersByGroup['subGroups'] as $subgrpid => $subgrpusers) {
1077
							if (!isset($grpReadPer[$subgrpid])) {
1078
								$grpReadPer[$subgrpid] = $subgrpusers;
1079
							}
1080
							if (!in_array($subgrpid, $shareIdGrps)) {
1081
								$shareIdGrps[] = $subgrpid;
1082
							}
1083
						}
1084
					}
1085
				}
1086
				$shareIdMembers[$row['shareid']] = ['GROUP' => $shareIdGrps];
1087
			}
1088
			//Get roles from Us2Us
1089
			foreach (static::getDatashare('user2user', $modTabId, $userid) as $row) {
1090
				$shareUserId = (int) $row['share_userid'];