| 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\Course; |
| 10 |
|
| 11 |
use Exception; |
| 12 |
use LearnPress\CourseBuilder\CourseBuilder; |
| 13 |
use LearnPress\Helpers\Singleton; |
| 14 |
|
| 15 |
class BuilderCourseTemplate { |
| 16 |
use Singleton; |
| 17 |
|
| 18 |
public function init() {} |
| 19 |
|
| 20 |
/** |
| 21 |
* Check query var to switch layout. |
| 22 |
* |
| 23 |
* @param array $data |
| 24 |
* |
| 25 |
* @since 4.3.6 |
| 26 |
* @version 1.0.1 |
| 27 |
* @return void |
| 28 |
* @throws Exception |
| 29 |
*/ |
| 30 |
public function layout( array $data = [] ): string { |
| 31 |
// Check to switch layout. |
| 32 |
$item_id = CourseBuilder::get_item_id(); |
| 33 |
$data['item_id'] = $item_id; |
| 34 |
$html = ''; |
| 35 |
|
| 36 |
if ( ! empty( $item_id ) ) { |
| 37 |
// Show edit course |
| 38 |
$html = BuilderEditCourseTemplate::instance()->layout( $data ); |
| 39 |
} else { |
| 40 |
// Show list courses |
| 41 |
$html = BuilderListCoursesTemplate::instance()->layout( $data ); |
| 42 |
} |
| 43 |
|
| 44 |
return $html; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_link_edit( $course_id = 0 ) { |
| 48 |
if ( ! $course_id ) { |
| 49 |
return ''; |
| 50 |
} |
| 51 |
|
| 52 |
$section = CourseBuilder::get_current_section( '', 'courses' ); |
| 53 |
$link_tab = CourseBuilder::get_tab_link( 'courses' ); |
| 54 |
$link = $link_tab . $course_id . '/' . $section; |
| 55 |
|
| 56 |
return $link; |
| 57 |
} |
| 58 |
} |
| 59 |
|