/var/www/html_uk/wp-content/plugins/automatewoo/includes/Sensei_Workflow_Helper.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
<?php

namespace AutomateWoo;

defined'ABSPATH' ) || exit;

/**
 * Class Sensei_Workflow_Helper
 *
 * @since 5.6.10
 *
 * @package AutomateWoo
 */
class Sensei_Workflow_Helper {

    
/**
     * Get the Sensei group name.
     *
     * @return string
     */
    
public static function get_group_name() {
        return 
__'Sensei LMS''automatewoo' );
    }

    
/**
     * Get the Sensei Courses field.
     *
     * @return Fields\Sensei_Course
     */
    
public static function get_courses_field() {
        
$field = new Fields\Sensei_Course();
        
$field->set_name'sensei_courses' );
        
$field->set_title__'Courses''automatewoo' ) );
        
$field->set_description__'Select courses here to have this workflow trigger only for those specific courses. Leave blank to run for all courses.''automatewoo' ) );
        
$field->set_multipletrue );

        return 
$field;
    }

    
/**
     * Get the Sensei Lessons field.
     *
     * @return Fields\Sensei_Lesson
     */
    
public static function get_lessons_field() {
        
$field = new Fields\Sensei_Lesson();
        
$field->set_name'sensei_lessons' );
        
$field->set_title__'Lessons''automatewoo' ) );
        
$field->set_description__'Select lessons here to have this workflow trigger only for those specific lessons. Leave blank to run for all lessons.''automatewoo' ) );
        
$field->set_multipletrue );

        return 
$field;
    }

    
/**
     * Get the Sensei Quizzes field.
     *
     * @return Fields\Sensei_Quiz
     */
    
public static function get_quizzes_field() {
        
$field = new Fields\Sensei_Quiz();
        
$field->set_name'sensei_quizzes' );
        
$field->set_title__'Quizzes''automatewoo' ) );
        
$field->set_description__'Select quizzes here to have this workflow trigger only for those specific quizzes. Leave blank to run for all quizzes.''automatewoo' ) );
        
$field->set_multipletrue );

        return 
$field;
    }

    
/**
     * Get the Sensei Question field.
     *
     * @return Fields\Sensei_Question
     */
    
public static function get_question_field() {
        
$field = new Fields\Sensei_Question();
        
$field->set_name'sensei_question' );
        
$field->set_title__'Question''automatewoo' ) );
        
$field->set_description__'Select question here to have this workflow trigger only for those specific question.''automatewoo' ) );
        
$field->set_requiredtrue );

        return 
$field;
    }

    
/**
     * Get the Sensei Groups field.
     *
     * @return Fields\Sensei_Group
     */
    
public static function get_groups_field() {
        
$field = new Fields\Sensei_Group();
        
$field->set_name'sensei_groups' );
        
$field->set_title__'Groups''automatewoo' ) );
        
$field->set_description__'Select groups here to have this workflow trigger only for those specific groups. Leave blank to run for all groups.''automatewoo' ) );
        
$field->set_multipletrue );

        return 
$field;
    }

    
/**
     * Get student courses.
     *
     * @param int $user_id
     * @return array
     */
    
public static function get_student_course_ids$user_id ) {
        
$course_ids      = [];
        
$course_statuses \Sensei_Utils::sensei_check_for_activity(
            [
                
'user_id' => $user_id,
                
'type'    => 'sensei_course_status',
                
'status'  => 'any',
            ],
            
true
        
);

        
// Check for activity returns single if only one. We always want an array.
        
if ( ! is_array$course_statuses ) ) {
            
$course_statuses = [ $course_statuses ];
        }

        foreach ( 
$course_statuses as $status ) {
            
$course_ids[] = intval$status->comment_post_ID );
        }

        return 
$course_ids;
    }

    
/**
     * Get student quizzes.
     *
     * @param int $user_id
     * @return array
     */
    
public static function get_student_quiz_ids$user_id ) {
        
$course_ids self::get_student_course_ids$user_id );
        if ( empty( 
$course_ids ) ) {
            return [];
        }

        
$quiz_ids = [];
        foreach ( 
$course_ids as $course_id ) {
            
$quizzes \Sensei()->course->course_quizzes$course_id );
            if ( ! empty( 
$quizzes ) ) {
                
$quiz_ids array_merge$quiz_ids$quizzes );
            }
        }
        return 
$quiz_ids;
    }
}