Php GamiPress与Namaste LMS的集成

Php GamiPress与Namaste LMS的集成,php,triggers,event-listener,Php,Triggers,Event Listener,我想在GamiPress中创建一个自定义事件侦听器。代码如下: function my_prefix_register_specific_triggers_for_purchase_a_product( $triggers ) { $triggers['My Custom Specific Purchase Events'] = array( // Register the event my_prefix_custom_specific_purchase_event

我想在GamiPress中创建一个自定义事件侦听器。代码如下:

function my_prefix_register_specific_triggers_for_purchase_a_product( $triggers ) {

    $triggers['My Custom Specific Purchase Events'] = array(
        // Register the event my_prefix_custom_specific_purchase_event
        'my_prefix_custom_specific_purchase_event' => __( 'Purchase a specific product', 'gamipress' ),
    );

    return $triggers;

}
add_filter( 'gamipress_activity_triggers', 'my_prefix_register_specific_triggers_for_purchase_a_product' );

function my_prefix_specific_triggers_for_purchase_a_product( $specific_triggers ) {

    // Set 'my_prefix_custom_specific_purchase_event' as specific event that requires the 'product' post type
    $specific_triggers['my_prefix_custom_specific_purchase_event'] = array( 'product' );

    return $specific_triggers;

}
add_filter( 'gamipress_specific_activity_triggers', 'my_prefix_specific_triggers_for_purchase_a_product' );

function my_prefix_specific_label_for_purchase_a_product( $specific_trigger_labels ) {

    // %s will be replaced with the product title
    $specific_trigger_labels['my_prefix_custom_specific_purchase_event'] = __( 'Purchase the %s product', 'gamipress' );

    // GamiPress automatically will use this pattern for auto-generate the requirement label
    // Some examples with "Purchase the %s product" label:
    // Step example using the product "T-shirt": Purchase the T-shirt product 2 times
    // Points award example using the product "CD Album": 10 points for purchase the CD Album product  5 times

    return $specific_trigger_labels;

}
add_filter( 'gamipress_specific_activity_trigger_label', 'my_prefix_specific_label_for_purchase_a_product' );

function my_prefix_specific_listener_for_purchase_a_product( $order_id ) {

    $order = wc_get_order( $order_id );

    foreach ( $order->get_items() as $item ) {

        // Call to gamipress_trigger_event() on each product purchased
        gamipress_trigger_event( array(
            'event' => 'my_prefix_custom_specific_purchase_event', // Set our custom purchase event
            'user_id' => $order->user_id, // User that will be awarded is the one who made the order
            'specific_id' => $item->get_product_id(), // Specific ID, here is the product ID

            // Add any extra parameters you want
            // In this example we passed the order item object and the order object itself
            'item' => $item,
            'order' => $order,
        ) );

    }

}
// The safe way to check if an user has perform a purchase is when an order payment is set to completed
// So let's hook the 'woocommerce_payment_complete' action
add_action( 'woocommerce_payment_complete', 'my_prefix_specific_listener_for_purchase_a_product' );
现在我想修改上面的代码,以便在用户收到Namaste LMS!中的点时,它成为事件侦听器!。我在Namaste文件中查找了函数,它如下所示:

static function auto_grade_course($course_id, $student_id) {
global $wpdb;

if(get_option('namaste_use_grading_system') == '') return false;

$auto_grade = get_post_meta($course_id, 'namaste_auto_grade', true);
if(!$auto_grade) return false;

$_lesson = new NamasteLMSLessonModel();
$lessons = $_lesson->select($course_id);
if(!sizeof($lessons)) return false;

$grades_points = self :: grades_points();

$total = $num_graded_lessons = 0;
foreach($lessons as $lesson) {
    $lesson_grade = $wpdb->get_var($wpdb->prepare("SELECT grade FROM ".NAMASTE_STUDENT_LESSONS." 
        WHERE student_id=%d AND lesson_id=%d", $student_id, $lesson->ID));
    if(!empty($lesson_grade)) {
        $num_graded_lessons++;
        $lesson_grade = trim($lesson_grade);
        $points = intval(@$grades_points[$lesson_grade]);
        $total += $points;
    }   
} // end foreach lesson
我的意思不是要一个现成的解决方案,但你们中的一些人能否指导我找到我的答案,如何创建一个特定的事件,当用户在Namaste LMS中收到一个点时触发该事件