order-list.php
266 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Order List Template. |
| 4 | * |
| 5 | * @package Tutor\Views |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 2.0.0 |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | use Tutor\Ecommerce\Ecommerce; |
| 16 | use Tutor\Ecommerce\OrderController; |
| 17 | use Tutor\Helpers\DateTimeHelper; |
| 18 | use TUTOR\Input; |
| 19 | use Tutor\Models\OrderModel; |
| 20 | |
| 21 | /** |
| 22 | * Determine active tab |
| 23 | */ |
| 24 | $active_tab = Input::get( 'data', 'all' ); |
| 25 | |
| 26 | $paged_filter = Input::get( 'paged', 1, Input::TYPE_INT ); |
| 27 | $limit = (int) tutor_utils()->get_option( 'pagination_per_page', 10 ); |
| 28 | $offset = ( $limit * $paged_filter ) - $limit; |
| 29 | |
| 30 | $order_controller = new OrderController( false ); |
| 31 | |
| 32 | $get_orders = $order_controller->get_orders( $limit, $offset ); |
| 33 | $orders = $get_orders['results']; |
| 34 | $total_items = $get_orders['total_count']; |
| 35 | |
| 36 | $add_course_url = esc_url( admin_url( 'admin.php?page=create-course' ) ); |
| 37 | $navbar_data = array( |
| 38 | 'page_title' => $order_controller->page_title, |
| 39 | 'tabs' => $order_controller->tabs_key_value(), |
| 40 | 'active' => $active_tab, |
| 41 | 'add_button' => false, |
| 42 | 'button_title' => __( 'Add New', 'tutor' ), |
| 43 | 'button_url' => $add_course_url, |
| 44 | ); |
| 45 | |
| 46 | |
| 47 | $payment_status_options = array( |
| 48 | array( |
| 49 | 'key' => '', |
| 50 | 'title' => __( 'Select', 'tutor' ), |
| 51 | ), |
| 52 | ); |
| 53 | |
| 54 | $payment_status = array_map( |
| 55 | function ( $val, $key ) { |
| 56 | return array( |
| 57 | 'key' => $key, |
| 58 | 'title' => $val, |
| 59 | ); |
| 60 | }, |
| 61 | OrderModel::get_payment_status(), |
| 62 | array_keys( OrderModel::get_payment_status() ) |
| 63 | ); |
| 64 | |
| 65 | $payment_status_options = array_merge( $payment_status_options, $payment_status ); |
| 66 | |
| 67 | /** |
| 68 | * Bulk action & filters |
| 69 | */ |
| 70 | $filters = array( |
| 71 | 'bulk_action' => true, |
| 72 | 'bulk_actions' => $order_controller->prepare_bulk_actions(), |
| 73 | 'ajax_action' => 'tutor_order_bulk_action', |
| 74 | 'filters' => array( |
| 75 | array( |
| 76 | 'label' => __( 'Status', 'tutor' ), |
| 77 | 'field_type' => 'select', |
| 78 | 'field_name' => 'data', |
| 79 | 'options' => $order_controller->tabs_key_value(), |
| 80 | 'searchable' => false, |
| 81 | 'value' => Input::get( 'data', '' ), |
| 82 | ), |
| 83 | array( |
| 84 | 'label' => __( 'Payment Status', 'tutor' ), |
| 85 | 'field_type' => 'select', |
| 86 | 'field_name' => 'payment-status', |
| 87 | 'options' => $payment_status_options, |
| 88 | 'show_label' => true, |
| 89 | 'value' => Input::get( 'payment-status', '' ), |
| 90 | ), |
| 91 | array( |
| 92 | 'label' => __( 'Date', 'tutor' ), |
| 93 | 'field_type' => 'date', |
| 94 | 'field_name' => 'date', |
| 95 | 'show_label' => true, |
| 96 | 'value' => Input::get( 'date', '' ), |
| 97 | ), |
| 98 | ), |
| 99 | ); |
| 100 | |
| 101 | ?> |
| 102 | |
| 103 | <div class="tutor-admin-wrap"> |
| 104 | <?php |
| 105 | /** |
| 106 | * Load Templates with data. |
| 107 | */ |
| 108 | $navbar_template = tutor()->path . 'views/elements/list-navbar.php'; |
| 109 | $filters_template = tutor()->path . 'views/elements/list-filters.php'; |
| 110 | tutor_load_template_from_custom_path( $navbar_template, $navbar_data ); |
| 111 | tutor_load_template_from_custom_path( $filters_template, $filters ); |
| 112 | ?> |
| 113 | <div class="tutor-admin-container tutor-admin-container-lg"> |
| 114 | <div class="tutor-mt-24 tutor-dashboard-list-table"> |
| 115 | <div class="tutor-table-responsive"> |
| 116 | <?php if ( is_array( $orders ) && count( $orders ) ) : ?> |
| 117 | <table class="tutor-table tutor-table-middle"> |
| 118 | <thead class="tutor-text-sm tutor-text-400"> |
| 119 | <tr> |
| 120 | <th> |
| 121 | <div class="tutor-d-flex"> |
| 122 | <input type="checkbox" id="tutor-bulk-checkbox-all" class="tutor-form-check-input" /> |
| 123 | </div> |
| 124 | </th> |
| 125 | <th class="tutor-table-rows-sorting"> |
| 126 | <?php esc_html_e( 'ID', 'tutor' ); ?> |
| 127 | <span class="a-to-z-sort-icon tutor-icon-ordering-a-z"></span> |
| 128 | </th> |
| 129 | <th> |
| 130 | <?php esc_html_e( 'Name', 'tutor' ); ?> |
| 131 | </th> |
| 132 | <th class="tutor-table-rows-sorting"> |
| 133 | <?php esc_html_e( 'Date', 'tutor' ); ?> |
| 134 | <span class="a-to-z-sort-icon tutor-icon-ordering-a-z"></span> |
| 135 | </th> |
| 136 | <th> |
| 137 | <?php esc_html_e( 'Method', 'tutor' ); ?> |
| 138 | </th> |
| 139 | <th> |
| 140 | <?php esc_html_e( 'Payment Status', 'tutor' ); ?> |
| 141 | </th> |
| 142 | <th> |
| 143 | <?php esc_html_e( 'Status', 'tutor' ); ?> |
| 144 | </th> |
| 145 | <th class="tutor-table-rows-sorting"> |
| 146 | <?php esc_html_e( 'Total', 'tutor' ); ?> |
| 147 | <span class="a-to-z-sort-icon tutor-icon-ordering-a-z"></span> |
| 148 | </th> |
| 149 | <th width="10%"> |
| 150 | <?php esc_html_e( 'Action', 'tutor' ); ?> |
| 151 | </th> |
| 152 | </tr> |
| 153 | </thead> |
| 154 | |
| 155 | <tbody> |
| 156 | |
| 157 | <?php |
| 158 | foreach ( $orders as $key => $order ) : //phpcs:ignore |
| 159 | $user_data = get_userdata( $order->user_id ); |
| 160 | ?> |
| 161 | <tr> |
| 162 | <td> |
| 163 | <div class="td-checkbox tutor-d-flex "> |
| 164 | <input type="checkbox" class="tutor-form-check-input tutor-bulk-checkbox" name="tutor-bulk-checkbox-all" value="<?php echo esc_attr( $order->id ); ?>" /> |
| 165 | </div> |
| 166 | </td> |
| 167 | |
| 168 | <td> |
| 169 | <a href="<?php echo esc_url( $order_controller->get_order_page_url() . '&action=edit&id=' . $order->id ); ?>" class="tutor-table-link tutor-fs-7"> |
| 170 | <?php echo esc_html( '#' . $order->id ); ?> |
| 171 | </a> |
| 172 | </td> |
| 173 | |
| 174 | <td> |
| 175 | <div class="tutor-d-flex tutor-align-center"> |
| 176 | <?php |
| 177 | echo wp_kses( |
| 178 | tutor_utils()->get_tutor_avatar( $user_data, 'sm' ), |
| 179 | tutor_utils()->allowed_avatar_tags() |
| 180 | ) |
| 181 | ?> |
| 182 | <div class="tutor-ml-12"> |
| 183 | <a target="_blank" class="tutor-fs-7 tutor-table-link" href="<?php echo esc_url( tutor_utils()->profile_url( $user_data, true ) ); ?>"> |
| 184 | <?php echo esc_html( $user_data ? $user_data->display_name : '' ); ?> |
| 185 | </a> |
| 186 | </div> |
| 187 | </div> |
| 188 | </td> |
| 189 | |
| 190 | <td> |
| 191 | <span class="tutor-fw-normal tutor-fs-7"> |
| 192 | <?php echo esc_attr( DateTimeHelper::get_gmt_to_user_timezone_date( $order->created_at_gmt ) ); ?> |
| 193 | </span> |
| 194 | </td> |
| 195 | |
| 196 | <td> |
| 197 | <div class="tutor-fs-7"> |
| 198 | <?php echo esc_html( Ecommerce::get_payment_method_label( $order->payment_method ?? '' ) ); ?> |
| 199 | <?php if ( ! empty( $order->transaction_id ) ) : ?> |
| 200 | <br> |
| 201 | <span class="tutor-fw-normal tutor-fs-8 tutor-color-muted"> |
| 202 | <?php |
| 203 | /* translators: %s is the transaction ID */ |
| 204 | echo esc_html( sprintf( __( 'Trx ID: %s', 'tutor' ), $order->transaction_id ) ); |
| 205 | ?> |
| 206 | </span> |
| 207 | <?php endif; ?> |
| 208 | </div> |
| 209 | </td> |
| 210 | |
| 211 | <td> |
| 212 | <?php echo wp_kses_post( tutor_utils()->translate_dynamic_text( $order->payment_status, true ) ); ?> |
| 213 | </td> |
| 214 | |
| 215 | <td> |
| 216 | <?php echo wp_kses_post( tutor_utils()->translate_dynamic_text( $order->order_status, true ) ); ?> |
| 217 | </td> |
| 218 | <td> |
| 219 | <?php echo wp_kses_post( tutor_utils()->tutor_price( $order->total_price ) ); ?> |
| 220 | </td> |
| 221 | <td> |
| 222 | <div class="tutor-d-flex tutor-align-center tutor-gap-1"> |
| 223 | <a href="<?php echo esc_url( $order_controller->get_order_page_url() . '&action=edit&id=' . $order->id ); ?>" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm"> |
| 224 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 225 | </a> |
| 226 | <?php do_action( 'tutor_after_order_edit_link', $order ); ?> |
| 227 | </div> |
| 228 | </td> |
| 229 | </tr> |
| 230 | <?php endforeach; ?> |
| 231 | </tbody> |
| 232 | </table> |
| 233 | <?php else : ?> |
| 234 | <?php tutils()->render_list_empty_state(); ?> |
| 235 | <?php endif; ?> |
| 236 | |
| 237 | <div class="tutor-admin-page-pagination-wrapper tutor-mt-32"> |
| 238 | <?php |
| 239 | /** |
| 240 | * Prepare pagination data & load template |
| 241 | */ |
| 242 | if ( $total_items > $limit ) { |
| 243 | $pagination_data = array( |
| 244 | 'total_items' => $total_items, |
| 245 | 'per_page' => $limit, |
| 246 | 'paged' => $paged_filter, |
| 247 | ); |
| 248 | $pagination_template = tutor()->path . 'views/elements/pagination.php'; |
| 249 | tutor_load_template_from_custom_path( $pagination_template, $pagination_data ); |
| 250 | } |
| 251 | ?> |
| 252 | </div> |
| 253 | </div> |
| 254 | <!-- end table responsive --> |
| 255 | </div> |
| 256 | </div> |
| 257 | </div> |
| 258 | |
| 259 | <?php |
| 260 | tutor_load_template_from_custom_path( |
| 261 | tutor()->path . 'views/elements/common-confirm-popup.php', |
| 262 | array( |
| 263 | 'message' => __( 'Deletion of the course will erase all its topics, lessons, quizzes, events, and other information. Please confirm your choice.', 'tutor' ), |
| 264 | ) |
| 265 | ); |
| 266 |