LLMS_REST_Sections_Controller::prepare_links( LLMS_Section $section, WP_REST_Request $request )

Prepare links for the request.


Parameters Parameters

$section

(LLMS_Section) (Required) LLMS Section.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(array) Links for the given object.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/class-llms-rest-sections-controller.php

419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
* @param LLMS_Section    $section LLMS Section.
 * @param WP_REST_Request $request Request object.
 * @return array Links for the given object.
 */
protected function prepare_links( $section, $request ) {
 
    $links            = parent::prepare_links( $section, $request );
    $parent_course_id = $section->get( 'parent_course' );
 
    // If the section has no course parent return earlier.
    if ( ! $parent_course_id ) {
        return $links;
    }
 
    $parent_course = llms_get_post( $parent_course_id );
    if ( ! is_a( $parent_course, 'LLMS_Course' ) ) {
        return $links;
    }
 
    $section_id    = $section->get( 'id' );
    $section_links = array();
 
    // Parent (course).
    $section_links['parent'] = array(
        'type' => 'course',
        'href' => rest_url( sprintf( '/%s/%s/%d', 'llms/v1', 'courses', $parent_course_id ) ),
    );
 
    // Siblings.
    $section_links['siblings'] = array(
        'href' => add_query_arg(
            'parent',
            $parent_course_id,
            $links['collection']['href']
        ),
    );
 
    // Next.
    $next_section = $section->get_next();
    if ( $next_section ) {
        $section_links['next'] = array(
            'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $next_section->get( 'id' ) ) ),
        );
    }
 
    // Previous.
    $previous_section = $section->get_previous();
    if ( $previous_section ) {
        $section_links['previous'] = array(
            'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $previous_section->get( 'id' ) ) ),
        );


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.7 Fix the way we get the section's parent course object.
1.0.0-beta.23 Replaced call to deprecated LLMS_Section::get_parent_course() with LLMS_Section::get( 'parent_course' ).
1.0.0-beta.14 Added $request parameter.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.