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