| 1 |
<?php |
| 2 |
class Survey_Requests_List_Table extends WP_List_Table{ |
| 3 |
private $plugin_name; |
| 4 |
|
| 5 |
public function __construct($plugin_name) { |
| 6 |
$this->plugin_name = $plugin_name; |
| 7 |
parent::__construct( array( |
| 8 |
'singular' => __( 'Result', "survey-maker" ), |
| 9 |
'plural' => __( 'Results', "survey-maker" ), |
| 10 |
'ajax' => false |
| 11 |
) ); |
| 12 |
} |
| 13 |
|
| 14 |
public function display_tablenav( $which ) { |
| 15 |
?> |
| 16 |
<div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 17 |
|
| 18 |
<div class="alignleft actions"> |
| 19 |
<?php $this->bulk_actions( $which ); ?> |
| 20 |
</div> |
| 21 |
|
| 22 |
<?php |
| 23 |
$this->pagination( $which ); |
| 24 |
?> |
| 25 |
<br class="clear" /> |
| 26 |
</div> |
| 27 |
<?php |
| 28 |
} |
| 29 |
|
| 30 |
public function column_default( $item, $column_name ) { |
| 31 |
switch ( $column_name ) { |
| 32 |
case 'user_id': |
| 33 |
case 'survey_title': |
| 34 |
case 'request_date': |
| 35 |
case 'status': |
| 36 |
case 'approved': |
| 37 |
case 'id': |
| 38 |
return $item[ $column_name ]; |
| 39 |
break; |
| 40 |
default: |
| 41 |
return print_r( $item, true ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
function column_cb( $item ) { |
| 46 |
return ( |
| 47 |
'<input type="checkbox" >' |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
function column_survey_title() { |
| 52 |
return 'User\'s Survey'; |
| 53 |
} |
| 54 |
|
| 55 |
function column_user_id() { |
| 56 |
return "User"; |
| 57 |
} |
| 58 |
|
| 59 |
function column_approved() { |
| 60 |
return sprintf('<input type="button" class="button primary ays_survey_approve_button" value="%s"/>', __("Approve", "survey-maker") ); |
| 61 |
} |
| 62 |
|
| 63 |
function get_columns() { |
| 64 |
$columns = array( |
| 65 |
'cb' => '<input type="checkbox" />', |
| 66 |
'survey_title' => __( 'Survey Title', "survey-maker" ), |
| 67 |
'user_id' => __( 'User Name', "survey-maker" ), |
| 68 |
'request_date' => __( 'Request Date', "survey-maker" ), |
| 69 |
'status' => __( 'Status', "survey-maker" ), |
| 70 |
'approved' => __( 'Approved', "survey-maker" ), |
| 71 |
'id' => __( 'ID', "survey-maker" ), |
| 72 |
); |
| 73 |
|
| 74 |
return $columns; |
| 75 |
} |
| 76 |
|
| 77 |
public function get_bulk_actions() { |
| 78 |
$actions = array( |
| 79 |
'mark-as-approved' => __( 'Mark as approved', "survey-maker"), |
| 80 |
); |
| 81 |
|
| 82 |
return $actions; |
| 83 |
} |
| 84 |
|
| 85 |
public function prepare_items() { |
| 86 |
|
| 87 |
$per_page = 1; |
| 88 |
|
| 89 |
$columns = $this->get_columns(); |
| 90 |
$this->_column_headers = array($columns, array(), array()); |
| 91 |
|
| 92 |
$current_page = 1; |
| 93 |
$total_items = 1; |
| 94 |
|
| 95 |
$this->set_pagination_args( array( |
| 96 |
'total_items' => $total_items, |
| 97 |
'per_page' => $per_page |
| 98 |
) ); |
| 99 |
|
| 100 |
$requests = array( |
| 101 |
array( |
| 102 |
'id' => '1', |
| 103 |
'survey_id' => '0', |
| 104 |
'category_id' => '1', |
| 105 |
'user_id' => '1', |
| 106 |
'user_ip' => '::1', |
| 107 |
'survey_title' => 'Survey', |
| 108 |
'request_data' => '', |
| 109 |
'request_date' => '2023-10-25 08:27:40', |
| 110 |
'status' => 'Unpublished', |
| 111 |
'approved' => 'not-approved', |
| 112 |
'options' => '[]', |
| 113 |
) |
| 114 |
); |
| 115 |
|
| 116 |
$this->items = $requests; |
| 117 |
} |
| 118 |
} |
| 119 |
|