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 fdf82e2 commit f832cfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions api/ui/Rearranger.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function searchInside ($subarray, $goal) {
return false;
}
public function swap($array, $goal, $goalkey, $direction) {
echo "swap received '" . $direction . "' and this array: \n";
print_r($array, false);
//echo "swap received '" . $direction . "' and this array: \n";
//print_r($array, false);
$temp = '';
$tempkey = 0;
$counter = 0;
Expand All @@ -86,8 +86,8 @@ public function swap($array, $goal, $goalkey, $direction) {
$temp = '';
foreach ($array as $key => $element) {
if ($temp != '') { // previous element in temp2 is the goal, $element is the one to be swapped
echo "Array before swap: \n";
print_r($array, false);
//echo "Array before swap: \n";
//print_r($array, false);
$array[$goalkey] = $element;
$array[$key] = $temp;
echo "Array after swap: \n";
Expand All @@ -96,7 +96,7 @@ public function swap($array, $goal, $goalkey, $direction) {
}
// if element is at last position, $temp will be set but nothing is swapped, foreach is over
else if ($key == $goalkey) {
echo "Found array containing the value at key: " . $key . "\n";
//echo "Found array containing the value at key: " . $key . "\n";
$temp = $element;
}
}
Expand Down
2 changes: 2 additions & 0 deletions api/ui/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ 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 f832cfb

Please sign in to comment.