UserData::enrol_course( object|int $course, int $order_id = null, string $expired_at = '' )
Enrol to the course
Parameters
- $course
-
(object|int) (Required) Course Object or Course ID
- $order_id
-
(int) (Optional)
Default value: null
- $expired_at
-
(string) (Optional) Date time mysql format
Default value: ''
Return
(bool|DozentModelEnrol)
Source
File: classes/UserData.php
public function enrol_course( $course, $order_id = null, $expired_at = '' ) { $course = dozent_get_course( $course ); $course_id = $course->get_id(); $product_id = dozent_get_attached_product_id_by_course( $course ); //Enrolment $enrol = dozent_enrolment(); $enrol->course_id = $course_id; $enrol->user_id = $this->user_id; if ( $order_id ) { $enrol->order_id = $order_id; } if ( $product_id ) { $enrol->order_by_product_id = $product_id; } if ( $course->is_free() ) { $enrol->status = 'active'; } else { $enrol->status = apply_filters( 'dozent_course_new_enrol_status', 'pending', $course, $order_id, $expired_at = '' ); } if ( $expired_at ) { $enrol->expired_at = $expired_at; } /** * Filter the pre enrol data * Enrolment data is Object Format * * @since DozentLMS 1.0.0 * * @param object $enrol Enrolment object, set for insert data into 'dozent_enrols' table * @param object $course Course Object which need enrol * @param int|null $order_id Order ID if exists * @param string $expired_at If Exists * */ $enrol = apply_filters( 'dozent_pre_course_enrol_data', $enrol, $course, $order_id = null, $expired_at = '' ); $enrol->do_enrol(); //End Enrolment if ( $course_id ) { $enrolled_courses = (array) $this->get( 'enrolled_courses' ); $enrolled_courses[] = $course_id; $this->update( 'enrolled_courses', array_filter( $enrolled_courses ) ); } return $enrol; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |