PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.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 4.2.1 All 138 releases
learnpress / inc / Models / WPTables / CoursesTable.php

CoursesTable.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.8, at inc/Models/WPTables/CoursesTable.php

198 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LearnPress\Models\WPTables;
4
5 use LearnPress\Helpers\Template;
6 use LearnPress\Models\CourseModel;
7 use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
8 use LP_Abstract_Post_Type;
9 use LP_Helper;
10 use WP_List_Table;
11 use WP_Posts_List_Table;
12
13 /**
14 * LearnPress Courses Table class.
15 */
16
17 class CoursesTable extends WP_Posts_List_Table {
18 /**
19 * Get the table columns.
20 *
21 * @return array
22 */
23 public function get_columns() {
24 $columns = parent::get_columns();
25
26 unset( $columns['comments'] );
27
28 $columns = Template::insert_value_to_position_array(
29 $columns,
30 'before',
31 'title',
32 'thumbnail',
33 esc_html__( 'Thumbnail', 'learnpress' )
34 );
35
36 $columns = Template::insert_value_to_position_array(
37 $columns,
38 'after',
39 'author',
40 'curriculum',
41 esc_html__( 'Curriculum', 'learnpress' )
42 );
43
44 $columns = Template::insert_value_to_position_array(
45 $columns,
46 'after',
47 'curriculum',
48 'student',
49 esc_html__( 'Student', 'learnpress' )
50 );
51
52 $columns = Template::insert_value_to_position_array(
53 $columns,
54 'after',
55 'student',
56 'price',
57 esc_html__( 'Price', 'learnpress' )
58 );
59
60 return $columns;
61 }
62
63 /**
64 * Set columns can be sortable query
65 *
66 * @return array
67 */
68 public function get_sortable_columns() {
69 $sortable_columns = parent::get_sortable_columns();
70 $sortable_columns['author'] = array( 'author', 'asc' );
71 $sortable_columns['price'] = array( 'price', 'desc' );
72 return $sortable_columns;
73 }
74
75 /**
76 * Column thumbnail
77 * @use WP_List_Table::single_row_columns
78 * call_user_func( array( $this, 'column_' . $column_name ), $item )
79 *
80 * @param $post
81 *
82 * @return void
83 */
84 public function column_thumbnail( $post ) {
85 $courseModel = CourseModel::find( $post->ID, true );
86 if ( ! $courseModel ) {
87 return;
88 }
89
90 $singleCourseTemplate = SingleCourseTemplate::instance();
91 echo $singleCourseTemplate->html_image( $courseModel );
92 }
93
94 /**
95 * Column author
96 * @use WP_List_Table::single_row_columns
97 * call_user_func( array( $this, 'column_' . $column_name ), $item )
98 *
99 * @param $post
100 *
101 * @return void
102 */
103 public function column_author( $post ) {
104 LP_Abstract_Post_Type::column_author( $post );
105 }
106
107 /**
108 * Column Curriculum
109 * @use WP_List_Table::single_row_columns
110 * call_user_func( array( $this, 'column_' . $column_name ), $item )
111 *
112 * @param $post
113 *
114 * @return void
115 */
116 public function column_curriculum( $post ) {
117 $courseModel = CourseModel::find( $post->ID, true );
118 if ( ! $courseModel ) {
119 return;
120 }
121
122 $count_sections = $courseModel->get_total_sections();
123
124 $html_count_item = '';
125 $item_types_of_course = CourseModel::item_types_support();
126 foreach ( $item_types_of_course as $type ) {
127 $count_items = $courseModel->count_items( $type );
128 $html_count_item .= sprintf(
129 '<div><strong>%d</strong> %s</div>',
130 $count_items,
131 LP_Helper::get_i18n_string_plural( $count_items, $type, false )
132 );
133 }
134
135 $section = [
136 'count_section' => sprintf(
137 '<div>%d %s</div>',
138 $count_sections,
139 _n( 'Section', 'Sections', $count_sections, 'learnpress' )
140 ),
141 'count_item' => $html_count_item,
142 ];
143
144 echo Template::combine_components( $section );
145 }
146
147 /**
148 * Column count student
149 * @use WP_List_Table::single_row_columns
150 * call_user_func( array( $this, 'column_' . $column_name ), $item )
151 *
152 * @param $post
153 *
154 * @return void
155 */
156 public function column_student( $post ) {
157 $courseModel = CourseModel::find( $post->ID, true );
158 if ( ! $courseModel ) {
159 return;
160 }
161
162 // Count students
163 printf(
164 '<div class="lp-label-counter">%d</div>',
165 $courseModel->count_students()
166 );
167
168 // Button view list students
169 printf(
170 '<a type="button"
171 class="lp-button lp-btn-view-students"
172 data-course-id="%d"
173 data-course-title="%s">%s</a>',
174 $post->ID,
175 esc_attr( $post->post_title ),
176 esc_html__( 'View List', 'learnpress' )
177 );
178 }
179
180 /**
181 * Column count student
182 * @use WP_List_Table::single_row_columns
183 * call_user_func( array( $this, 'column_' . $column_name ), $item )
184 *
185 * @param $post
186 *
187 * @return void
188 */
189 public function column_price( $post ) {
190 $courseModel = CourseModel::find( $post->ID, true );
191 if ( ! $courseModel ) {
192 return;
193 }
194
195 echo SingleCourseTemplate::instance()->html_price( $courseModel );
196 }
197 }
198