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
← All changes | inc/Models/WPTables/CoursesTable.php +83 -56 4.4.24.4.8 View file →
@@ -1,20 +1,27 @@
1 1 <?php
2 2
3 3 namespace LearnPress\Models\WPTables;
4 4
5 +use LearnPress\Helpers\Response;
5 6 use LearnPress\Helpers\Template;
6 7 use LearnPress\Models\CourseModel;
7 8 use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
8 9 use LP_Abstract_Post_Type;
9 10 use LP_Helper;
11 +use Throwable;
10 12 use WP_List_Table;
11 13 use WP_Posts_List_Table;
12 14
15 +defined( 'ABSPATH' ) || exit;
16 +
13 17 /**
14 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
15 23 */
16 -
17 24 class CoursesTable extends WP_Posts_List_Table {
18 25 /**
19 26 * Get the table columns.
20 27 *
@@ -81,15 +88,19 @@
81 88 *
82 89 * @return void
83 90 */
84 91 public function column_thumbnail( $post ) {
85 - $courseModel = CourseModel::find( $post->ID, true );
86 - if ( ! $courseModel ) {
87 - return;
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 );
88 102 }
89 -
90 - $singleCourseTemplate = SingleCourseTemplate::instance();
91 - echo $singleCourseTemplate->html_image( $courseModel );
92 103 }
93 104
94 105 /**
95 106 * Column author
@@ -100,9 +111,13 @@
100 111 *
101 112 * @return void
102 113 */
103 114 public function column_author( $post ) {
104 - LP_Abstract_Post_Type::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 + }
105 120 }
106 121
107 122 /**
108 123 * Column Curriculum
@@ -113,36 +128,40 @@
113 128 *
114 129 * @return void
115 130 */
116 131 public function column_curriculum( $post ) {
117 - $courseModel = CourseModel::find( $post->ID, true );
118 - if ( ! $courseModel ) {
119 - return;
120 - }
132 + try {
133 + $courseModel = CourseModel::find( $post->ID, true );
134 + if ( ! $courseModel ) {
135 + return;
136 + }
121 137
122 - $count_sections = $courseModel->get_total_sections();
138 + $count_sections = $courseModel->get_total_sections();
123 139
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 - }
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 + }
134 150
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 - ];
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 + ];
143 159
144 - echo Template::combine_components( $section );
160 + echo Template::combine_components( $section );
161 + } catch ( Throwable $e ) {
162 + Template::print_message( $e->getMessage(), Response::STATUS_ERROR );
163 + }
145 164 }
146 165
147 166 /**
148 167 * Column count student
@@ -153,29 +172,33 @@
153 172 *
154 173 * @return void
155 174 */
156 175 public function column_student( $post ) {
157 - $courseModel = CourseModel::find( $post->ID, true );
158 - if ( ! $courseModel ) {
159 - return;
160 - }
176 + try {
177 + $courseModel = CourseModel::find( $post->ID, true );
178 + if ( ! $courseModel ) {
179 + return;
180 + }
161 181
162 - // Count students
163 - printf(
164 - '<div class="lp-label-counter">%d</div>',
165 - $courseModel->count_students()
166 - );
182 + // Count students
183 + printf(
184 + '<div class="lp-label-counter">%d</div>',
185 + $courseModel->count_students()
186 + );
167 187
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 - );
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 + }
178 201 }
179 202
180 203 /**
181 204 * Column count student
@@ -186,12 +209,16 @@
186 209 *
187 210 * @return void
188 211 */
189 212 public function column_price( $post ) {
190 - $courseModel = CourseModel::find( $post->ID, true );
191 - if ( ! $courseModel ) {
192 - return;
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 );
193 222 }
194 -
195 - echo SingleCourseTemplate::instance()->html_price( $courseModel );
196 223 }
197 224 }