Skip to content

Commit

Permalink
No manual sort for portfolios
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharles committed Apr 6, 2023
1 parent 0affd0f commit 8353e5d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
25 changes: 12 additions & 13 deletions public/api/createPortfolioActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,18 @@
// $learningOutcomes = '';
$isPublic = '0';

$sql = "SELECT sortOrder
FROM `course_content`
WHERE courseId = '$portfolioCourseId'
AND sortOrder >= (Select sortOrder From `course_content` WHERE doenetId='$previousContainingDoenetId' AND isDeleted = 0)
AND isDeleted = 0
ORDER BY sortOrder
LIMIT 2";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$prev = $row['sortOrder'] ?: '';
$row = $result->fetch_assoc();
$next = $row['sortOrder'] ?: '';
$sortOrder = SortOrder\getSortOrder($prev, $next);

// $sql = "SELECT sortOrder
// FROM `course_content`
// WHERE courseId = '$portfolioCourseId'
// AND isDeleted = 0
// AND isPublic = 0
// ORDER BY sortOrder DESC
// LIMIT 1";
// $result = $conn->query($sql);
// $row = $result->fetch_assoc();
// $prev = $row['sortOrder'] ?: 'a';
$sortOrder = 'n'; //We are sorting by date created and not using manual sorting

$sql = "
INSERT INTO course_content
Expand Down
37 changes: 37 additions & 0 deletions public/api/lexicographicalRankingSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,42 @@ function getSortOrder($prev, $next)

return $newOrder;
}

function lettersToANumber($sequence){
$valueOfA = 97;
$num = 0;
for ($i = 0; $i < strlen($sequence); $i++){
$letter = substr($sequence, strlen($sequence) - $i - 1, 1);
$letterNum = ord($letter) - $valueOfA + 1;
$positionmultiplier = pow(26, $i);
$valueOfLetterAtThePossition = $letterNum * $positionmultiplier;
$num = $num + $valueOfLetterAtThePossition;
}
return $num;
}

function numberToLetters($num,$numOfLetters){
$valueOfA = 97;
$letters = "";
$remainingNum = $num;
for ($i = $numOfLetters; $i >= 0; $i--){
$divisor = pow(26, $i);
$quotient = (int) ($remainingNum / $divisor);
if ($quotient > 0){
$char = chr($quotient + $valueOfA - 1);
$letters = $letters . $char;
$remainingNum = $remainingNum - $quotient * $divisor;
}
}
return $letters;
}

//This is incomplete!
//After 'aay' it goes to 'ab'
function getNextSortOrder($str){
$str_as_num = lettersToANumber($str);
return numberToLetters($str_as_num + 1,strlen($str));
}

}
?>

0 comments on commit 8353e5d

Please sign in to comment.