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 / Models / WPTables / CoursesTable.php

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

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