| @@ -1,197 +1,224 @@ | ||
| 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 | -} | |
| 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 | +} | |