Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Assets.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_Settings_Tabs.php
5 years ago
Course_Widget.php
5 years ago
Custom_Validation.php
5 years ago
Dashboard.php
4 years ago
Email.php
5 years ago
FormHandler.php
5 years ago
Frontend.php
5 years ago
Gutenberg.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
5 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
5 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
5 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
5 years ago
Withdraw.php
5 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Withdraw_Requests_List.php
220 lines
| 1 | <?php |
| 2 | namespace TUTOR; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | if (! class_exists('Tutor_List_Table')){ |
| 8 | include_once tutor()->path.'classes/Tutor_List_Table.php'; |
| 9 | } |
| 10 | |
| 11 | class Withdraw_Requests_List extends \Tutor_List_Table { |
| 12 | |
| 13 | const WITHDRAW_REQUEST_LIST_PAGE = 'tutor_withdraw_requests'; |
| 14 | |
| 15 | function __construct(){ |
| 16 | global $status, $page; |
| 17 | |
| 18 | //Set parent defaults |
| 19 | parent::__construct( array( |
| 20 | 'singular' => 'withdraw', //singular name of the listed records |
| 21 | 'plural' => 'withdraw', //plural name of the listed records |
| 22 | 'ajax' => false //does this table support ajax? |
| 23 | ) ); |
| 24 | |
| 25 | $this->process_bulk_action(); |
| 26 | } |
| 27 | |
| 28 | function column_default($item, $column_name){ |
| 29 | switch($column_name){ |
| 30 | case 'testing_col': |
| 31 | return $item->$column_name; |
| 32 | default: |
| 33 | return print_r($item,true); //Show the whole array for troubleshooting purposes |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | function column_cb($item){ |
| 38 | return sprintf( |
| 39 | '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
| 40 | /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("student") |
| 41 | /*$2%s*/ $item->withdraw_id //The value of the checkbox should be the record's id |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | function column_requested_user($item){ |
| 46 | echo "<p>{$item->user_name}</p><p>{$item->user_email}</p>"; |
| 47 | |
| 48 | $actions = array(); |
| 49 | switch ($item->status){ |
| 50 | case 'pending': |
| 51 | $actions['approved'] = sprintf('<a href="?page=%s&action=%s&withdraw_id=%s">'.__('Approve', 'tutor').'</a>',self::WITHDRAW_REQUEST_LIST_PAGE,'approved', |
| 52 | $item->withdraw_id); |
| 53 | $actions['rejected'] = sprintf('<a href="?page=%s&action=%s&withdraw_id=%s">'.__('Rejected', 'tutor').'</a>',self::WITHDRAW_REQUEST_LIST_PAGE,'rejected',$item->withdraw_id); |
| 54 | break; |
| 55 | case 'approved': |
| 56 | $actions['rejected'] = sprintf('<a href="?page=%s&action=%s&withdraw_id=%s">'.__('Rejected', 'tutor').'</a>',self::WITHDRAW_REQUEST_LIST_PAGE,'rejected',$item->withdraw_id); |
| 57 | break; |
| 58 | case 'rejected': |
| 59 | $actions['approved'] = sprintf('<a href="?page=%s&action=%s&withdraw_id=%s">'.__('Approve', 'tutor').'</a>',self::WITHDRAW_REQUEST_LIST_PAGE,'approved',$item->withdraw_id); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | $actions['delete'] = sprintf('<a href="?page=%s&action=%s&withdraw_id=%s" onclick="return confirm(\'' . __('Are you Sure? It can not be undone.', 'tutor') . '\')">' . __('Delete', 'tutor') . '</a>', self::WITHDRAW_REQUEST_LIST_PAGE, 'delete', $item->withdraw_id); |
| 64 | |
| 65 | return "<div class='withdraw-list-row-actions'>". $this->row_actions($actions)."</div>"; |
| 66 | } |
| 67 | function column_withdraw_method($item){ |
| 68 | if ($item->method_data){ |
| 69 | $data = maybe_unserialize($item->method_data); |
| 70 | |
| 71 | $method_name = tutor_utils()->avalue_dot('withdraw_method_name', $data); |
| 72 | |
| 73 | if ($method_name){ |
| 74 | echo "<p><strong>{$method_name}</strong></p>"; |
| 75 | } |
| 76 | |
| 77 | unset($data['withdraw_method_key'], $data['withdraw_method_name']); |
| 78 | |
| 79 | if (tutor_utils()->count($data)){ |
| 80 | foreach ($data as $method_field){ |
| 81 | $label = tutor_utils()->avalue_dot('label', $method_field); |
| 82 | $value = tutor_utils()->avalue_dot('value', $method_field); |
| 83 | echo "<p class='withdraw-method-data-row'> <span class='withdraw-method-label'>{$label}</span> : <span class='withdraw-method-value'>{$value}</span> </p>"; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | return ''; |
| 89 | } |
| 90 | |
| 91 | function column_requested_at($item){ |
| 92 | echo "<p>".date_i18n(get_option('date_format').' '.get_option('time_format'), strtotime($item->created_at))."</p>"; |
| 93 | } |
| 94 | |
| 95 | function column_amount($item){ |
| 96 | $available_status = array( |
| 97 | 'pending' => __( 'pending', 'tutor' ), |
| 98 | 'approved' => __( 'approved', 'tutor' ), |
| 99 | 'rejected' => __( 'rejected', 'tutor' ), |
| 100 | ); |
| 101 | echo "<p>".tutor_utils()->tutor_price($item->amount)."</p>"; |
| 102 | echo "<p><span class='withdraw-status withdraw-status-{$item->status}'>".__( isset( $available_status[$item->status] ) ? $available_status[$item->status] : $item->status, 'tutor' )."</span></p>"; |
| 103 | } |
| 104 | |
| 105 | function get_columns(){ |
| 106 | $columns = array( |
| 107 | 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
| 108 | 'requested_user' => __('Requested By', 'tutor'), |
| 109 | 'amount' => __('Amount', 'tutor'), |
| 110 | 'withdraw_method' => __('Withdrawal Method', 'tutor'), |
| 111 | 'requested_at' => __('Requested Time', 'tutor'), |
| 112 | ); |
| 113 | return $columns; |
| 114 | } |
| 115 | |
| 116 | function get_bulk_actions() { |
| 117 | $actions = array( |
| 118 | //'delete' => 'Delete' |
| 119 | ); |
| 120 | return $actions; |
| 121 | } |
| 122 | |
| 123 | function process_bulk_action() { |
| 124 | global $wpdb; |
| 125 | |
| 126 | $withdraw_page_url = admin_url('admin.php?page=' . self::WITHDRAW_REQUEST_LIST_PAGE); |
| 127 | $date = date("Y-m-d H:i:s", tutor_time()); |
| 128 | $redirect = false; |
| 129 | |
| 130 | //Detect when a bulk action is being triggered... |
| 131 | if( 'delete'===$this->current_action() ) { |
| 132 | $should_withdraw_delete = apply_filters('tutor_should_withdraw_delete', true); |
| 133 | |
| 134 | if ($should_withdraw_delete){ |
| 135 | $withdraw_id = (int) sanitize_text_field($_GET['withdraw_id']); |
| 136 | |
| 137 | do_action('tutor_before_delete_withdraw', $withdraw_id); |
| 138 | |
| 139 | $wpdb->delete($wpdb->prefix."tutor_withdraws",array('withdraw_id' =>$withdraw_id)); |
| 140 | |
| 141 | do_action('tutor_after_delete_withdraw', $withdraw_id); |
| 142 | |
| 143 | $redirect = true; |
| 144 | }else{ |
| 145 | wp_die('Items deleted (or they would be if we had items to delete)!'); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /** |
| 151 | * Reject Withdraw |
| 152 | */ |
| 153 | if( 'approved' === $this->current_action() ) { |
| 154 | $withdraw_id = (int) sanitize_text_field($_GET['withdraw_id']); |
| 155 | $withdraw = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}tutor_withdraws WHERE withdraw_id = %d ", $withdraw_id)); |
| 156 | if ( ! $withdraw || $withdraw->status === 'approved'){ |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | do_action('tutor_before_approved_withdraw', $withdraw_id); |
| 161 | |
| 162 | $wpdb->update($wpdb->prefix."tutor_withdraws", array('status' => 'approved', 'updated_at' => $date ), array('withdraw_id' =>$withdraw_id)); |
| 163 | |
| 164 | do_action('tutor_after_approved_withdraw', $withdraw_id); |
| 165 | |
| 166 | $redirect = true; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Rejected |
| 171 | */ |
| 172 | if( 'rejected' === $this->current_action() ) { |
| 173 | $withdraw_id = (int) sanitize_text_field($_GET['withdraw_id']); |
| 174 | $withdraw = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}tutor_withdraws WHERE withdraw_id = %d ", $withdraw_id)); |
| 175 | if ( ! $withdraw || $withdraw->status === 'rejected'){ |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | do_action('tutor_before_rejected_withdraw', $withdraw_id); |
| 180 | |
| 181 | $wpdb->update($wpdb->prefix."tutor_withdraws", array('status' => 'rejected', 'updated_at' => $date ), array('withdraw_id' =>$withdraw_id)); |
| 182 | |
| 183 | do_action('tutor_after_rejected_withdraw', $withdraw_id); |
| 184 | |
| 185 | $redirect = true; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | if ($redirect){ |
| 190 | die("<script>location.href='{$withdraw_page_url}';</script>"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | function prepare_items() { |
| 195 | $per_page = 20; |
| 196 | |
| 197 | $search_term = ''; |
| 198 | if (isset($_REQUEST['s'])){ |
| 199 | $search_term = sanitize_text_field($_REQUEST['s']); |
| 200 | } |
| 201 | |
| 202 | $columns = $this->get_columns(); |
| 203 | $hidden = array(); |
| 204 | |
| 205 | $this->_column_headers = array($columns, $hidden); |
| 206 | $current_page = $this->get_pagenum(); |
| 207 | |
| 208 | $start = ($current_page-1)*$per_page; |
| 209 | $withdraw_requests = tutor_utils()->get_withdrawals_history(null, compact('start', 'per_page', 'search_term') ); |
| 210 | $this->items = $withdraw_requests->results; |
| 211 | $count_result = $withdraw_requests->count; |
| 212 | |
| 213 | $this->set_pagination_args( array( |
| 214 | 'total_items' => $count_result, |
| 215 | 'per_page' => $per_page, |
| 216 | 'total_pages' => ceil($count_result/$per_page) |
| 217 | ) ); |
| 218 | } |
| 219 | } |
| 220 |