Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/classes/ProgressReset.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Manage Course Progress Reset
4
+
*
5
+
* @package TutorPro
6
+
* @subpackage Frontend
7
+
* @author Themeum <support@themeum.com>
8
+
* @link https://themeum.com
9
+
* @since 3.9.0
10
+
*/
11
+
12
+
namespace TUTOR_PRO;
13
+
14
+
use TUTOR\Input;
15
+
use Tutor\Traits\JsonResponse;
16
+
use TUTOR\User;
17
+
18
+
if ( ! defined( 'ABSPATH' ) ) {
19
+
exit;
20
+
}
21
+
22
+
/**
23
+
* Progress Reset Class
24
+
*
25
+
* @since 3.9.0
26
+
*/
27
+
class ProgressReset {
28
+
29
+
use JsonResponse;
30
+
31
+
/**
32
+
* Register hooks
33
+
*
34
+
* @since 3.9.0
35
+
*
36
+
* @return void
37
+
*/
38
+
public function __construct() {
39
+
add_filter( 'tutor/options/extend/attr', array( $this, 'setting_field' ), 11 );
40
+
add_action( 'tutor_after_enrollment_list_course_progress', array( $this, 'reset_student_progress_button' ), 10, 3 );
41
+
add_action( 'tutor_after_student_profile_course_progress', array( $this, 'reset_student_progress_button' ), 10, 3 );
42
+
add_action( 'tutor_after_student_details_view_progress', array( $this, 'dashboard_reset_student_progress_button' ), 10, 3 );
43
+
add_action( 'wp_ajax_tutor_reset_student_course_progress', array( $this, 'ajax_reset_student_course_progress' ) );
44
+
}
45
+
46
+
/**
47
+
* Settings field.
48
+
*
49
+
* @since 3.9.0
50
+
*
51
+
* @param array $attr attr.
52
+
*
53
+
* @return array
54
+
*/
55
+
public function setting_field( $attr ) {
56
+
$attr['general']['blocks'][3]['fields'][] = array(
57
+
'key' => 'instructor_can_reset_course_progress',
58
+
'type' => 'toggle_switch',
59
+
'label' => __( 'Allow Instructors to Reset Student Progress', 'tutor-pro' ),
60
+
'label_title' => '',
61
+
'default' => 'off',
62
+
'desc' => __( 'Enable to allow instructors to reset a student’s course progress.', 'tutor-pro' ),
63
+
);
64
+
65
+
return $attr;
66
+
}
67
+
68
+
/**
69
+
* Can reset students progress.
70
+
*
71
+
* @since 3.9.0
72
+
*
73
+
* @param int $user_id The user ID.
74
+
*
75
+
* @return bool
76
+
*/
77
+
public static function can_reset_progress( $user_id = 0 ) {
78
+
$can_instructor_reset = (bool) tutor_utils()->get_option( 'instructor_can_reset_course_progress' );
79
+
if ( User::is_admin( $user_id ) || ( User::is_only_instructor( $user_id ) && $can_instructor_reset ) ) {
80
+
return true;
81
+
}
82
+
return false;
83
+
}
84
+
85
+
/**
86
+
* Load progress modal template
87
+
*
88
+
* @since 3.9.0
89
+
*
90
+
* @return void
91
+
*/
92
+
public static function load_progress_modal() {
93
+
tutor_load_template_from_custom_path( tutor_pro()->path . '/views/modals/reset-progress-modal.php' );
94
+
}
95
+
96
+
/**
97
+
* Add reset progress button
98
+
*
99
+
* @since 3.9.0
100
+
*
101
+
* @param int $course_id id The course id.
102
+
* @param int $student_id id The student id.
103
+
* @param int $progress The progress.
104
+
*
105
+
* @return void
106
+
*/
107
+
public function reset_student_progress_button( $course_id, $student_id, $progress ) {
108
+
if ( ! $progress ) {
109
+
return;
110
+
}
111
+
?>
112
+
<button type="button"
113
+
class="tutor-btn tutor-btn-secondary tutor-btn-sm tutor-reset-progress-btn"
114
+
data-tutor-modal-target="tutor-reset-progress-modal"
115
+
data-course_id="<?php echo esc_attr( $course_id ); ?>"
116
+
data-student_id="<?php echo esc_attr( $student_id ); ?>">
117
+
<?php esc_html_e( 'Reset Progress', 'tutor-pro' ); ?>
118
+
</button>
119
+
<?php
120
+
}
121
+
122
+
123
+
/**
124
+
* Add reset progress button to student course actions.
125
+
*
126
+
* @since 3.9.0
127
+
*
128
+
* @param int $course_id id The course id.
129
+
* @param int $student_id id The student id.
130
+
* @param int $progress The progress.
131
+
*
132
+
* @return void
133
+
*/
134
+
public function dashboard_reset_student_progress_button( $course_id, $student_id, $progress ) {
135
+
if ( $progress && $this->can_reset_progress() ) {
136
+
?>
137
+
<button type="button"
138
+
class="tutor-btn tutor-btn-outline-primary tutor-btn-sm tutor-reset-progress-btn"
139
+
data-tutor-modal-target="tutor-reset-progress-modal"
140
+
data-course_id="<?php echo esc_attr( $course_id ); ?>"
141
+
data-student_id="<?php echo esc_attr( $student_id ); ?>">
142
+
<?php esc_html_e( 'Reset', 'tutor-pro' ); ?>
143
+
</button>
144
+
<?php
145
+
}
146
+
}
147
+
148
+
/**
149
+
* Reset course progress.
150
+
*
151
+
* @since 3.9.0
152
+
*
153
+
* @return void
154
+
*/
155
+
public function ajax_reset_student_course_progress() {
156
+
tutor_utils()->check_nonce();
157
+
158
+
$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );
159
+
$student_id = Input::post( 'student_id', 0, Input::TYPE_INT );
160
+
161
+
if ( ! $course_id || ! $student_id || ! tutor_utils()->is_enrolled( $course_id, $student_id, false ) ) {
162
+
$this->response_bad_request( __( 'Invalid request', 'tutor-pro' ) );
163
+
}
164
+
165
+
if ( $this->can_reset_progress() ) {
166
+
tutor_utils()->delete_course_progress( $course_id, $student_id );
167
+
$this->json_response( __( 'Progress has been successfully reset.', 'tutor-pro' ) );
168
+
} else {
169
+
$this->response_bad_request( tutor_utils()->error_message() );
170
+
}
171
+
}
172
+
}
173
+