PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 All 142 releases
← All changes | inc/TemplateHooks/CourseBuilder/Question/BuilderListQuestionsTemplate.php +388 -355 4.3.9 → 4.4.10 View file →
@@ -1,355 +1,388 @@
1 -<?php
2 -/**
3 - * Template hooks Tab Course in Course Builder.
4 - *
5 - * @since 4.3.0
6 - * @version 1.0.0
7 - */
8 -
9 -namespace LearnPress\TemplateHooks\CourseBuilder\Question;
10 -
11 -use LearnPress\CourseBuilder\CourseBuilder;
12 -use LearnPress\Helpers\Singleton;
13 -use LearnPress\Helpers\Template;
14 -use LearnPress\Models\PostModel;
15 -use LearnPress\Models\Question\QuestionPostModel;
16 -use LearnPress\Models\UserModel;
17 -use LearnPress\TemplateHooks\CourseBuilder\CourseBuilderTemplate;
18 -use LearnPress\TemplateHooks\CourseBuilder\Quiz\BuilderQuizTemplate;
19 -use LP_Question;
20 -use LP_Question_CURD;
21 -use LP_WP_Filesystem;
22 -use Throwable;
23 -use WP_Query;
24 -
25 -class BuilderListQuestionsTemplate {
26 - use Singleton;
27 -
28 - public function init() {
29 - add_action( 'learn-press/course-builder/list-questions/layout', [ $this, 'layout' ] );
30 - }
31 -
32 - public function layout( array $data = [] ) {
33 - $list_question = $this->tab_list_questions();
34 -
35 - $tab = [
36 - 'wrapper' => '<div class="cb-tab-question">',
37 - 'header' => $this->html_header(),
38 - 'filter_bar' => $this->html_filter_bar(),
39 - 'questions' => $list_question,
40 - 'wrapper_end' => '</div>',
41 - ];
42 -
43 - echo Template::combine_components( $tab );
44 - }
45 -
46 - public function html_header(): string {
47 - $section = [
48 - 'wrapper' => '<div class="cb-tab-header">',
49 - 'title' => sprintf( '<h2 class="lp-cb-tab__title">%s</h2>', __( 'Questions', 'learnpress' ) ),
50 - 'actions' => sprintf(
51 - '<div class="cb-tab-header-actions" style="display:flex;align-items:center;gap:8px;">%s</div>',
52 - CourseBuilderTemplate::instance()->html_btn_add_new()
53 - ),
54 - 'wrapper_end' => '</div>',
55 - ];
56 -
57 - return Template::combine_components( $section );
58 - }
59 -
60 - public function html_filter_bar(): string {
61 - $section = [
62 - 'wrapper_action' => '<div class="cb-tab-question__action">',
63 - 'search_question' => $this->html_search(),
64 - 'wrapper_action_end' => '</div>',
65 - ];
66 -
67 - return Template::combine_components( $section );
68 - }
69 -
70 - public function html_search() {
71 - $args = lp_archive_skeleton_get_args();
72 - $link_tab = CourseBuilder::get_tab_link( 'questions' );
73 -
74 - $search = [
75 - 'wrapper' => sprintf( '<form class="cb-search-form" method="get" action="%s">', $link_tab ),
76 - 'search_question' => '<button class="lp-button cb-search-btn" type="submit"> <i class="lp-icon-search"> </i></button>',
77 - 'input' => sprintf( '<input class="cb-input-search-question" type="search" placeholder="%s" name="c_search" value="%s">', __( 'Search', 'learnpress' ), $args['c_search'] ?? '' ),
78 - 'wrapper_end' => '</form>',
79 - ];
80 -
81 - return Template::combine_components( $search );
82 - }
83 -
84 - public function tab_list_questions(): string {
85 - $content = '';
86 -
87 - try {
88 - // Query questions of user
89 - $param = lp_archive_skeleton_get_args();
90 - $param['id_url'] = 'tab-list-questions';
91 -
92 - $query_args = array(
93 - 'post_type' => LP_QUESTION_CPT,
94 - 'post_status' => array( 'publish', 'private', 'draft', 'pending', 'trash' ),
95 - 'posts_per_page' => 12,
96 - 'paged' => $GLOBALS['wp_query']->get( 'paged', 1 ) ? $GLOBALS['wp_query']->get( 'paged', 1 ) : 1,
97 - 's' => ! empty( $param['c_search'] ) ? sanitize_text_field( $param['c_search'] ) : '',
98 -
99 - );
100 -
101 - $user_id = get_current_user_id();
102 - $userModel = UserModel::find( $user_id, true );
103 - if ( ! $userModel instanceof UserModel ) {
104 - return '';
105 - }
106 -
107 - if ( ! current_user_can( ADMIN_ROLE ) ) {
108 - $query_args['author'] = $user_id;
109 - }
110 -
111 - $query = new WP_Query();
112 - $result = $query->query( $query_args );
113 - $total_questions = $query->found_posts ?? 0;
114 -
115 - if ( $total_questions < 1 ) {
116 - unset( $query_args['paged'] );
117 - $count_query = new WP_Query();
118 - $count_query->query( $query_args );
119 - $total_questions = $count_query->found_posts;
120 - }
121 -
122 - $questions = array();
123 -
124 - if ( $query->have_posts() ) {
125 - while ( $query->have_posts() ) {
126 - $query->the_post();
127 -
128 - $question_model = QuestionPostModel::find( get_the_ID(), true );
129 - $questions[] = $question_model;
130 - }
131 - }
132 - wp_reset_postdata();
133 -
134 - if ( ! empty( $questions ) ) {
135 - $html_questions = $this->list_questions( $questions );
136 - } else {
137 - $html_questions = Template::print_message(
138 - sprintf( __( 'No questions found', 'learnpress' ) ),
139 - 'info',
140 - false
141 - );
142 - }
143 -
144 - $total_pages = \LP_Database::get_total_pages( $query_args['posts_per_page'], $total_questions );
145 - $link_tab = CourseBuilder::get_tab_link( 'questions' );
146 - $data_pagination = [
147 - 'paged' => max( 1, $query_args['paged'] ?? 1 ),
148 - 'total_pages' => $total_pages,
149 - 'base' => trailingslashit( $link_tab ) . 'page/%#%',
150 - 'format' => '',
151 - ];
152 -
153 - $pagination = Template::instance()->html_pagination( $data_pagination );
154 -
155 - $sections = apply_filters(
156 - 'learn-press/course-builder/questions/sections',
157 - [
158 - 'wrapper' => '<div class="courses-builder__question-tab learn-press-questions">',
159 - 'questions' => $html_questions,
160 - 'wrapper_end' => '</div>',
161 - 'pagination' => $pagination,
162 - ],
163 - $questions,
164 - $userModel
165 - );
166 -
167 - $content = Template::combine_components( $sections );
168 - } catch ( Throwable $e ) {
169 - error_log( __METHOD__ . ': ' . $e->getMessage() );
170 - }
171 -
172 - return $content;
173 - }
174 -
175 - /**
176 - * Display list questions.
177 - *
178 - * @param $questions
179 - *
180 - * @return string
181 - */
182 - public function list_questions( $questions ): string {
183 - $content = '';
184 -
185 - try {
186 - $html_list_question = '';
187 - foreach ( $questions as $question_model ) {
188 - $html_list_question .= self::render_question( $question_model );
189 - }
190 -
191 - $header = '<div class="cb-list-table-header">';
192 - $header .= sprintf( '<span>%s</span>', __( 'Question Title', 'learnpress' ) );
193 - $header .= sprintf( '<span>%s</span>', __( 'Quiz', 'learnpress' ) );
194 - $header .= sprintf( '<span>%s</span>', __( 'Create Date', 'learnpress' ) );
195 - $header .= sprintf( '<span>%s</span>', __( 'Status', 'learnpress' ) );
196 - $header .= sprintf( '<span>%s</span>', __( 'Preview', 'learnpress' ) );
197 - $header .= sprintf( '<span>%s</span>', __( 'Actions', 'learnpress' ) );
198 - $header .= '</div>';
199 -
200 - $sections = [
201 - 'header' => $header,
202 - 'wrapper' => '<ul class="cb-list-question">',
203 - 'list_question' => $html_list_question,
204 - 'wrapper_end' => '</ul>',
205 - ];
206 -
207 - $content = Template::combine_components( $sections );
208 - } catch ( Throwable $e ) {
209 - error_log( __METHOD__ . ': ' . $e->getMessage() );
210 - }
211 -
212 - return $content;
213 - }
214 -
215 - /**
216 - * Render question in course builder
217 - *
218 - * @param $question
219 - * @param array $settings
220 - *
221 - * @return string
222 - * @since 4.3.0
223 - * @version 1.0.0
224 - */
225 - public static function render_question( QuestionPostModel $question_model, array $settings = [] ): string {
226 - $edit_icon = LP_WP_Filesystem::get_icon_svg( 'ico-cb-edit.svg' );
227 - $more_actions_icon = LP_WP_Filesystem::get_icon_svg( 'ico-cb-more.svg' );
228 -
229 - $types = LP_Question::get_types();
230 - $type = get_post_meta( $question_model->get_id(), '_lp_type', true );
231 - $question_type = $types[ $type ] ?? '';
232 - $author = get_user_by( 'ID', $question_model->post_author );
233 - $author_name = $author && isset( $author->display_name ) ? $author->display_name : '--';
234 -
235 - $question = array(
236 - 'id' => $question_model->get_id(),
237 - 'title' => $question_model->post_title,
238 - 'status' => $question_model->post_status,
239 - 'quizzes' => BuilderEditQuestionTemplate::instance()->get_assigned_question( $question_model->get_id() ),
240 - 'author' => $author_name,
241 - 'type' => $question_type,
242 - 'date_modified' => lp_jwt_prepare_date_response( $question_model->post_date_gmt ),
243 - );
244 -
245 - try {
246 - $edit_link = BuilderQuestionTemplate::instance()->get_link_edit( $question['id'] );
247 -
248 - $html_quizzes = '';
249 - $assigned = '--';
250 - if ( ! empty( $question['quizzes'] ) ) {
251 - $quizzes = is_array( $question['quizzes'] ) && isset( $question['quizzes']['id'] )
252 - ? array( $question['quizzes'] )
253 - : $question['quizzes'];
254 -
255 - $quiz_htmls = array();
256 - foreach ( $quizzes as $quiz ) {
257 - $quiz_id = $quiz['id'] ?? 0;
258 - $quiz_title = $quiz['title'] ?? '';
259 -
260 - if ( $quiz_id && $quiz_title ) {
261 - $quiz_link = BuilderQuizTemplate::instance()->get_link_edit( $quiz_id );
262 - $quiz_htmls[] = sprintf(
263 - '<a href="%s">%s</a>',
264 - esc_url( $quiz_link ),
265 - esc_html( $quiz_title )
266 - );
267 - }
268 - }
269 -
270 - if ( ! empty( $quiz_htmls ) ) {
271 - $assigned = implode( ', ', $quiz_htmls );
272 - }
273 - }
274 -
275 - $html_quizzes = sprintf(
276 - '<div class="question-assigned-quizzes"><span class="label">%s:</span> %s</div>',
277 - __( 'Assigned', 'learnpress' ),
278 - $assigned
279 - );
280 -
281 - $status = $question_model->post_status ?? '';
282 - $html_content = apply_filters(
283 - 'learn-press/course-builder/list-questions/item/section/bottom',
284 - [
285 - 'title' => sprintf(
286 - '<h3 class="wap-question-title"><a href="%s">%s</a></h3>',
287 - esc_url( $edit_link ),
288 - esc_html( $question['title'] )
289 - ),
290 - 'quizzes' => $html_quizzes,
291 - 'date' => sprintf( '<span class="question__date">%s</span>', ! empty( $question['date_modified'] ) ? date_i18n( 'm/d/Y', strtotime( $question['date_modified'] ) ) : '--' ),
292 - 'question_status' => ! empty( $status ) ? sprintf( '<span class="question-status %1$s">%1$s</span>', $status ) : '<span></span>',
293 - 'type' => sprintf( '<span class="question__preview">%s</span>', $question['type'] ),
294 - ],
295 - $question,
296 - $settings
297 - );
298 -
299 - $html_action = apply_filters(
300 - 'learn-press/course-builder/list-questions/item/action',
301 - [
302 - 'wrapper' => '<div class="question-action">',
303 - 'edit' => $status !== PostModel::STATUS_TRASH ? sprintf(
304 - '<div class="question-action-editor"><a class="lp-button btn-edit-question question-edit-permalink" href="%s">%s %s</a></div>',
305 - esc_url( $edit_link ),
306 - $edit_icon,
307 - __( 'Edit', 'learnpress' )
308 - ) : '',
309 - 'action_expanded_button' => sprintf(
310 - '<button type="button" class="lp-button question-action-expanded">%s</button>',
311 - $more_actions_icon
312 - ),
313 - 'action_expanded_wrapper' => '<div style="display:none;" class="question-action-expanded__items">',
314 - 'action_expanded_duplicate' => sprintf( '<span class="lp-button question-action-expanded__duplicate">%s</span>', __( 'Duplicate', 'learnpress' ) ),
315 - 'action_expanded_publish' => sprintf( '<span class="lp-button question-action-expanded__publish">%s</span>', __( 'Publish', 'learnpress' ) ),
316 - 'action_expanded_trash' => sprintf(
317 - '<span class="lp-button question-action-expanded__trash"%s>%s</span>',
318 - $status === 'trash' ? ' style="display:none"' : '',
319 - __( 'Trash', 'learnpress' )
320 - ),
321 - 'action_expanded_restore' => sprintf(
322 - '<span class="lp-button question-action-expanded__restore"%s>%s</span>',
323 - $status !== 'trash' ? ' style="display:none"' : '',
324 - __( 'Restore', 'learnpress' )
325 - ),
326 - 'action_expanded_delete' => sprintf( '<span class="lp-button question-action-expanded__delete">%s</span>', __( 'Delete', 'learnpress' ) ),
327 - 'action_expanded_wrapper_end' => '</div>',
328 - 'wrapper_end' => '</div>',
329 - ],
330 - $question,
331 - $settings
332 - );
333 -
334 - $section = apply_filters(
335 - 'learn-press/course-builder/list-questions/item-li',
336 - [
337 - 'wrapper_li' => '<li class="question">',
338 - 'wrapper_div' => sprintf( '<div class="question-item" data-question-id="%s" data-status="%s">', $question['id'], $status ),
339 - 'question_info' => Template::combine_components( $html_content ),
340 - 'question_action' => Template::combine_components( $html_action ),
341 - 'wrapper_div_end' => '</div>',
342 - 'wrapper_li_end' => '</li>',
343 - ],
344 - $question,
345 - $settings
346 - );
347 -
348 - $html_item = Template::combine_components( $section );
349 - } catch ( Throwable $e ) {
350 - $html_item = $e->getMessage();
351 - }
352 -
353 - return $html_item;
354 - }
355 -}
1 +<?php
2 +/**
3 + * Template hooks Tab Course in Course Builder.
4 + *
5 + * @since 4.3.0
6 + * @version 1.0.0
7 + */
8 +
9 +namespace LearnPress\TemplateHooks\CourseBuilder\Question;
10 +
11 +use LearnPress\CourseBuilder\CourseBuilder;
12 +use LearnPress\Helpers\Singleton;
13 +use LearnPress\Helpers\Template;
14 +use LearnPress\Models\PostModel;
15 +use LearnPress\Models\Question\QuestionPostModel;
16 +use LearnPress\Models\UserModel;
17 +use LearnPress\TemplateHooks\CourseBuilder\CourseBuilderTemplate;
18 +use LearnPress\TemplateHooks\CourseBuilder\Quiz\BuilderQuizTemplate;
19 +use LearnPress\TemplateHooks\Table\TableListTemplate;
20 +use LP_Question;
21 +use LP_Question_CURD;
22 +use LP_WP_Filesystem;
23 +use Throwable;
24 +use WP_Query;
25 +
26 +class BuilderListQuestionsTemplate {
27 + use Singleton;
28 +
29 + public function init() {
30 + add_action( 'learn-press/course-builder/list-questions/layout', [ $this, 'layout' ] );
31 + }
32 +
33 + public function layout( array $data = [] ) {
34 + $list_question = $this->tab_list_questions();
35 +
36 + $tab = [
37 + 'wrapper' => '<div class="cb-tab-question">',
38 + 'header' => $this->html_header(),
39 + 'filter_bar' => $this->html_filter_bar(),
40 + 'questions' => $list_question,
41 + 'wrapper_end' => '</div>',
42 + ];
43 +
44 + echo Template::combine_components( $tab );
45 + }
46 +
47 + public function html_header(): string {
48 + $section = [
49 + 'wrapper' => '<div class="cb-tab-header">',
50 + 'title' => sprintf( '<h2 class="lp-cb-tab__title">%s</h2>', __( 'Questions', 'learnpress' ) ),
51 + 'actions' => sprintf(
52 + '<div class="cb-tab-header-actions" style="display:flex;align-items:center;gap:8px;">%s</div>',
53 + CourseBuilderTemplate::instance()->html_btn_add_new()
54 + ),
55 + 'wrapper_end' => '</div>',
56 + ];
57 +
58 + return Template::combine_components( $section );
59 + }
60 +
61 + public function html_filter_bar(): string {
62 + $section = [
63 + 'wrapper_action' => '<div class="cb-tab-question__action">',
64 + 'search_question' => $this->html_search(),
65 + 'wrapper_action_end' => '</div>',
66 + ];
67 +
68 + return Template::combine_components( $section );
69 + }
70 +
71 + public function html_search() {
72 + $args = lp_archive_skeleton_get_args();
73 + $link_tab = CourseBuilder::get_tab_link( 'questions' );
74 +
75 + $search = [
76 + 'wrapper' => sprintf( '<form class="cb-search-form" method="get" action="%s">', $link_tab ),
77 + 'search_question' => '<button class="lp-button cb-search-btn" type="submit"> <i class="lp-icon-search"> </i></button>',
78 + 'input' => sprintf( '<input class="cb-input-search-question" type="search" placeholder="%s" name="c_search" value="%s">', __( 'Search', 'learnpress' ), esc_attr( $args['c_search'] ?? '' ) ),
79 + 'wrapper_end' => '</form>',
80 + ];
81 +
82 + return Template::combine_components( $search );
83 + }
84 +
85 + public function tab_list_questions(): string {
86 + $content = '';
87 +
88 + try {
89 + // Query questions of user
90 + $param = lp_archive_skeleton_get_args();
91 + $param['id_url'] = 'tab-list-questions';
92 +
93 + $query_args = array(
94 + 'post_type' => LP_QUESTION_CPT,
95 + 'post_status' => array( 'publish', 'private', 'draft', 'pending', 'trash' ),
96 + 'posts_per_page' => 12,
97 + 'paged' => $GLOBALS['wp_query']->get( 'paged', 1 ) ? $GLOBALS['wp_query']->get( 'paged', 1 ) : 1,
98 + 's' => ! empty( $param['c_search'] ) ? sanitize_text_field( $param['c_search'] ) : '',
99 +
100 + );
101 +
102 + $user_id = get_current_user_id();
103 + $userModel = UserModel::find( $user_id, true );
104 + if ( ! $userModel instanceof UserModel ) {
105 + return '';
106 + }
107 +
108 + if ( ! current_user_can( ADMIN_ROLE ) ) {
109 + $query_args['author'] = $user_id;
110 + }
111 +
112 + $query = new WP_Query();
113 + $result = $query->query( $query_args );
114 + $total_questions = $query->found_posts ?? 0;
115 +
116 + if ( $total_questions < 1 ) {
117 + unset( $query_args['paged'] );
118 + $count_query = new WP_Query();
119 + $count_query->query( $query_args );
120 + $total_questions = $count_query->found_posts;
121 + }
122 +
123 + $questions = array();
124 +
125 + if ( $query->have_posts() ) {
126 + while ( $query->have_posts() ) {
127 + $query->the_post();
128 +
129 + $question_model = QuestionPostModel::find( get_the_ID(), true );
130 + $questions[] = $question_model;
131 + }
132 + }
133 + wp_reset_postdata();
134 +
135 + $html_questions = $this->list_questions( $questions );
136 +
137 + $total_pages = \LP_Database::get_total_pages( $query_args['posts_per_page'], $total_questions );
138 + $link_tab = CourseBuilder::get_tab_link( 'questions' );
139 + $data_pagination = [
140 + 'paged' => max( 1, $query_args['paged'] ?? 1 ),
141 + 'total_pages' => $total_pages,
142 + 'base' => trailingslashit( $link_tab ) . 'page/%#%',
143 + 'format' => '',
144 + ];
145 +
146 + $pagination = Template::instance()->html_pagination( $data_pagination );
147 +
148 + $sections = apply_filters(
149 + 'learn-press/course-builder/questions/sections',
150 + [
151 + 'wrapper' => '<div class="courses-builder__question-tab learn-press-questions">',
152 + 'questions' => $html_questions,
153 + 'wrapper_end' => '</div>',
154 + 'pagination' => $pagination,
155 + ],
156 + $questions,
157 + $userModel
158 + );
159 +
160 + $content = Template::combine_components( $sections );
161 + } catch ( Throwable $e ) {
162 + error_log( __METHOD__ . ': ' . $e->getMessage() );
163 + }
164 +
165 + return $content;
166 + }
167 +
168 + /**
169 + * Display list questions.
170 + *
171 + * @param $questions
172 + *
173 + * @return string
174 + */
175 + public function list_questions( $questions ): string {
176 + $content = '';
177 +
178 + try {
179 + $html_list_question = '';
180 +
181 + if ( empty( $questions ) ) {
182 + return Template::print_message(
183 + __( 'No questions found', 'learnpress' ),
184 + 'info',
185 + false
186 + );
187 + }
188 +
189 + foreach ( $questions as $question_model ) {
190 + $html_list_question .= self::render_question( $question_model );
191 + }
192 +
193 + $table_args = [
194 + 'class_table' => 'cb-list-table cb-list-question',
195 + 'header' => [
196 + 'title' => [
197 + 'class' => 'cb-col-title',
198 + 'title' => __( 'Question Title', 'learnpress' ),
199 + ],
200 + 'quizzes' => [
201 + 'class' => 'cb-col-assigned',
202 + 'title' => __( 'Quiz', 'learnpress' ),
203 + ],
204 + 'date' => [
205 + 'class' => 'cb-col-date',
206 + 'title' => __( 'Create Date', 'learnpress' ),
207 + ],
208 + 'status' => [
209 + 'class' => 'cb-col-status',
210 + 'title' => __( 'Status', 'learnpress' ),
211 + ],
212 + 'type' => [
213 + 'class' => 'cb-col-type',
214 + 'title' => __( 'Preview', 'learnpress' ),
215 + ],
216 + 'actions' => [
217 + 'class' => 'cb-col-actions',
218 + 'title' => __( 'Actions', 'learnpress' ),
219 + ],
220 + ],
221 + 'body' => [
222 + 'rows_html' => $html_list_question,
223 + ],
224 + ];
225 +
226 + $content = TableListTemplate::instance()->html_table( $table_args );
227 + } catch ( Throwable $e ) {
228 + error_log( __METHOD__ . ': ' . $e->getMessage() );
229 + }
230 +
231 + return $content;
232 + }
233 +
234 + /**
235 + * Render question in course builder
236 + *
237 + * @param $question
238 + * @param array $settings
239 + *
240 + * @return string
241 + * @since 4.3.0
242 + * @version 1.0.0
243 + */
244 + public static function render_question( QuestionPostModel $question_model, array $settings = [] ): string {
245 + $edit_icon = LP_WP_Filesystem::get_icon_svg( 'ico-cb-edit.svg' );
246 + $more_actions_icon = LP_WP_Filesystem::get_icon_svg( 'ico-cb-more.svg' );
247 +
248 + $types = LP_Question::get_types();
249 + $type = get_post_meta( $question_model->get_id(), '_lp_type', true );
250 + $question_type = $types[ $type ] ?? '';
251 + $author = get_user_by( 'ID', $question_model->post_author );
252 + $author_name = $author && isset( $author->display_name ) ? $author->display_name : '--';
253 +
254 + $question = array(
255 + 'id' => $question_model->get_id(),
256 + 'title' => $question_model->post_title,
257 + 'status' => $question_model->post_status,
258 + 'quizzes' => BuilderEditQuestionTemplate::instance()->get_assigned_question( $question_model->get_id() ),
259 + 'author' => $author_name,
260 + 'type' => $question_type,
261 + 'date_modified' => lp_jwt_prepare_date_response( $question_model->post_date_gmt ),
262 + );
263 +
264 + try {
265 + $edit_link = BuilderQuestionTemplate::instance()->get_link_edit( $question['id'] );
266 +
267 + $html_quizzes = '';
268 + $assigned = '--';
269 + if ( ! empty( $question['quizzes'] ) ) {
270 + $quizzes = is_array( $question['quizzes'] ) && isset( $question['quizzes']['id'] )
271 + ? array( $question['quizzes'] )
272 + : $question['quizzes'];
273 +
274 + $quiz_htmls = array();
275 + foreach ( $quizzes as $quiz ) {
276 + $quiz_id = $quiz['id'] ?? 0;
277 + $quiz_title = $quiz['title'] ?? '';
278 +
279 + if ( $quiz_id && $quiz_title ) {
280 + $quiz_link = BuilderQuizTemplate::instance()->get_link_edit( $quiz_id );
281 + $quiz_htmls[] = sprintf(
282 + '<a href="%s">%s</a>',
283 + esc_url( $quiz_link ),
284 + esc_html( $quiz_title )
285 + );
286 + }
287 + }
288 +
289 + if ( ! empty( $quiz_htmls ) ) {
290 + $assigned = implode( ', ', $quiz_htmls );
291 + }
292 + }
293 +
294 + $html_quizzes = sprintf(
295 + '<div class="question-assigned-quizzes"><span class="label">%s:</span> %s</div>',
296 + __( 'Assigned', 'learnpress' ),
297 + $assigned
298 + );
299 +
300 + $status = $question_model->post_status ?? '';
301 + $html_content = apply_filters(
302 + 'learn-press/course-builder/list-questions/item/section/bottom',
303 + [
304 + 'title' => sprintf(
305 + '<h3 class="wap-question-title"><a href="%s">%s</a></h3>',
306 + esc_url( $edit_link ),
307 + esc_html( $question['title'] )
308 + ),
309 + 'quizzes' => $html_quizzes,
310 + 'date' => sprintf( '<span class="question__date">%s</span>', ! empty( $question['date_modified'] ) ? date_i18n( 'm/d/Y', strtotime( $question['date_modified'] ) ) : '--' ),
311 + 'question_status' => ! empty( $status ) ? sprintf( '<span class="question-status %1$s">%1$s</span>', $status ) : '<span></span>',
312 + 'type' => sprintf( '<span class="question__preview">%s</span>', $question['type'] ),
313 + ],
314 + $question,
315 + $settings
316 + );
317 +
318 + $html_action = apply_filters(
319 + 'learn-press/course-builder/list-questions/item/action',
320 + [
321 + 'wrapper' => '<div class="question-action">',
322 + 'edit' => $status !== PostModel::STATUS_TRASH ? sprintf(
323 + '<div class="question-action-editor"><a class="lp-button btn-edit-question question-edit-permalink" href="%s">%s %s</a></div>',
324 + esc_url( $edit_link ),
325 + $edit_icon,
326 + __( 'Edit', 'learnpress' )
327 + ) : '',
328 + 'action_expanded_button' => sprintf(
329 + '<button type="button" class="lp-button question-action-expanded">%s</button>',
330 + $more_actions_icon
331 + ),
332 + 'action_expanded_wrapper' => '<div style="display:none;" class="question-action-expanded__items">',
333 + 'action_expanded_duplicate' => sprintf( '<span class="lp-button question-action-expanded__duplicate">%s</span>', __( 'Duplicate', 'learnpress' ) ),
334 + 'action_expanded_publish' => sprintf( '<span class="lp-button question-action-expanded__publish">%s</span>', __( 'Publish', 'learnpress' ) ),
335 + 'action_expanded_trash' => sprintf(
336 + '<span class="lp-button question-action-expanded__trash"%s>%s</span>',
337 + $status === 'trash' ? ' style="display:none"' : '',
338 + __( 'Trash', 'learnpress' )
339 + ),
340 + 'action_expanded_restore' => sprintf(
341 + '<span class="lp-button question-action-expanded__restore"%s>%s</span>',
342 + $status !== 'trash' ? ' style="display:none"' : '',
343 + __( 'Restore', 'learnpress' )
344 + ),
345 + 'action_expanded_delete' => sprintf( '<span class="lp-button question-action-expanded__delete">%s</span>', __( 'Delete', 'learnpress' ) ),
346 + 'action_expanded_wrapper_end' => '</div>',
347 + 'wrapper_end' => '</div>',
348 + ],
349 + $question,
350 + $settings
351 + );
352 +
353 + $cell_classes = [
354 + 'quizzes' => 'assigned',
355 + 'question_status' => 'status',
356 + ];
357 + $html_cells = [];
358 + foreach ( $html_content as $key => $html ) {
359 + $cell_class = $cell_classes[ $key ] ?? $key;
360 + $html_cells[ $key ] = sprintf(
361 + '<td class="cb-col-%s">%s</td>',
362 + esc_attr( sanitize_html_class( $cell_class ) ),
363 + $html
364 + );
365 + }
366 +
367 + $section = apply_filters(
368 + 'learn-press/course-builder/list-questions/item-li',
369 + [
370 + 'wrapper_li' => sprintf( '<tr class="question question-item" data-question-id="%s" data-status="%s">', $question['id'], $status ),
371 + 'wrapper_div' => '',
372 + 'question_info' => Template::combine_components( $html_cells ),
373 + 'question_action' => sprintf( '<td class="cb-col-actions">%s</td>', Template::combine_components( $html_action ) ),
374 + 'wrapper_div_end' => '',
375 + 'wrapper_li_end' => '</tr>',
376 + ],
377 + $question,
378 + $settings
379 + );
380 +
381 + $html_item = Template::combine_components( $section );
382 + } catch ( Throwable $e ) {
383 + $html_item = $e->getMessage();
384 + }
385 +
386 + return $html_item;
387 + }
388 +}