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.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 / includes / droip / backend / ElementGenerator / Preview.php
tutor / includes / droip / backend / ElementGenerator Last commit date
ActionsGenerator.php 9 months ago AddRatingGenerator.php 1 year ago CourseMetaGenerator.php 9 months ago ElementGenerator.php 1 year ago MaterialGenerator.php 1 year ago Preview.php 1 year ago PriceGenerator.php 9 months ago SocialLinkGenerator.php 1 year ago ThumbnailGenerator.php 1 year ago
Preview.php
210 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 CourseMetaGenerator;
22 use AddRatingGenerator;
23 use MaterialGenerator;
24 use ActionsGenerator;
25 use PriceGenerator;
26 use SocialLinkGenerator;
27 use ThumbnailGenerator;
28
29 /**
30 * Droip element object
31 *
32 * @var array $element | element data.
33 */
34 private $element = array();
35 /**
36 * Droip all elements object
37 *
38 * @var array $elements | array of elements.
39 */
40 private $elements = array();
41 /**
42 * Droip all style blocks object
43 *
44 * @var array $style_blocks | array of style blocks.
45 */
46 private $style_blocks = array();
47 /**
48 * Droip all style blocks object
49 *
50 * @var array $style_blocks | array of style blocks.
51 */
52 private $attributes = array();
53 /**
54 * Droip all options object
55 *
56 * @var array $options | array of options.
57 */
58 private $options = array();
59 /**
60 * Droip generate child element function
61 *
62 * @var callable $generate_child_element | function.
63 */
64 private $generate_child_element = null; // function.
65 private $generate_element = null; // function.
66 /**
67 * Droip generate child element with new id function
68 *
69 * @var callable $generate_child_element_with_new_id | function.
70 */
71 private $generate_child_element_with_new_id = null; // function.
72 private $get_data_and_styles_from_root = null; // function.
73 /**
74 * Droip element properties
75 *
76 * @var array $properties | array of element properties.
77 */
78 private $properties = array();
79 /**
80 * LMS course id
81 *
82 * @var int $course_id | course id.
83 */
84 private $course_id = null;
85
86 /**
87 * Class constructor
88 *
89 * @param array $props array of element properties.
90 *
91 * @since 1.0.0
92 */
93 public function __construct( $props ) {
94 $this->element = $props['element'];
95 $this->elements = $props['elements'];
96 $this->style_blocks = $props['style_blocks'];
97 $this->attributes = $props['attributes'];
98 $this->options = $props['options'];
99 $this->generate_child_element = $props['generate_child_element'];
100 $this->generate_element = $props['generate_element'];
101 $this->generate_child_element_with_new_id = $props['generate_child_element_with_new_id'];
102 $this->get_data_and_styles_from_root = $props['get_data_and_styles_from_root'];
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 switch ( $this->element['name'] ) {
119 case TDE_APP_PREFIX . '-course-meta':
120 return $this->generate_course_meta_markup();
121 case TDE_APP_PREFIX . '-add-rating':
122 case TDE_APP_PREFIX . '-active-stars':
123 case TDE_APP_PREFIX . '-inactive-stars':
124 return $this->generate_add_rating_element();
125 case TDE_APP_PREFIX . '-material':
126 return $this->generate_material_markup();
127 case TDE_APP_PREFIX . '-action':
128 return $this->generate_action_markup();
129 case TDE_APP_PREFIX . '-price':
130 return $this->generate_price_markup();
131 case TDE_APP_PREFIX . '-price-value':
132 return $this->generate_price_value_markup();
133 case TDE_APP_PREFIX . '-social-profile-link':
134 return $this->generate_social_link_markup();
135 case TDE_APP_PREFIX . '-course-thumbnail':
136 return $this->generate_course_thumbnail_markup();
137
138 default:
139 return $this->generate_common_element();
140 }
141 }
142
143 /**
144 * Generate common element.
145 *
146 * @param bool $hide | false | true. | Hide element.
147 * @param bool $children_html | false | true. | Hide children.
148 * @return string
149 */
150 private function generate_common_element( $hide = false, $children_html = false, $extra_attributes = '' ) {
151 $tag = isset( $this->properties['tag'] ) ? $this->properties['tag'] : 'div';
152 $name = $this->element['name'];
153 if ( $hide ) {
154 $extra_attributes .= " data-element_hide='true'";
155 }
156 // $extra_attributes .= " data-ele_name='$name'";
157
158 $html = '';
159 if ( ! $children_html ) {
160 $children_html = $this->generate_child_elements();
161 }
162 $html = "<$tag $this->attributes $extra_attributes>$children_html</$tag>";
163 return $html;
164 }
165
166 /**
167 * Generate child elements.
168 *
169 * @return string
170 */
171 private function generate_child_elements() {
172 $html = '';
173 $child_count = isset( $this->element['children'] ) ? count( $this->element['children'] ) : 0;
174 for ( $i = 0; $i < $child_count; $i++ ) {
175 $html .= call_user_func( $this->generate_child_element, $this->element['children'][ $i ], $this->options );
176 }
177 return $html;
178 }
179
180 /**
181 * Generate child element by name.
182 *
183 * @return array $element | Element array.
184 */
185 private function group_elements_by_element_name() {
186 return array_reduce(
187 $this->element['children'],
188 function ( $carry, $item ) {
189 if ( isset( $this->elements[ $item ], $this->elements[ $item ]['name'] ) ) {
190 $carry[ $this->elements[ $item ]['name'] ] = $this->elements[ $item ];
191 }
192
193 return $carry;
194 },
195 array()
196 );
197 }
198
199 private function get_all_data_and_styles_from_element_id( $element_id ) {
200 $data_n_styles = array(
201 'blocks' => array(),
202 'styles' => array(),
203 'root' => $element_id,
204 );
205
206 call_user_func_array( $this->get_data_and_styles_from_root, array( $element_id, &$data_n_styles, &$this->elements, &$this->style_blocks ) );
207 return $data_n_styles;
208 }
209 }
210