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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 / Preview.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
Preview.php
302 lines
1 <?php
2 /**
3 * Preview script for html markup 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 Preview
16 * This class is used to define all preview functions.
17 */
18 class Preview {
19 use LessonGenerator;
20 use InstructorGenerator;
21 use ShareGenerator;
22 use CourseMetaGenerator;
23 use ActionboxGenerator;
24 use WishListGenerator;
25 use CourseThumbnailGenerator;
26 use RatingGenerator;
27 use AnnouncementsGenerator;
28 use QnAGenerator;
29 use ResourcesGenerator;
30 use GradebookGenerator;
31 use TopicsGenerator;
32
33 /**
34 * Droip element object
35 *
36 * @var array $element | element data.
37 */
38 private $element = array();
39 /**
40 * Droip all elements object
41 *
42 * @var array $elements | array of elements.
43 */
44 private $elements = array();
45 /**
46 * Droip all style blocks object
47 *
48 * @var array $style_blocks | array of style blocks.
49 */
50 private $style_blocks = array();
51 /**
52 * Droip all style blocks object
53 *
54 * @var array $style_blocks | array of style blocks.
55 */
56 private $attributes = array();
57 /**
58 * Droip all options object
59 *
60 * @var array $options | array of options.
61 */
62 private $options = array();
63 /**
64 * Droip generate child element function
65 *
66 * @var callable $generate_child_element | function.
67 */
68 private $generate_child_element = null;// function.
69 /**
70 * Droip generate child element with new id function
71 *
72 * @var callable $generate_child_element_with_new_id | function.
73 */
74 private $generate_child_element_with_new_id = null;// function.
75 /**
76 * Droip element properties
77 *
78 * @var array $properties | array of element properties.
79 */
80 private $properties = array();
81 /**
82 * LMS course id
83 *
84 * @var int $course_id | course id.
85 */
86 private $course_id = null;
87
88 /**
89 * Class constructor
90 *
91 * @param array $props array of element properties.
92 *
93 * @since 1.0.0
94 */
95 public function __construct( $props ) {
96 $this->element = $props['element'];
97 $this->elements = $props['elements'];
98 $this->style_blocks = $props['style_blocks'];
99 $this->attributes = $props['attributes'];
100 $this->options = $props['options'];
101 $this->generate_child_element = $props['generate_child_element'];
102 $this->generate_child_element_with_new_id = $props['generate_child_element_with_new_id'];
103 $this->properties = $this->element['properties'];
104 }
105
106
107 /**
108 * Generate elements
109 *
110 * $element: the element
111 * $attributes: elements html attributes
112 * $options: options is needed if any dynamic content need to be render
113 * $generate_child_element: this is a helper method for printing nested element or child elements. This method take 2 arg: 1. elemenbt id 2. $options.
114 *
115 * @return string html markup;
116 */
117 public function generate_elements() {
118
119 switch ( $this->element['name'] ) {
120 case TDE_APP_PREFIX . '-wish-list':
121 case TDE_APP_PREFIX . '-wish-list-normal':
122 case TDE_APP_PREFIX . '-wish-list-loading':
123 case TDE_APP_PREFIX . '-wish-list-wishlisted':
124 case TDE_APP_PREFIX . '-wish-list-unauthinticate':
125 return $this->generate_wish_list_elements();
126
127 // Share Course.
128 case TDE_APP_PREFIX . '-share-course':
129 return $this->generate_course_share_markup();
130
131 // Course meta.
132 case TDE_APP_PREFIX . '-course-meta':
133 case TDE_APP_PREFIX . '-course-level':
134 case TDE_APP_PREFIX . '-course-level-text':
135 case TDE_APP_PREFIX . '-enroll-count':
136 case TDE_APP_PREFIX . '-enroll-count-value':
137 case TDE_APP_PREFIX . '-course-duration':
138 case TDE_APP_PREFIX . '-course-duration-value':
139 case TDE_APP_PREFIX . '-course-update':
140 case TDE_APP_PREFIX . '-course-update-value':
141 case TDE_APP_PREFIX . '-sidebar-meta':
142 case TDE_APP_PREFIX . '-sidebar-meta-icon':
143 case TDE_APP_PREFIX . '-sidebar-meta-value':
144 return $this->generate_course_meta_markup();
145
146 case TDE_APP_PREFIX . '-course-thumbnail-image':
147 case TDE_APP_PREFIX . '-course-thumbnail-video':
148 return $this->generate_course_thumbnail_elements();
149
150 // Action box.
151 case TDE_APP_PREFIX . '-course-enroll-buttons':
152 case TDE_APP_PREFIX . '-free-action-box':
153 case TDE_APP_PREFIX . '-enroll-button':
154 case TDE_APP_PREFIX . '-paid-action-buttons':
155 case TDE_APP_PREFIX . '-cart-box':
156 case TDE_APP_PREFIX . '-add-to-cart-button':
157 case TDE_APP_PREFIX . '-view-cart-button':
158 case TDE_APP_PREFIX . '-discounted-price':
159 case TDE_APP_PREFIX . '-regular-price':
160 case TDE_APP_PREFIX . '-course-action-buttons':
161 case TDE_APP_PREFIX . '-start-learning':
162 case TDE_APP_PREFIX . '-continue-learning':
163 case TDE_APP_PREFIX . '-complete-course':
164 case TDE_APP_PREFIX . '-retake-and-certificate':
165 case TDE_APP_PREFIX . '-retake-course':
166 case TDE_APP_PREFIX . '-view-certificate':
167 case TDE_APP_PREFIX . '-enroll-info':
168 case TDE_APP_PREFIX . '-enroll-date':
169 case TDE_APP_PREFIX . '-lesson-counter':
170 case TDE_APP_PREFIX . '-progress-percent':
171 case TDE_APP_PREFIX . '-progress-bar-inner':
172 return $this->generate_actionbox_markup();
173
174 case TDE_APP_PREFIX . '-rating-empty':
175 case TDE_APP_PREFIX . '-rating-not-empty':
176 case TDE_APP_PREFIX . '-rating-summery':
177 case TDE_APP_PREFIX . '-rating-summery-item-index':
178 case TDE_APP_PREFIX . '-rating-summery-item-progress':
179 case TDE_APP_PREFIX . '-review-add-edit':
180 case TDE_APP_PREFIX . '-review-text-input':
181 return $this->generate_review_elements();
182
183 case TDE_APP_PREFIX . '-rating-active-icon':
184 case TDE_APP_PREFIX . '-rating-inactive-icon':
185 case TDE_APP_PREFIX . '-rating-avarage-count':
186 case TDE_APP_PREFIX . '-rating-total-count':
187 return $this->generate_rating_elements();
188
189 case TDE_APP_PREFIX . '-lessons':
190 case TDE_APP_PREFIX . '-assignment':
191 case TDE_APP_PREFIX . '-googlemeet':
192 case TDE_APP_PREFIX . '-lesson-video':
193 case TDE_APP_PREFIX . '-lesson-text':
194 case TDE_APP_PREFIX . '-quiz':
195 case TDE_APP_PREFIX . '-zoom':
196 case TDE_APP_PREFIX . '-lesson-duration':
197 case TDE_APP_PREFIX . '-lesson-access':
198 case TDE_APP_PREFIX . '-meeting-status':
199 // case TDE_APP_PREFIX . '-has-topics':
200 return $this->generate_lessions_all_markup();
201
202 case TDE_APP_PREFIX . '-instructor-list':
203 case TDE_APP_PREFIX . '-instructor-list-item':
204 case TDE_APP_PREFIX . '-instructor-avatar':
205 case TDE_APP_PREFIX . '-instructor-name':
206 return $this->generate_instructor_all_markup();
207
208 case TDE_APP_PREFIX . '-announcements':
209 case TDE_APP_PREFIX . '-has-announcements':
210 case TDE_APP_PREFIX . '-no-announcements':
211 return $this->generate_announcements_markup();
212
213 case TDE_APP_PREFIX . '-topics':
214 case TDE_APP_PREFIX . '-has-topics':
215 case TDE_APP_PREFIX . '-no-topics':
216 return $this->generate_topics_markup();
217
218 case TDE_APP_PREFIX . '-qna-editor':
219 return $this->generate_qna_editor();
220
221 case TDE_APP_PREFIX . '-qna-reply':
222 return $this->generate_qna_reply();
223
224 case TDE_APP_PREFIX . '-reply-button':
225 return $this->generate_qna_reply_button();
226
227 // Resources.
228 case TDE_APP_PREFIX . '-resources':
229 case TDE_APP_PREFIX . '-has-resources':
230 case TDE_APP_PREFIX . '-resource-download':
231 case TDE_APP_PREFIX . '-resource-title':
232 case TDE_APP_PREFIX . '-resource-size':
233 return $this->generate_resources_markup();
234
235 // Gradebook.
236 case TDE_APP_PREFIX . '-gradebook':
237 case TDE_APP_PREFIX . '-has-gradebook':
238 case TDE_APP_PREFIX . '-no-gradebook':
239 return $this->generate_course_gradebook_markup();
240
241 default:
242 return $this->generate_common_element();
243
244 }
245 }
246
247 /**
248 * Generate common element.
249 *
250 * @param bool $hide | false | true. | Hide element.
251 * @param bool $children_html | false | true. | Hide children.
252 * @return string
253 */
254 private function generate_common_element( $hide = false, $children_html = false ) {
255 $extra_attributes = '';
256 if ( $hide ) {
257 $extra_attributes .= ' data-element_hide="true"';
258 }
259
260 $html = '';
261 $tag = isset( $this->properties['tag'] ) ? $this->properties['tag'] : 'div';
262 $name = $this->element['name'];
263 if ( ! $children_html ) {
264 $children_html = $this->generate_child_elements();
265 }
266 $html = "<$tag $this->attributes data-ele_name='$name' $extra_attributes>$children_html</$tag>";
267 return $html;
268 }
269
270 /**
271 * Generate child elements.
272 *
273 * @return string
274 */
275 private function generate_child_elements() {
276 $html = '';
277 $child_count = isset( $this->element['children'] ) ? count( $this->element['children'] ) : 0;
278 for ( $i = 0; $i < $child_count; $i++ ) {
279 $html .= call_user_func( $this->generate_child_element, $this->element['children'][ $i ], $this->options );
280 }
281 return $html;
282 }
283
284 /**
285 * Generate child element by name.
286 *
287 * @return array $element | Element array.
288 */
289 private function group_elements_by_element_name() {
290 return array_reduce(
291 $this->element['children'],
292 function ( $carry, $item ) {
293 if ( isset( $this->elements[ $item ], $this->elements[ $item ]['name'] ) ) {
294 $carry[ $this->elements[ $item ]['name'] ] = $this->elements[ $item ];
295 }
296
297 return $carry;
298 },
299 array()
300 );
301 }
302 }