Skip to content

Conversation

berthob98
Copy link
Contributor

This PR adjusts the sorting of the videos table in the block overview page.
The current behaviour is, that the videos table is always sorted by the start_date, if a second column is picked in the UI the videos table gets multi sorted by the start_date and the picked column.
This PR changes the behaviour to fully sort the table by the newly picked column instead of multisorting.

If there won't be another Moodle 4.5 Release, I can rebase this PR for Moodle 5.0.

@bluetom
Copy link
Member

bluetom commented Jul 26, 2025

Hello Berthold,
can I merge this PR for the upcoming new 4.5 version?

@bluetom bluetom requested a review from ferishili July 31, 2025 11:56
Copy link
Contributor

@ferishili ferishili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @berthob98,
I’ve left some comments. I also want to point out that suddenly removing or replacing the sorting is not an ideal solution.
The proper and sufficient fix is to only set: $table->maxsortkeys = 1;
This ensures only one sorting key is applied, which resolves the issue without introducing unnecessary complexity or sudden change of behavior.

$table->no_sorting('visibility'); // This column cannot be sortable because it does not mean anything to Opencast!
$table->no_sorting('select');
$table->sortable(true, 'start_date', SORT_DESC);
$table->text_sorting('title');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we initiating the sort with title instead of start_date?

$table->no_sorting('select');
$table->sortable(true, 'start_date', SORT_DESC);
$table->text_sorting('title');
$table->sortable(true, null, SORT_DESC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to restore start_date as the initial sorting column. Without it, the table does not follow the expected initial sort order.

$sortcolumns = $table->get_sort_columns();

// If we don't have a sortcolumn we sort by date desc.
if (empty($sortcolumns)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is not ideal. We are requesting the video list from Opencast sorted by start date, but the Moodle table is not being sorted accordingly. This logic should be removed to avoid inconsistent behavior.
Additionally, instead of using the hardcoded value 3, please use the SORT_DESC constant for better readability and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants