diff --git a/app/Controllers/Common.php b/app/Controllers/Common.php new file mode 120000 index 000000000000..97709cc62c5f --- /dev/null +++ b/app/Controllers/Common.php @@ -0,0 +1 @@ +D:/Project/laragon/www/ci4/app/Common.php \ No newline at end of file diff --git a/app/Controllers/Language b/app/Controllers/Language new file mode 120000 index 000000000000..1ac35c4de569 --- /dev/null +++ b/app/Controllers/Language @@ -0,0 +1 @@ +D:/Project/laragon/www/ci4/app/Language \ No newline at end of file diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index 7d1098680ffa..938ec6dbc528 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -321,37 +321,36 @@ public static function sortValuesByNatural(array &$array, $sortByIndex = null): } /** - * Duplicate Array Check by Column + * Returns duplicate elements from an array by key(s). * - * @param array|string $column Unique Column - * @param array $data Array Data + * @param array|string $key Key(s) to check + * @param array $array Array Data */ - public static function arrayDuplicatesBy($column, array $data = []): array + public static function duplicatesBy($key, array $array = []): array { - if ($data === []) { + if ($array === []) { return []; } $duplicateData = []; $dataUnique = []; - foreach ($data as $lineIndex => $searchData) { - if (is_array($column)) { - foreach ($column as $rawColumn) { - if (in_array($searchData[$rawColumn], $dataUnique[$rawColumn] ?? [], true)) { + foreach ($array as $lineIndex => $searchData) { + // If the specified column is an array, generate a unique key using implode + // to concatenate values of specified columns and create a unique identifier + $keyColumns = is_array($key) ? implode('-', array_intersect_key($searchData, array_flip($key))) : $searchData[$key]; + + // Check for duplicates based on the generated key + if (isset($dataUnique[$keyColumns])) { + if (is_array($key)) { + foreach ($key as $rawColumn) { $duplicateData[$lineIndex][$rawColumn] = $searchData[$rawColumn]; - } else { - $dataUnique[$rawColumn][] = $searchData[$rawColumn]; } - } - } - - if (is_string($column)) { - if (in_array($searchData[$column], $dataUnique[$column] ?? [], true)) { - $duplicateData[$lineIndex][$column] = $searchData[$column]; } else { - $dataUnique[$column][] = $searchData[$column]; + $duplicateData[$lineIndex][$key] = $searchData[$key]; } + } else { + $dataUnique[$keyColumns] = true; } } diff --git a/system/Helpers/array_helper.php b/system/Helpers/array_helper.php index e676719aa5a5..ece478960fc3 100644 --- a/system/Helpers/array_helper.php +++ b/system/Helpers/array_helper.php @@ -17,16 +17,16 @@ if (! function_exists('array_duplicate_by')) { /** - * Duplicate array check by column. + * Returns duplicate elements from an array by key(s). * - * @param array|string $column Unique Column - * @param array $data Array Data + * @param array|string $key Key(s) to check + * @param array $array Array Data * * @return array */ - function array_duplicate_by($column, array $data = []) + function array_duplicate_by($key, array $array = []) { - return ArrayHelper::arrayDuplicatesBy($column, $data); + return ArrayHelper::duplicatesBy($key, $array); } } diff --git a/tests/system/Helpers/Array/ArrayHelperDuplicateCheckTest.php b/tests/system/Helpers/Array/ArrayHelperDuplicateCheckTest.php index 014f721c3622..7708f86d387a 100644 --- a/tests/system/Helpers/Array/ArrayHelperDuplicateCheckTest.php +++ b/tests/system/Helpers/Array/ArrayHelperDuplicateCheckTest.php @@ -24,24 +24,46 @@ final class ArrayHelperDuplicateCheckTest extends CIUnitTestCase { private array $array = [ [ - 'name' => 'Fred Flinstone', - 'age' => 20, + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', ], [ - 'name' => 'Brad Pierce', - 'age' => 30, + 'provider_name' => 'Rumah Sakit Silorm', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.72', + 'provider_address' => 'wwaasawdasa', ], [ - 'name' => 'Fred Flinstone', - 'age' => 70, + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', ], [ - 'name' => 'Michelle Stone', - 'age' => 30, + 'provider_name' => 'Rumah Sakit Siloum', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.74', + 'provider_address' => 'wwaasawdasa', ], [ - 'name' => 'Michael Bram', - 'age' => 40, + 'provider_name' => 'Rumah Sakit Siloem', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.75', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Silosm', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.76', + 'provider_address' => 'wwaasawdasa', ], ]; @@ -49,20 +71,18 @@ public function testSingleColumn(): void { $this->assertSame([ 2 => [ - 'name' => 'Fred Flinstone', + 'provider_name' => 'Rumah Sakit Siloam', ], - ], ArrayHelper::arrayDuplicatesBy('name', $this->array)); + ], ArrayHelper::duplicatesBy('provider_name', $this->array)); } public function testMultipleColumn(): void { $this->assertSame([ 2 => [ - 'name' => 'Fred Flinstone', - ], - 3 => [ - 'age' => 30, + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_region' => '31.71', ], - ], ArrayHelper::arrayDuplicatesBy(['name', 'age'], $this->array)); + ], ArrayHelper::duplicatesBy(['provider_name', 'provider_region'], $this->array)); } } diff --git a/tests/system/Helpers/ArrayHelperTest.php b/tests/system/Helpers/ArrayHelperTest.php index 31a3b76f4878..dc04f2921981 100644 --- a/tests/system/Helpers/ArrayHelperTest.php +++ b/tests/system/Helpers/ArrayHelperTest.php @@ -1291,73 +1291,119 @@ public static function provideArrayGroupByExcludeEmpty(): iterable /** * @dataProvider provideArrayDuplicate * - * @param mixed $column + * @param array|string $key Key(s) to Check */ - public function testArrayDuplicate($column, array $data, array $expected): void + public function testArrayDuplicate($key, array $data, array $expected): void { - $this->assertSame($expected, array_duplicate_by($column, $data)); + $this->assertSame($expected, array_duplicate_by($key, $data)); } public static function provideArrayDuplicate(): iterable { - yield 'single and multiple' => [ - 'name', // Single - [ - [ - 'name' => 'Fred Flinstone', - 'age' => 20, - ], - [ - 'name' => 'Brad Pierce', - 'age' => 30, - ], - [ - 'name' => 'Fred Flinstone', - 'age' => 70, - ], + yield from [ + 'single' => [ + 'provider_name', // Single [ - 'name' => 'Michelle Stone', - 'age' => 30, + [ + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Silorm', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.72', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloum', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.74', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloem', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.75', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Silosm', + 'provider_email' => 'xxxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.76', + 'provider_address' => 'wwaasawdasa', + ], ], [ - 'name' => 'Michael Bram', - 'age' => 40, - ], - ], - [ - 2 => [ - 'name' => 'Fred Flinstone', + 2 => [ + 'provider_name' => 'Rumah Sakit Siloam', + ], ], ], - ['name', 'age'], // Multiple - [ + 'multiple' => [ + ['provider_name', 'provider_region'], // Multiple [ - 'name' => 'Fred Flinstone', - 'age' => 20, - ], - [ - 'name' => 'Brad Pierce', - 'age' => 30, - ], - [ - 'name' => 'Fred Flinstone', - 'age' => 70, - ], - [ - 'name' => 'Michelle Stone', - 'age' => 30, + [ + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Silorm', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.72', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.71', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloum', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.74', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Siloem', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.75', + 'provider_address' => 'wwaasawdasa', + ], + [ + 'provider_name' => 'Rumah Sakit Silosm', + 'provider_email' => 'xxxx@example.com', + 'provider_website' => 'example.com', + 'provider_region' => '31.76', + 'provider_address' => 'wwaasawdasa', + ], ], [ - 'name' => 'Michael Bram', - 'age' => 40, - ], - ], - [ - 2 => [ - 'name' => 'Fred Flinstone', - ], - 3 => [ - 'age' => 30, + 2 => [ + 'provider_name' => 'Rumah Sakit Siloam', + 'provider_region' => '31.71', + ], ], ], ];