LessonsReportsGenerator

Extends report generator for lessons reports

Description

Source

File: bp-integrations/learndash/buddypress/generators/LessonsReportsGenerator.php

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class LessonsReportsGenerator extends ReportsGenerator
{
    /**
     * Constructor
     *
     * @since BuddyBoss 1.0.0
     */
    public function __construct()
    {
        $this->completed_table_title = __('Completed Lessons', 'buddyboss');
        $this->incompleted_table_title = __('Incomplete Lessons', 'buddyboss');
 
        parent::__construct();
    }
 
    /**
     * Returns the columns and their settings
     *
     * @since BuddyBoss 1.0.0
     */
    protected function columns()
    {
        return [
            'user_id'         => $this->column('user_id'),
            'user'            => $this->column('user'),
            'course_id'       => $this->column('course_id'),
            'course'          => $this->column('course'),
            'lesson'          => [
                'label'     => __( 'Lesson', 'buddyboss' ),
                'sortable'  => true,
                'order_key' => 'post_title',
            ],
            'start_date'      => $this->column('start_date'),
            'completion_date' => $this->column('completion_date'),
            'updated_date'    => $this->column('updated_date'),
            'time_spent'      => $this->column('time_spent'),
        ];
    }
 
    /**
     * Format the activity results for each column
     *
     * @since BuddyBoss 1.0.0
     */
    protected function formatData($activity)
    {
        return [
            'user_id'         => $activity->user_id,
            'user'            => $activity->user_display_name,
            'course_id'       => $activity->activity_course_id,
            'course'          => $activity->activity_course_title,
            'lesson'          => $activity->post_title,
            'start_date'      => $activity->activity_started_formatted,
            'completion_date' => $this->completionDate($activity),
            'updated_date'    => $this->updatedDate($activity),
            'time_spent'      => $this->timeSpent($activity),
        ];
    }
 
    /**
     * Overwrite results value for export
     *
     * @since BuddyBoss 1.0.0
     */
    protected function formatDataForExport( $data, $activity ) {
        $data['status'] = empty( $activity->activity_completed ) ? $this->incompleted_table_title : $this->completed_table_title;
 
        return $data;
    }
 
    /**
     * Overwrite results value for display
     *
     * @since BuddyBoss 1.0.0
     */
    protected function formatDataForDisplay($data, $activity)
    {
        $data = wp_parse_args([
            'lesson' => sprintf(
                '<a href="%s" target="_blank">%s</a>',
                get_permalink($activity->post_id),
                $activity->post_title
            )
        ], $data);
 
        return parent::formatDataForDisplay($data, $activity);
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Methods

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.