Skip to content

Commit fe9de66

Browse files
=4.2.8.7.5= ~ add comment
1 parent 530e34d commit fe9de66

1 file changed

Lines changed: 65 additions & 8 deletions

File tree

inc/TemplateHooks/Course/CourseMaterialTemplate.php

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Throwable;
1818
use Exception;
1919
class CourseMaterialTemplate {
20+
2021
public static function instance() {
2122
static $instance = null;
2223

@@ -31,6 +32,7 @@ protected function __construct() {
3132
add_action( 'learn-press/course-material/layout', array( $this, 'sections' ) );
3233
add_filter( 'lp/rest/ajax/allow_callback', array( $this, 'allow_callback' ) );
3334
}
35+
3436
/**
3537
* Allow callback for AJAX.
3638
*
@@ -44,6 +46,10 @@ public function allow_callback( array $callbacks ): array {
4446
return $callbacks;
4547
}
4648

49+
/**
50+
* Layout
51+
* @param array $data
52+
*/
4753
public function sections( array $data = array() ) {
4854
$html_wrapper = apply_filters(
4955
'learn-press/course-material/sections/wrapper',
@@ -86,7 +92,15 @@ public function sections( array $data = array() ) {
8692
);
8793
echo Template::combine_components( $section );
8894
}
89-
public static function render_material_items( $args ) {
95+
96+
/**
97+
* Render html
98+
*
99+
* @param array $settings
100+
*
101+
* @return stdClass { content: string_html }
102+
*/
103+
public static function render_material_items( $args ): stdClass {
90104
$content = new stdClass();
91105
try {
92106
$material_db = LP_Material_Files_DB::getInstance();
@@ -128,7 +142,12 @@ public static function render_material_items( $args ) {
128142
}
129143
return $content;
130144
}
131-
public static function table_header() {
145+
146+
/**
147+
* material table header
148+
* @return string
149+
*/
150+
public static function table_header(): string {
132151
$sections = array(
133152
'wrap' => '<thead>',
134153
'file-name' => sprintf( '<th class="lp-material-th-file-name">%s</th>', esc_html__( 'Name', 'learnpress' ) ),
@@ -139,7 +158,14 @@ public static function table_header() {
139158
);
140159
return Template::combine_components( $sections );
141160
}
142-
public static function material_item( $material, $current_item_id ) {
161+
162+
/**
163+
* row html
164+
* @param object $material
165+
* @param integer $current_item_id current item id ( course/lesson )
166+
* @return string
167+
*/
168+
public static function material_item( $material, $current_item_id ): string {
143169
$sections = array(
144170
'wrap' => '<tr class="lp-material-item">',
145171
'file-name' => self::html_file_name( $material, $current_item_id ),
@@ -150,7 +176,14 @@ public static function material_item( $material, $current_item_id ) {
150176
);
151177
return Template::combine_components( $sections );
152178
}
153-
public static function html_file_name( $material, $current_item_id ) {
179+
180+
/**
181+
* file name html
182+
* @param object $material
183+
* @param integer $current_item_id
184+
* @return string
185+
*/
186+
public static function html_file_name( $material, $current_item_id ): string {
154187
if ( get_post_type( $current_item_id ) == LP_COURSE_CPT && $material->item_type == LP_LESSON_CPT ) {
155188
$html_file_name = sprintf( esc_html( '%1$s ( %2$s )' ), $material->file_name, get_the_title( $material->item_id ) );
156189
} else {
@@ -159,10 +192,22 @@ public static function html_file_name( $material, $current_item_id ) {
159192
$content = sprintf( '<td class="lp-material-file-name">%s</td>', $html_file_name );
160193
return $content;
161194
}
162-
public static function html_file_type( $material ) {
195+
196+
/**
197+
* file type html
198+
* @param object $material
199+
* @return string
200+
*/
201+
public static function html_file_type( $material ): string {
163202
return sprintf( '<td class="lp-material-file-type">%s</td>', $material->file_type );
164203
}
165-
public static function html_file_size( $material ) {
204+
205+
/**
206+
* file size html
207+
* @param object $material
208+
* @return string
209+
*/
210+
public static function html_file_size( $material ): string {
166211
if ( $material->method == 'upload' ) {
167212
$file_size = filesize( wp_upload_dir()['basedir'] . $material->file_path );
168213
$file_size = ( $file_size / 1024 < 1024 ) ? round( $file_size / 1024, 2 ) . 'KB' : round( $file_size / 1024 / 1024, 2 ) . 'MB';
@@ -172,7 +217,13 @@ public static function html_file_size( $material ) {
172217
$content = sprintf( '<td class="lp-material-file-size">%s</td>', $file_size );
173218
return $content;
174219
}
175-
public static function html_file_link( $material ) {
220+
221+
/**
222+
* file url html
223+
* @param object $material
224+
* @return string
225+
*/
226+
public static function html_file_link( $material ): string {
176227
$file_url = $material->method == 'upload' ? wp_upload_dir()['baseurl'] . $material->file_path : $material->file_path;
177228
$enable_nofollow = LP_Settings::instance()->get_option( 'material_url_nofollow', 'yes' );
178229
$rel = '';
@@ -190,7 +241,13 @@ public static function html_file_link( $material ) {
190241
);
191242
return $content;
192243
}
193-
public static function html_loadmore_btn( $args ) {
244+
245+
/**
246+
* Load more button
247+
* @param array $args params...
248+
* @return string
249+
*/
250+
public static function html_loadmore_btn( $args ): string {
194251
return $args['paged'] < $args['total_pages'] ? sprintf( '<button class="button lp-button lp-loadmore-material">%s</button>', esc_html__( 'Load more', 'learnpress' ) ) : '';
195252
}
196253
}

0 commit comments

Comments
 (0)