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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / tutor-droip / backend / ElementGenerator / LessonGenerator.php
tutor / tutor-droip / backend / ElementGenerator Last commit date
ActionBoxGenerator.php 1 year ago AnnouncementsGenerator.php 1 year ago CourseMetaGenerator.php 1 year ago CourseThumbnailGenerator.php 1 year ago ElementGenerator.php 1 year ago GradebookGenerator.php 1 year ago InstructorGenerator.php 1 year ago LessonGenerator.php 1 year ago Preview.php 1 year ago QnAGenerator.php 1 year ago RatingGenerator.php 1 year ago ResourcesGenerator.php 1 year ago ShareGenerator.php 1 year ago TopicsGenerator.php 1 year ago WishListGenerator.php 1 year ago
LessonGenerator.php
292 lines
1 <?php
2 /**
3 * Lesson view generator
4 *
5 * @package tutor-droip-elements
6 */
7
8 namespace TutorLMSDroip\ElementGenerator;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Class LessonGenerator
16 * This class is used to define all lesson generator functions.
17 */
18 trait LessonGenerator {
19
20 /**
21 * Post type enum
22 *
23 * @var array
24 */
25 private $post_type_enum = array(
26 'QUIZ' => 'tutor_quiz',
27 'ASSIGNMENT' => 'tutor_assignments',
28 'LESSON' => 'lesson',
29 'GOOGLE_MEET' => 'tutor-googl,-meet',
30 'ZOOM' => 'tutor_zoom_meeting',
31 );
32
33 /**
34 * Generate lessons markup
35 */
36 private function generate_lessions_all_markup() {
37 switch ( $this->element['name'] ) {
38 case TDE_APP_PREFIX . '-lessons':
39 return $this->generate_lessons_markup();
40 case TDE_APP_PREFIX . '-assignment':
41 case TDE_APP_PREFIX . '-googlemeet':
42 case TDE_APP_PREFIX . '-lesson-video':
43 case TDE_APP_PREFIX . '-lesson-text':
44 case TDE_APP_PREFIX . '-quiz':
45 case TDE_APP_PREFIX . '-zoom':
46 return $this->generate_lesson_markup();
47 case TDE_APP_PREFIX . '-lesson-duration':
48 return $this->generate_lesson_duration();
49 case TDE_APP_PREFIX . '-lesson-access':
50 return $this->lesson_aceess();
51 case TDE_APP_PREFIX . '-meeting-status':
52 return $this->lesson_status();
53 }
54 }
55
56 /**
57 * Generate lessons markup
58 *
59 * @return string
60 */
61 private function generate_lessons_markup() {
62 $element_block = $this->group_elements_by_element_name();
63
64 $lessons_query = tutor_utils()->get_course_contents_by_topic( $this->options['post']->ID, -1 );
65
66 $children = '';
67
68 while ( $lessons_query->have_posts() ) {
69 $lessons_query->the_post();
70 global $post;
71
72 $options = array_merge(
73 $this->options,
74 array(
75 'post' => $post,
76 )
77 );
78
79 switch ( get_post_type() ) {
80 case $this->post_type_enum['QUIZ']:
81 $quiz_block = $element_block[ TDE_APP_PREFIX . '-quiz' ];
82 $children .= call_user_func( $this->generate_child_element, $quiz_block['id'], $options );
83 break;
84 case $this->post_type_enum['ASSIGNMENT']:
85 $assignment_block = $element_block[ TDE_APP_PREFIX . '-assignment' ];
86
87 $children .= call_user_func( $this->generate_child_element, $assignment_block['id'], $options );
88 break;
89 case $this->post_type_enum['LESSON']:
90 if ( $this->lesson_has_video() ) {
91 $lesson_block = $element_block[ TDE_APP_PREFIX . '-lesson-video' ];
92
93 $children .= call_user_func( $this->generate_child_element, $lesson_block['id'], $options );
94 } else {
95 $lesson_block = $element_block[ TDE_APP_PREFIX . '-lesson-text' ];
96
97 $children .= call_user_func( $this->generate_child_element, $lesson_block['id'], $options );
98 }
99 break;
100
101 case $this->post_type_enum['ZOOM']:
102 $zoom_block = $element_block[ TDE_APP_PREFIX . '-zoom' ];
103
104 $children .= call_user_func( $this->generate_child_element, $zoom_block['id'], $options );
105 break;
106
107 case $this->post_type_enum['GOOGLE_MEET']:
108 $googlemeet_block = $element_block[ TDE_APP_PREFIX . '-googlemeet' ];
109
110 $children .= call_user_func( $this->generate_child_element, $googlemeet_block['id'], $options );
111 break;
112
113 default:
114 $children .= ( '<div>' . get_post_type() . ': ' . get_the_title() . '</div>' );
115 break;
116
117 }
118 }
119
120 wp_reset_postdata();
121
122 return "<div $this->attributes > $children </div>";
123 }
124
125 /**
126 * Generate lesson markup
127 *
128 * @return string
129 */
130 private function generate_lesson_markup() {
131 global $post;
132
133 $lesson_permalink = $this->lesson_has_access() ? get_the_permalink() : 'javascript:void()';
134
135 $children = '';
136
137 $options = array_merge(
138 $this->options,
139 array(
140 'post' => $post,
141 )
142 );
143
144 if ( isset( $this->element['children'] ) && $this->element['children'] && is_array( $this->element['children'] ) ) {
145 $children = array_reduce(
146 $this->element['children'],
147 fn ( $carry, $item ) => ( $carry . call_user_func( $this->generate_child_element, $item, $options ) ),
148 ''
149 );
150 }
151
152 return "<a $this->attributes href='$lesson_permalink' > $children </a>";
153 }
154
155 /**
156 * Generate lesson duration markup
157 *
158 * @return string
159 */
160 private function generate_lesson_duration() {
161 $duration = tutor_utils()->get_optimized_duration( $this->lesson_play_time() );
162
163 return "<div $this->attributes> $duration </div>";
164 }
165
166 /**
167 * Generate lesson access markup
168 *
169 * @return string
170 */
171 private function lesson_aceess() {
172 $is_locked = $this->lesson_is_locked();
173
174 $child = $is_locked ?
175 call_user_func( $this->generate_child_element, $this->element['children'][0], $this->options ) :
176 call_user_func( $this->generate_child_element, $this->element['children'][1], $this->options );
177
178 return "<span $this->attributes> $child </span>";
179 }
180
181 /**
182 * Generate lesson status markup
183 *
184 * @return string
185 */
186 private function lesson_status() {
187 if ( ! tutor()->has_pro ) {
188 return '';
189 }
190
191 global $post;
192
193 $element_blocks = $this->group_elements_by_element_name();
194
195 $live_block = $element_blocks[ TDE_APP_PREFIX . '-meeting-live' ];
196
197 $expired_block = $element_blocks[ TDE_APP_PREFIX . '-meeting-expired' ];
198
199 $zoom_meeting = tutor_zoom_meeting_data( $post->ID );
200
201 $block = null;
202
203 if ( $zoom_meeting->is_expired ) {
204 $block = $expired_block;
205 } elseif ( $zoom_meeting->is_started ) {
206 $block = $live_block;
207 }
208
209 $child = $block ? call_user_func( $this->generate_child_element, $block['id'], $this->options ) : '';
210
211 return "<div $this->attributes> $child </div>";
212 }
213
214 /**
215 * Check if lesson has video
216 *
217 * @return bool
218 */
219 private function lesson_has_video() {
220 return (bool) tutor_utils()->get_video_info();
221 }
222
223 /**
224 * Check if lesson is locked
225 *
226 * @return bool
227 */
228 private function lesson_play_time() {
229 $video = tutor_utils()->get_video_info();
230
231 $play_time = $video ? $video->playtime : 0;
232
233 return $play_time;
234 }
235
236 /**
237 * Check if lesson is enrolled
238 *
239 * @return bool
240 */
241 private function is_enrolled() {
242 $course_id = $this->get_course_id();
243
244 return (bool) tutor_utils()->is_enrolled( $course_id );
245 }
246
247 /**
248 * Get course id
249 *
250 * @return int
251 */
252 private function get_course_id() {
253 global $post;
254
255 if ( ! $this->course_id ) {
256 $this->course_id = tutor_utils()->get_course_id_by( 'lesson', $post->ID );
257 }
258
259 return $this->course_id;
260 }
261
262 /**
263 * Check if lesson has access
264 *
265 * @return bool
266 */
267 private function lesson_has_access() {
268 $course_id = $this->get_course_id();
269
270 return $this->is_enrolled() ||
271 (
272 get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes' &&
273 ! tutor_utils()->is_course_purchasable( $course_id )
274 );
275 }
276
277 /**
278 * Check if lesson is locked
279 *
280 * @return bool
281 */
282 private function lesson_is_locked() {
283 global $post;
284
285 $course_id = $this->get_course_id();
286
287 $is_preview = get_post_meta( $post->ID, '_is_preview', true );
288
289 return ! ( $this->is_enrolled() || $is_preview || \TUTOR\Course_List::is_public( $course_id ) );
290 }
291 }
292