Skip to content

Commit

Permalink
Expermineting to drag results
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikBuetler committed Jun 24, 2024
1 parent f832cfb commit 8687c73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 9 additions & 6 deletions api/ui/Rearranger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function seekAndSwap($array, $goal, $direction) {
if ($found) {
$temparray = $array;
$tempkey = $goalkey;
echo "Element found inside this array:\n";
print_r($array, false);
//echo "Element found inside this array:\n";
//print_r($array, false);
break;
}
else {
Expand All @@ -42,8 +42,11 @@ public function seekAndSwap($array, $goal, $direction) {
}
}
if(isset($temparray) && isset($tempkey)) {
echo "\nInitiating swap.. Key: " . $goalkey . "\n";
return $this->swap($temparray, $goal, $tempkey, $direction);
echo "\nInitiating swap.. Key: " . $tempkey . "\n";
$temparray = $this->swap($temparray, $goal, $tempkey, $direction);
echo "Returning the array: \n";
print_r($temparray, false);
return $temparray;
}
}
return $array;
Expand Down Expand Up @@ -90,8 +93,8 @@ public function swap($array, $goal, $goalkey, $direction) {
//print_r($array, false);
$array[$goalkey] = $element;
$array[$key] = $temp;
echo "Array after swap: \n";
print_r($array, false);
//echo "Array after swap: \n";
//print_r($array, false);
return $array;
}
// if element is at last position, $temp will be set but nothing is swapped, foreach is over
Expand Down
2 changes: 0 additions & 2 deletions api/ui/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ public function get() {
$arr = $system->getResultsAll();
$id = $this->get['uid'];
$arr = json_decode($arr, true);
print_r($arr, false);
$rearranger = new Rearranger();
$swapped_arr = $rearranger->seekAndSwap($arr, $id, 'down');
print_r($swapped_arr, false);
$system->setResultsAll(json_encode($swapped_arr));
break;
default:
Expand Down

0 comments on commit 8687c73

Please sign in to comment.