Skip to content

Commit

Permalink
Revert "try to fix sort bug"
Browse files Browse the repository at this point in the history
This reverts commit c2e97b1.
  • Loading branch information
TamaroWalter committed Jan 18, 2024
1 parent c2e97b1 commit 544db80
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
28 changes: 1 addition & 27 deletions classes/ratings.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ public static function moodleoverflow_get_reputation($moodleoverflowid, $userid
/**
* Sort the answers of a discussion by their marks and votes.
*
* @param array $posts all the posts from a discussion.
* @param object $posts all the posts from a discussion.
*/
public static function moodleoverflow_sort_answers_by_ratings($posts) {

// Create a copy that only has the answer posts and save the parent post.
$answerposts = $posts;
$parentpost = array_shift($answerposts);
Expand Down Expand Up @@ -848,29 +847,4 @@ private static function moodleoverflow_quicksort_post_by_votes(array &$posts, $l
}
}

private static function moodleoverflow_mergesort_post_by_votes(array &$posts, $low, $high): array {
$length = $high - $low;
if ($length <= 1) {
return $posts;
}
$mid = $low + (int) ($length / 2);

self::moodleoverflow_mergesort_post_by_votes($posts, $low, $mid);
self::moodleoverflow_mergesort_post_by_votes($posts, $mid + 1, $high);
return self::moodleoverflow_merge_posts($post, $low, $mid, $mid+1, $high);
}

private static function moodleoverflow_merge_posts(&$posts, $leftlow, $lefthigh, $rightlow, $righthigh) {
while ($leftlow <= $lefthigh && $rightlow <= $righthigh) {
// Sort after votesdifference, then sort after time created.
if ($posts[$leftlow]->votesdifference > $posts[$rightlow]->votesdifference) {
$leftlow++;
} else {
$value = $posts[$rightlow];
$index = $rightlow;

//Shift all the element
}
}
}
}
8 changes: 2 additions & 6 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,8 @@ function moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discuss

// Retrieve all posts of the discussion.
$posts = moodleoverflow_get_all_discussion_posts($discussion->id, $istracked, $modulecontext);
/*$newpost = [];
foreach($posts as $posti) {
$newpost[] = $posti->message;
}
var_dump($newpost);
*/$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);

$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);

// Start with the parent post.
$post = $posts[$post->id];
Expand Down

0 comments on commit 544db80

Please sign in to comment.