PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / masteriyo-lms / includes / triggers / complete-course.php

complete-course.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.3, at integrations/masteriyo-lms/includes/triggers/complete-course.php

99 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trigger: Complete a Course
4 *
5 * @package AutomatorWP\Masteriyo_LMS\Triggers\Complete_Course
6 * @since 1.0.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) exit;
10
11 class AutomatorWP_Masteriyo_Complete_Course extends AutomatorWP_Integration_Trigger {
12
13 public $integration = 'masteriyo_lms';
14 public $trigger = 'masteriyo_lms_complete_course';
15
16 /**
17 * Register the trigger
18 *
19 * @since 1.0.0
20 */
21 public function register() {
22
23 automatorwp_register_trigger( $this->trigger, array(
24 'integration' => $this->integration,
25 'label' => __( 'User completes a course', 'automatorwp' ),
26 'select_option' => __( 'User completes a <strong>course</strong>', 'automatorwp' ),
27 //* translators: %1$s: Post title. %2$s: Number of times. */
28 'edit_label' => sprintf( __( 'User completes %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ),
29 /* translators: %1$s: Post title. */
30 'log_label' => sprintf( __( 'User completes %1$s', 'automatorwp' ), '{post}' ),
31 'action' => 'masteriyo_course_progress_status_completed',
32 'function' => array( $this, 'listener' ),
33 'priority' => 10,
34 'accepted_args' => 2,
35 'options' => array(
36 'post' => automatorwp_utilities_post_option( array(
37 'name' => __( 'Course:', 'automatorwp-tutor' ),
38 'option_none_label' => __( 'any course', 'automatorwp-tutor' ),
39 'post_type' => 'mto-course'
40 ) ),
41 'times' => automatorwp_utilities_times_option(),
42 ),
43 ) );
44 }
45
46 /**
47 * Trigger listener
48 *
49 * @since 1.0.0
50 *
51 * @param int $course_progress_id The course progress ID.
52 * @param \Masteriyo\Models\CourseProgress $course_progress The course progress object.
53 */
54 public function listener( $course_progress_id, $course_progress ) {
55
56 $user_id = $course_progress->get_user_id();
57 $course_id = $course_progress->get_course_id();
58
59 automatorwp_trigger_event( array(
60 'trigger' => $this->trigger,
61 'user_id' => $user_id,
62 'post_id' => $course_id,
63 'progress_id' => $course_progress_id,
64 ) );
65 }
66
67 /**
68 * User deserves check
69 *
70 * @since 1.0.0
71 *
72 * @param bool $deserves_trigger True if user deserves trigger, false otherwise.
73 * @param stdClass $trigger The trigger object.
74 * @param int $user_id The user ID.
75 * @param array $event The event data.
76 * @param array $trigger_options The trigger options.
77 * @param stdClass $automation The trigger's automation object.
78 *
79 * @return bool True if the user deserves the trigger, false otherwise.
80 */
81 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
82
83 // Don't deserve if post is not received
84 if( ! isset( $event['post_id'] ) ) {
85 return false;
86 }
87
88 // Don't deserve if post doesn't match with the trigger option
89 if( ! automatorwp_posts_matches( $event['post_id'], $trigger_options['post'] ) ) {
90 return false;
91 }
92
93 return $deserves_trigger;
94 }
95
96 }
97
98 new AutomatorWP_Masteriyo_Complete_Course();
99