Skip to content

Commit

Permalink
fix: updated nmrium info save routine
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Nov 13, 2023
1 parent e854cbb commit 5f22551
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,45 +209,50 @@ public function nmriumInfo(Request $request, Study $study)
$_nmriumJSON = $nmriumInfo;
foreach ($study->datasets as $dataset) {
$fsObject = $dataset->fsObject;
$level = -($fsObject->level + 1);
// echo $fsObject->path;
$path = implode('/', array_slice(explode('/', $fsObject->path), $level));

$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;

$pathsMatch = false;
foreach ($nmriumInfo['data']['spectra'] as $spectra) {
unset($_nmriumJSON['data']['spectra']);
$files = $spectra['sourceSelector']['files'];
$pathsMatch = true;
if ($files) {
foreach ($files as $file) {
if (! str_contains($file, $path)) {
$pathsMatch = false;
if (str_contains($file, $path)) {
$pathsMatch = true;
}
}
}
if ($pathsMatch) {
$_nmriumJSON['data']['spectra'] = [$spectra];
$_nmrium = $dataset->nmrium;
if ($_nmrium) {
$_nmrium->nmrium_info = $_nmriumJSON;
$dataset->has_nmrium = true;
$_nmrium->save();
} else {
$_nmrium = NMRium::create([
'nmrium_info' => json_encode($_nmriumJSON),
]);
$dataset->nmrium()->save($_nmrium);
$dataset->has_nmrium = true;
}
$experimentDetailsExists = array_key_exists('experiment', $spectra['info']);
if ($experimentDetailsExists) {
$experiment = $spectra['info']['experiment'];
$nucleus = $spectra['info']['nucleus'];
if (is_array($nucleus)) {
$nucleus = implode('-', $nucleus);
}
$dataset->type = $experiment.','.$nucleus;
break;
}
}
if ($pathsMatch){
$_nmriumJSON['data']['spectra'] = [$spectra];
$_nmrium = $dataset->nmrium;
if ($_nmrium) {
$_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE);
$dataset->has_nmrium = true;
$_nmrium->save();
} else {
$_nmrium = NMRium::create([
'nmrium_info' => json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE),
]);
$dataset->nmrium()->save($_nmrium);
$dataset->has_nmrium = true;
}
$experimentDetailsExists = array_key_exists('experiment', $spectra['info']);
if ($experimentDetailsExists) {
$experiment = $spectra['info']['experiment'];
$nucleus = $spectra['info']['nucleus'];
if (is_array($nucleus)) {
$nucleus = implode('-', $nucleus);
}
$dataset->save();
$dataset->type = $experiment.','.$nucleus;
}
$dataset->save();
}
}

Expand Down

0 comments on commit 5f22551

Please sign in to comment.