PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / TemplateHooks / Table / TableListTemplate.php

TableListTemplate.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at inc/TemplateHooks/Table/TableListTemplate.php

179 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class ProfileQuizzesTemplate.
4 *
5 * @since 4.2.8.2
6 * @version 1.0.0
7 */
8
9 namespace LearnPress\TemplateHooks\Table;
10
11 use LearnPress\Helpers\Singleton;
12 use LearnPress\Helpers\Template;
13
14
15 class TableListTemplate {
16 use Singleton;
17
18 public function init(): void {}
19
20 /**
21 * Render the HTML table.
22 *
23 * @param array $data
24 *
25 * @return string
26 */
27 public function html_table( array $data = [] ): string {
28 $class_tb = $data['class_table'] ?? '';
29 $section = [
30 'wrap' => '<div class="lp-table-wrap">',
31 'table' => sprintf(
32 '<table class="lp-list-table %s">',
33 esc_attr( $class_tb )
34 ),
35 'header' => $this->html_header( $data['header'] ?? [] ),
36 'body' => $this->html_body( $data['body'] ?? [] ),
37 'footer' => $this->html_footer( $data['footer'] ?? '' ),
38 'table-end' => '</table>',
39 'wrap-end' => '</div>',
40 ];
41
42 return Template::combine_components( $section );
43 }
44
45 /**
46 * Render the HTML table header.
47 *
48 * @param array $data
49 *
50 * @return string
51 */
52 public function html_header( array $data = [] ): string {
53 $html_th = '';
54
55 foreach ( $data as $item ) {
56 $html_th .= sprintf(
57 '<th class="%s">%s</th>',
58 esc_attr( $item['class'] ?? '' ),
59 wp_kses_post( $item['title'] ?? '' )
60 );
61 }
62
63 $section = [
64 'wrapper' => '<thead>',
65 'tr' => '<tr>',
66 'ths' => $html_th,
67 'tr_end' => '</tr>',
68 'wrapper_end' => '</thead>',
69 ];
70
71 return Template::combine_components( $section );
72 }
73
74 /**
75 * Render the HTML table body.
76 *
77 * @param array $data
78 *
79 * @return string
80 */
81 public function html_body( array $data = [] ): string {
82 $html_tr = '';
83
84 // Allow callers to pass fully prepared rows HTML.
85 if ( isset( $data['rows_html'] ) && is_string( $data['rows_html'] ) ) {
86 $html_tr = $data['rows_html'];
87 } else {
88 foreach ( $data as $item_tr ) {
89 $html_tr .= '<tr>';
90 foreach ( $item_tr as $item_td ) {
91 $html_td = sprintf(
92 '<td>%s</td>',
93 wp_kses_post( $item_td )
94 );
95 $html_tr .= $html_td;
96 }
97 $html_tr .= '</tr>';
98 }
99 }
100
101 $section = [
102 'wrapper' => '<tbody>',
103 'trs' => $html_tr,
104 'wrapper_end' => '</tbody>',
105 ];
106
107 return Template::combine_components( $section );
108 }
109
110 /**
111 * Render the HTML table footer.
112 *
113 * @param string $footer_html
114 *
115 * @return string
116 */
117 public function html_footer( string $footer_html = '' ): string {
118 if ( '' === trim( $footer_html ) ) {
119 return '';
120 }
121
122 $html_td = sprintf(
123 '<td colspan="10">%s</td>',
124 wp_kses_post( $footer_html )
125 );
126
127 $section = [
128 'wrapper' => '<tfoot>',
129 'tr' => '<tr>',
130 'tds' => $html_td,
131 'tr_end' => '</tr>',
132 'wrapper_end' => '</tfoot>',
133 ];
134
135 return Template::combine_components( $section );
136 }
137
138 /**
139 * Render the HTML info page query.
140 *
141 * @param array $data
142 *
143 * @return string
144 */
145 public function html_page_result( array $data = [] ): string {
146 $total_rows = $data['total_rows'] ?? 0;
147 $paged = $data['paged'] ?? 1;
148 $per_page = $data['per_page'] ?? 1;
149 $item_name = $data['item_name'] ?? _n( 'item', 'items', $total_rows, 'learnpress' );
150
151 $from = ( $paged - 1 ) * $per_page + 1;
152 $to = $from + $per_page - 1;
153 $to = min( $to, $total_rows );
154 if ( $total_rows < 1 ) {
155 $from = 0;
156 }
157
158 $format = __( 'Displaying {{from}} to {{to}} of {{total}} {{item_name}}.', 'learnpress' );
159 $format = apply_filters(
160 'learnpress/table/list-page-result',
161 $format,
162 $data
163 );
164
165 $output = str_replace(
166 array( '{{from}}', '{{to}}', '{{total}}', '{{item_name}}' ),
167 array(
168 $from,
169 $to,
170 $total_rows,
171 $item_name,
172 ),
173 $format
174 );
175
176 return wp_kses_post( $output );
177 }
178 }
179