1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* API Keys Admin Table.
*
* @package LifterLMS_REST/Admin/Classes
*
* @since 1.0.0-beta.1
* @version 1.0.0-beta.1
*/
defined( 'ABSPATH' ) || exit;
/**
* LLMS_REST_Table_Webhooks class..
*
* @since 1.0.0-beta.1
* @since 1.0.0-beta.3 Output translated status instead of the database value; trim the delivery URL to 40 characters.
*/
class LLMS_REST_Table_Webhooks extends LLMS_Admin_Table {
/**
* Unique ID for the Table
*
* @var string
*/
protected $id = 'rest-webhooks';
/**
* If true will be a table with a larger font size
*
* @var bool
*/
protected $is_large = true;
/**
* Retrieve information for a the webhook title/description <td>
*
* @since 1.0.0-beta.1
*
* @param LLMS_REST_API_Key $webhook API Key object.
* @return string
*/
protected function get_name_cell( $webhook ) {
$html = esc_html( $webhook->get( 'name' ) );
$edit_link = esc_url( $webhook->get_edit_link() );
$html = '<a href="' . $edit_link . '">' . $html . '</a>';
$html .= '<div class="llms-rest-actions">';
$html .= '<small class="llms-action-icon">ID: ' . $webhook->get( 'id' ) . '</small> | ';
$html .= '<small><a class="llms-action-icon" href="' . $edit_link . '">' . __( 'View/Edit', 'lifterlms' ) . '</a></small> | ';
$html .= '<small><a class="llms-action-icon danger" href="' . esc_url( $webhook->get_delete_link() ) . '">' . __( 'Delete', 'lifterlms' ) . '</a></small>';
$html .= '</div>';
return $html;
}
/**
* Retrieve data for the columns
*
* @since 1.0.0-beta.1
* @since 1.0.0-beta.3 Output translated status instead of the database value; trim the delivery URL to 40 characters.
*
* @param string $key the column id / key.
* @param LLMS_REST_API_Key $webhook API key object.
* @return mixed
*/
public function get_data( $key, $webhook ) {
switch ( $key ) {
case 'name':
$value = $this->get_name_cell( $webhook );
break;
case 'status':
$statuses = LLMS_REST_API()->webhooks()->get_statuses();
$value = $webhook->get( $key );
$value = isset( $statuses[ $value ] ) ? $statuses[ $value ] : $value;
break;
case 'delivery_url':
$value = llms_trim_string( $webhook->get( $key ), 40 );
break;
default:
$value = $webhook->get( $key );
}
return $this->filter_get_data( $value, $key, $webhook );
}
/**
* Execute a query to retrieve results from the table
*
* @since 1.0.0-beta.1
*
* @param array $args Array of query args.
*
* @return void
*/
public function get_results( $args = array() ) {
$args = wp_parse_args( $args, $this->set_args() );
$query = new LLMS_REST_Webhooks_Query( $args );
$this->tbody_data = $query->get_webhooks();
}
/**
* Define the structure of arguments used to pass to the get_results method
*
* @since 1.0.0-beta.1
*
* @return array
*/
public function set_args() {
return array(
'per_page' => 999,
);
}
/**
* Define the structure of the table
*
* @since 1.0.0-beta.1
*
* @return array
*/
public function set_columns() {
return array(
'name' => __( 'Name', 'lifterlms' ),
'status' => __( 'Status', 'lifterlms' ),
'topic' => __( 'Topic', 'lifterlms' ),
'delivery_url' => __( 'Delivery URL', 'lifterlms' ),
);
}
}