Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] LifterLMS DataTables support #2008

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,67 @@ protected function configure() {
add_filter( 'llms_get_student_dashboard_tabs', [ $this, 'filter_student_dashboard_tabs' ], 1 );
add_action( 'lifterlms_student_dashboard_index', [ $this, 'add_student_dashboard_my_forms' ] );
add_action( 'lifterlms_settings_save_integrations', [ $this, 'save' ], 30 );

// Early hook inside DataTables layout output to allow for the endpoint to be added to the URL.
add_action( 'gk/gravityview/datatables/get-output-data/before', [ $this, 'datatables_setup_filters' ] );
}

/**
* Add hooks to the DataTables output to fix Lifter dashboard behavior.
*
* @since TODO
*
* @return void
*/
public function datatables_setup_filters() {
add_filter( 'option_permalink_structure', [ $this, 'return_false' ] );

// Append the LifterLMS GravityView endpoint to the directory link.
add_filter( 'gravityview_directory_link', [ $this, 'add_endpoint_to_directory_link' ] );
add_filter( 'gravityview_go_back_url', [ $this, 'single_entry_go_back_url' ] );
}

/**
* Fix the permalinks to the entry for the DataTables layout.
*
* @since TODO
*
* @param string $permalink
*
* @return string The filtered output of the DataTables extension.
*/
public function filter_datatables_permalink( $permalink ) {

$parts = explode( '?', $permalink );

return $this->add_endpoint_to_directory_link( $parts[0] ) . '?' . $parts[1];
}

/**
* Fix the permalinks to the entry for the DataTables layout.
*
* @since TODO
*
* @param string $output The output of the DataTables extension.
* @param \GV\View $view The View context.
*
* @return string The filtered output of the DataTables extension.
*/
public function filter_datatables_output( $output, $view ) {

if ( empty( $output['data'] ) ) {
return $output;
}

$entry_endpoint = \GV\Entry::get_endpoint_name();
foreach ( $output['data'] as &$entry ) {

foreach( $entry as $key => $column ) {
$entry[ $key ] = preg_replace( '/\/(' . preg_quote( $entry_endpoint ) . ')\/(.*?)\/?/is', '/?$1=$2', $column );
}
}

return $output;
}

/**
Expand Down Expand Up @@ -234,7 +295,6 @@ public function dashboard_content() {

// Append the LifterLMS GravityView endpoint to the directory link.
add_filter( 'gravityview_directory_link', [ $this, 'add_endpoint_to_directory_link' ] );

add_filter( 'gravityview_go_back_url', [ $this, 'single_entry_go_back_url' ] );

echo do_shortcode( $content );
Expand Down Expand Up @@ -276,7 +336,7 @@ public function return_false() {
*/
public function add_endpoint_to_directory_link( $permalink ) {

// Check against empty string (WordPress) instead of false (as returned by this class).
/** Check against empty string (WordPress) instead of false (as returned by {@see return_false}). */
if ( '' === get_option( 'permalink_structure' ) ) {
return add_query_arg( [ $this->get_endpoint() => 1 ], $permalink );
}
Expand Down