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 | } |