-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/gat 5343 5 - Create SQL linkage from Dataset Version to Tools, Publications and other Dataset Versions #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thomgiles
wants to merge
28
commits into
dev
Choose a base branch
from
Feature/GAT-5343-5/Edit-Dataset-Creates-Linkages
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6a12767
Feature commit
thomgiles 25cc80a
Merge branch 'dev' of https://github.com/HDRUK/gateway-api-2 into dev
thomgiles 9558c62
tiltfile
thomgiles 7e22964
Whitespace
thomgiles 5016b82
Moved to GetValueByPossibleKeys
thomgiles 94218ad
Update to GetValueByPossibleKeys
thomgiles 0e9306d
Merge branch 'dev' into Feature/GAT-5343-5/Edit-Dataset-Creates-Linkages
thomgiles f4ef531
Moved to a modular function approach
thomgiles e721218
removed dd() in test
thomgiles 6a5571d
Added commenting
thomgiles bcfe82a
Tidy commenting
thomgiles 3bec236
Moved trait call to MetadataOnboard.php
thomgiles 3243de1
Reverted
thomgiles 31662b6
removed modifcation to gdwm_v1p1
thomgiles 3e4a65a
reverted headers
thomgiles c18dd0e
Defined $textMatches explicitly to keep phpstan happy
thomgiles d66d8bf
Removed Pluck
thomgiles 112ad46
Moved Dataset Fetch to only get active datasets
thomgiles bc35094
further prevention of self loops (including test)
thomgiles f0d2c8e
Subsumed DatasetVersionHasSpatialCoverage
thomgiles 650a1f9
Moved to Job with Queue
thomgiles 3b12f1b
Fix for isset()
thomgiles 1933953
Removed Logging
thomgiles c08f6e0
Returned Trait for ref
thomgiles fc5fc4f
Update to dataset logic to remove redundant code
thomgiles 75e89b8
Fixed createSqlLinkageFromDataset() function
thomgiles 5a10aaa
Removed caching
thomgiles 8bb62c0
Fix
thomgiles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,26 +8,117 @@ | |
| trait GetValueByPossibleKeys | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these are part of a library not a trait.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| /** | ||
| * Search for a value in an array by trying multiple possible keys in order. | ||
| * Search for a value in an array by trying multiple possible keys or paths in order. | ||
| * | ||
| * Note 15th Oct 2024 - Tom Giles - I have now enhanced this function for full searching: | ||
| * The function now supports both simple keys and dot notation paths. for example ['tools'] | ||
| * or ['linkages.tools'] or even ['metadata.linkages.tools'] will now return the ['tools'] | ||
| * object. Previously the full path in the array was requried. I have done this because | ||
| * widening the potential search parathenisis provides more flexible in terms maintaining | ||
| * functionality across data model changes. | ||
| * | ||
| * @param array $array The array to search. | ||
| * @param array $keys The list of possible keys to try, in order. | ||
| * @param array $keys The list of possible keys or paths to try, in order. | ||
| * @param mixed $default The default value to return if none of the keys are found. | ||
| * @return mixed The value of the first key found, or the default value if none are found. | ||
| */ | ||
| public function getValueByPossibleKeys(array $array, array $keys, $default = null) | ||
| { | ||
| foreach ($keys as $key) { | ||
| $value = Arr::get($array, $key, null); | ||
| if (!is_null($value)) { | ||
| return $value; | ||
| if (strpos($key, '.') !== false) { | ||
| // Treat key as a dot notation path | ||
| $value = $this->findByPath($array, $key); | ||
| if (!is_null($value)) { | ||
| return $value; | ||
| } | ||
| } else { | ||
| // Treat key as a simple key and search recursively | ||
| $value = $this->recursiveSearch($array, $key); | ||
| if (!is_null($value)) { | ||
| return $value; | ||
| } | ||
| } | ||
| } | ||
| // Removing, as it doesn't really serve a purpose dumping this to stdout. | ||
| // Suggest, if we care about it, then we audit it instead. | ||
|
|
||
| // Optionally log if no keys are found | ||
| // Log::info('No value found for any of the specified keys', [ | ||
| // 'keys' => $keys, | ||
| // ]); | ||
|
|
||
| return $default; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Recursively search for a key in a multi-dimensional array. | ||
| * | ||
| * @param array $array The array to search. | ||
| * @param string $key The key to search for. | ||
| * @return mixed|null The value if found, or null otherwise. | ||
| */ | ||
| protected function recursiveSearch(array $array, string $key) | ||
| { | ||
| foreach ($array as $k => $v) { | ||
| if ($k === $key) { | ||
| return $v; | ||
| } | ||
|
|
||
| if (is_array($v)) { | ||
| $result = $this->recursiveSearch($v, $key); | ||
| if (!is_null($result)) { | ||
| return $result; | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Find a value in a multi-dimensional array based on a dot notation path. | ||
| * This function searches through all possible branches to find the path. | ||
| * | ||
| * @param array $array The array to search. | ||
| * @param string $path The dot notation path to search for. | ||
| * @return mixed|null The value if found, or null otherwise. | ||
| */ | ||
| protected function findByPath(array $array, string $path) | ||
| { | ||
| $segments = explode('.', $path); | ||
|
|
||
| return $this->recursivePathSearch($array, $segments); | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to perform recursive path search. | ||
| * | ||
| * @param array $array The current array segment. | ||
| * @param array $segments The remaining path segments to search. | ||
| * @return mixed|null The value if found, or null otherwise. | ||
| */ | ||
| protected function recursivePathSearch(array $array, array $segments) | ||
| { | ||
| $currentSegment = array_shift($segments); | ||
|
|
||
| if (array_key_exists($currentSegment, $array)) { | ||
| $value = $array[$currentSegment]; | ||
| if (empty($segments)) { | ||
| return $value; | ||
| } | ||
|
|
||
| if (is_array($value)) { | ||
| return $this->recursivePathSearch($value, $segments); | ||
| } | ||
| } | ||
|
|
||
| // If the current segment is not found, search deeper in the array | ||
| foreach ($array as $key => $subArray) { | ||
| if (is_array($subArray)) { | ||
| $result = $this->recursivePathSearch($subArray, array_merge([$currentSegment], $segments)); | ||
| if (!is_null($result)) { | ||
| return $result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the attached tickets it is about creating a script.