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