LLMS_Course_Data::set_period( string $period = 'today' )

Set the dates pased on a date range period


Parameters Parameters

$period

(string) (Optional) date range period

Default value: 'today'


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.course.data.php

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
          AND post_id = %d
          AND updated_date BETWEEN %s AND %s
        ",
            $this->post_id,
            $this->get_date( $period, 'start' ),
            $this->get_date( $period, 'end' )
        )
    );// db call ok; no-cache ok.
 
}
 
/**
 * Retrieve # of course enrollments within the period
 *
 * @since 3.15.0
 * @since 3.31.0 Use $this->post_id instead of deprecated $this->course_id.
 *
 * @param string $period Optional. Date period [current|previous]. Default is 'current'.
 * @return int
 */
public function get_enrollments( $period = 'current' ) {
 
    global $wpdb;
 
    return $wpdb->get_var(
        $wpdb->prepare(
            "
        SELECT DISTINCT COUNT( user_id )
        FROM {$wpdb->prefix}lifterlms_user_postmeta
        WHERE meta_value = 'yes'
          AND meta_key = '_start_date'
          AND post_id = %d
          AND updated_date BETWEEN %s AND %s
        ",
            $this->post_id,
            $this->get_date( $period, 'start' ),
            $this->get_date( $period, 'end' )
        )
    );// db call ok; no-cache ok.
 
}
 
/**
 * Retrieve # of engagements related to the course awarded within the period
 *
 * @since 3.15.0
 *
 * @param string $type   Engagement type [email|certificate|achievement].
 * @param string $period Optional. Date period [current|previous]. Default is 'current'.
 * @return int
 */
public function get_engagements( $type, $period = 'current' ) {
 
    global $wpdb;
 
    $ids = implode( ',', $this->get_all_ids() );
 
    // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    return $wpdb->get_var(
        $wpdb->prepare(
            "
        SELECT DISTINCT COUNT( user_id )
        FROM {$wpdb->prefix}lifterlms_user_postmeta
        WHERE meta_key = %s
          AND post_id IN ( {$ids} )
          AND updated_date BETWEEN %s AND %s
        ",
            '_' . $type,
            $this->get_date( $period, 'start' ),
            $this->get_date( $period, 'end' )
        )
    );// db call ok; no-cache ok.
    // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
 
}
 
/**
 * Retrieves and returns the number of lessons completed within the period.
 *
 * @since 3.15.0
 * @since 5.10.0 Fixed issue when the course has no lessons.
 *
 * @param string $period Optional. Date period [current|previous]. Default is 'current'.
 * @return int
 */
public function get_lesson_completions( $period = 'current' ) {
 
    global $wpdb;
 
    $lessons = implode( ',', $this->post->get_lessons( 'ids' ) );
    // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
 
    // Return early for courses without any lessons.

Top ↑

Changelog Changelog

Changelog
Version Description
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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