1 | <?php |
||
13 | class License_List_Table extends WP_List_Table { |
||
14 | /** |
||
15 | * Constructor, setup labels. |
||
16 | * |
||
17 | * @since 5.0 |
||
18 | */ |
||
19 | public function __construct() { |
||
20 | parent::__construct( array( |
||
21 | 'singular' => 'license_list', // Singular label |
||
22 | 'plural' => 'license_lists', // plural label, also this well be one of the table css class |
||
23 | 'ajax' => false, // We won't support Ajax for this table |
||
24 | ) |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Add extra markup in the toolbars before or after the list. |
||
30 | * |
||
31 | * @since 5.0 |
||
32 | * |
||
33 | * @param string $which Whether the markup should be after (bottom) or before (top) the list |
||
34 | */ |
||
35 | public function extra_tablenav( $which ) { |
||
36 | if ( 'top' == $which ) { |
||
37 | echo '<p>'; |
||
38 | _e( 'This is the list of addon license that are currently registered with the plugin.', 'bulk-delete' ); |
||
39 | echo '</p>'; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Define the list of columns that will be used in the table. |
||
45 | * |
||
46 | * @since 5.0 |
||
47 | * |
||
48 | * @return array The list of columns in the table |
||
49 | */ |
||
50 | public function get_columns() { |
||
51 | return array( |
||
52 | 'col_addon_name' => __( 'Addon Name', 'bulk-delete' ), |
||
53 | 'col_license' => __( 'License Code', 'bulk-delete' ), |
||
54 | 'col_license_validity' => __( 'Validity', 'bulk-delete' ), |
||
55 | 'col_expires' => __( 'Expires', 'bulk-delete' ), |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Defines columns that can be sorted. |
||
61 | * |
||
62 | * @since 5.0 |
||
63 | * |
||
64 | * @return array List of columns that can be sorted |
||
65 | */ |
||
66 | public function get_sortable_columns() { |
||
67 | return array( |
||
68 | 'col_addon_name' => array( 'addon_name', false ), |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Prepare the table. |
||
74 | * |
||
75 | * @since 5.0 |
||
76 | */ |
||
77 | public function prepare_items() { |
||
78 | $columns = $this->get_columns(); |
||
79 | $hidden = array(); |
||
80 | $sortable = $this->get_sortable_columns(); |
||
81 | |||
82 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
83 | |||
84 | $this->items = BD_License::get_licenses(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Display the col_addon_name column. |
||
89 | * |
||
90 | * @since 5.0 |
||
91 | * |
||
92 | * @param array $item Single row of data |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function column_col_addon_name( $item ) { |
||
97 | $validity = $item['validity']; |
||
98 | $action_label = __( 'Delete', 'bulk-delete' ); |
||
99 | $action_name = 'delete_license'; |
||
100 | |||
101 | if ( 'valid' == $validity ) { |
||
102 | $action_label = __( 'Deactivate', 'bulk-delete' ); |
||
103 | $action_name = 'deactivate_license'; |
||
104 | } |
||
105 | |||
106 | // Build row actions |
||
107 | $actions = array( |
||
108 | 'deactivate' => sprintf( '<a href="?page=%s&bd_action=%s&addon-code=%s&%s=%s">%s</a>', |
||
109 | $_REQUEST['page'], |
||
110 | $action_name, |
||
111 | $item['addon-code'], |
||
112 | "bd-{$action_name}-nonce", |
||
113 | wp_create_nonce( "bd-{$action_name}" ), |
||
114 | $action_label |
||
115 | ), |
||
116 | ); |
||
117 | |||
118 | // Return the title contents |
||
119 | return sprintf( '%1$s%2$s', |
||
120 | /*$1%s*/ $item['addon-name'], |
||
121 | /*$2%s*/ $this->row_actions( $actions ) |
||
122 | ); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Display the col_license column. |
||
127 | * |
||
128 | * @since 5.0 |
||
129 | * |
||
130 | * @param array $item Single row of data |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function column_col_license( $item ) { |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Display the col_license_validity column. |
||
140 | * |
||
141 | * @since 5.0 |
||
142 | * |
||
143 | * @param array $item Single row of data |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function column_col_license_validity( $item ) { |
||
148 | $validity = $item['validity']; |
||
149 | if ( 'valid' == $validity ) { |
||
150 | return '<span style="color:green;">' . $validity . '</span>'; |
||
151 | } else { |
||
152 | return '<span style="color:red;">' . $validity . '</span>'; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Display the col_expires column. |
||
158 | * |
||
159 | * @since 5.0 |
||
160 | * |
||
161 | * @param array $item Single row of data |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function column_col_expires( $item ) { |
||
170 | } |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Define the message that will be shown when the table is empty. |
||
175 | * |
||
176 | * @since 5.0 |
||
177 | */ |
||
178 | public function no_items() { |
||
180 | } |
||
181 | } |
||
182 |