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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 / QnAGenerator.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
QnAGenerator.php
188 lines
1 <?php
2 /**
3 * QnA view generator
4 *
5 * @package tutor-droip-elements
6 */
7
8 namespace TutorLMSDroip\ElementGenerator;
9
10 use Droip\HelperFunctions as DroipHelperFunctions;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 /**
17 * Class QnAGenerator
18 * This class is used to define all QnA functions.
19 */
20 trait QnAGenerator {
21
22 /**
23 * Generate QnA Editor
24 *
25 * @return string
26 */
27 private function generate_qna_editor() {
28 $comment_id = 0;
29 if ( ! empty( $this->options ) && ! empty( $this->options['comment']->comment_ID ) ) {
30 $comment_id = $this->options['comment']->comment_ID;
31 }
32
33 ob_start();
34 wp_editor(
35 '',
36 'tutor_qna_reply_editor_' . $comment_id,
37 tutor_utils()->text_editor_config(
38 array(
39 'plugins' => 'codesample',
40 'tinymce' => array(
41 'toolbar1' => 'bold,italic,underline,link,unlink,removeformat,image,bullist,codesample',
42 'toolbar2' => '',
43 'toolbar3' => '',
44 ),
45 )
46 )
47 );
48 $editor_markup = ob_get_contents();
49 ob_end_clean();
50
51 $more_attrs_array = array(
52 'name' => $this->element['name'],
53 );
54
55 if ( ! empty( $this->options['comment'] ) ) {
56 $more_attrs_array['comment_parent'] = $this->options['comment']->comment_ID;
57 }
58
59 $more_attrs = '';
60
61 foreach ( $more_attrs_array as $key => $value ) {
62 $more_attrs .= "$key=\"$value\"";
63 }
64
65 return <<<EOL
66 <div $this->attributes $more_attrs>
67 $editor_markup
68 </div>
69 EOL;
70 }
71
72 /**
73 * Generate QnA Reply
74 *
75 * @return string
76 */
77 private function generate_qna_reply() {
78 $templates = $this->detectReplyTemplateByUser();
79
80 $non_current_user_reply_template_id = $templates[0];
81 $current_user_reply_template_id = $templates[1];
82
83 $child = '';
84
85 if ( (int) $this->options['comment']->user_id === get_current_user_ID() ) {
86 $child .= call_user_func(
87 $this->generate_child_element,
88 $current_user_reply_template_id,
89 $this->options
90 );
91 } else {
92 $child .= call_user_func(
93 $this->generate_child_element,
94 $non_current_user_reply_template_id,
95 $this->options
96 );
97 }
98
99 $name = $this->element['name'];
100
101 return <<<EOL
102 <div $this->attributes data-ele_name='$name'>
103 $child
104 </div>
105 EOL;
106 }
107
108 /**
109 * Generate QnA Reply Button
110 *
111 * @return string
112 */
113 private function generate_qna_reply_button() {
114 $child = '';
115
116 foreach ( $this->element['children'] as $child_id ) {
117 $child .= call_user_func(
118 $this->generate_child_element,
119 $child_id,
120 $this->options
121 );
122 }
123
124 $name = $this->element['name'];
125 $comment_parent = $this->options['comment']->comment_ID;
126 $commentItemId = $this->options['commentItemId'];
127
128 return <<<EOL
129 <a
130 $this->attributes
131 data-ele_name='$name'
132 data-comment_parent='$comment_parent'
133 data-comment_item_id='$commentItemId'
134 >
135 $child
136 </a>
137 EOL;
138 }
139
140 private function detectReplyTemplateByUser() {
141
142 return array(
143 $this->element['children'][0],
144 $this->element['children'][1],
145 );
146 }
147
148 /**
149 * Generate QnA Element
150 *
151 * @param object $comment (new comment)
152 * @param string $elementName (new element name to be generated, this could be comment-item or -qna-reply)
153 * @param array $collection_data (every collection data which comes with request)
154 * $collection_data = array(
155 * 'blocks' => array(),
156 * 'styles' => array(),
157 * );
158 *
159 * @return string as html preview element
160 */
161 public static function generateQnAElement( $comment, $elementName, $collection_data ) {
162 $blocks = $collection_data['blocks'];
163 $styles = $collection_data['styles'];
164
165 $element_id = '';
166
167 foreach ( $blocks as $key => $block ) {
168 if ( $elementName === $block['name'] ) {
169 $element_id = $key;
170 break;
171 }
172 }
173
174 $preview = DroipHelperFunctions::get_html_using_preview_script(
175 $blocks,
176 $styles,
177 $element_id,
178 null,
179 array(
180 'comment' => $comment,
181 'componentType' => 'comments',
182 )
183 );
184
185 return $preview;
186 }
187 }
188