wpml-tf-backend-feedback-list-view.php
7.37 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
use WPML\API\Sanitize;
/**
* Class WPML_TF_Backend_Feedback_List_View
*
* @author OnTheGoSystems
*/
class WPML_TF_Backend_Feedback_List_View {
const TEMPLATE_FOLDER = '/templates/translation-feedback/backend/';
const TEMPLATE_NAME = 'feedback-list-page.twig';
const ITEMS_PER_PAGE = 20;
/** @var IWPML_Template_Service $template_service */
private $template_service;
/** @var WPML_TF_Feedback_Query $feedback_query */
private $feedback_query;
/** @var WPML_Admin_Pagination $pagination */
private $pagination;
/** @var WPML_Admin_Table_Sort $table_sort */
private $table_sort;
/** @var WPML_TF_Feedback_Page_Filter $page_filter */
private $page_filter;
/**
* WPML_TF_Backend_Feedback_List_View constructor.
*
* @param IWPML_Template_Service $template_service
* @param WPML_TF_Feedback_Query $feedback_query
* @param WPML_Admin_Pagination $pagination
* @param WPML_Admin_Table_Sort $table_sort
* @param WPML_TF_Feedback_Page_Filter $page_filter
*/
public function __construct(
IWPML_Template_Service $template_service,
WPML_TF_Feedback_Query $feedback_query,
WPML_Admin_Pagination $pagination,
WPML_Admin_Table_Sort $table_sort,
WPML_TF_Feedback_Page_Filter $page_filter
) {
$this->template_service = $template_service;
$this->feedback_query = $feedback_query;
$this->pagination = $pagination;
$this->table_sort = $table_sort;
$this->page_filter = $page_filter;
}
/** @return string */
public function render_page() {
$args = $this->parse_request_args();
$feedback_collection = $this->feedback_query->get( $args );
$model = array(
'strings' => $this->get_strings(),
'columns' => $this->get_columns(),
'pagination' => $this->get_pagination( $args ),
'page_filters' => $this->get_page_filters(),
'admin_page_hook' => WPML_TF_Backend_Hooks::PAGE_HOOK,
'current_query' => $this->get_current_query(),
'nonce' => wp_create_nonce( WPML_TF_Backend_Hooks::PAGE_HOOK ),
'ajax_action' => WPML_TF_Backend_AJAX_Feedback_Edit_Hooks_Factory::AJAX_ACTION,
'ajax_nonce' => wp_create_nonce( WPML_TF_Backend_AJAX_Feedback_Edit_Hooks_Factory::AJAX_ACTION ),
'has_admin_capabilities' => current_user_can( 'manage_options' ),
'is_in_trash' => $this->feedback_query->is_in_trash(),
'feedback_collection' => $feedback_collection,
);
return $this->template_service->show( $model, self::TEMPLATE_NAME );
}
/** @return array */
private function parse_request_args() {
$args = array(
'paged' => 1,
'items_per_page' => self::ITEMS_PER_PAGE,
);
if ( isset( $_GET['paged'] ) ) {
$args['paged'] = filter_var( $_GET['paged'], FILTER_SANITIZE_NUMBER_INT );
}
if ( isset( $_GET['order'], $_GET['orderby'] ) ) {
$args['order'] = Sanitize::stringProp( 'order', $_GET );
$args['orderby'] = Sanitize::stringProp( 'orderby', $_GET );
}
if ( isset( $_GET['status'] ) ) {
$args['status'] = Sanitize::stringProp( 'status', $_GET );
} elseif ( isset( $_GET['language'] ) ) {
$args['language'] = Sanitize::stringProp( 'language', $_GET );
}
if ( isset( $_GET['post_id'] ) ) {
$args['post_id'] = filter_var( $_GET['post_id'], FILTER_SANITIZE_NUMBER_INT );
}
return $args;
}
/** @return array */
private function get_strings() {
$strings = array(
'page_title' => __( 'Translation Feedback', 'sitepress' ),
'page_subtitle' => __( 'Issues with translations', 'sitepress' ),
'table_header' => WPML_TF_Backend_Feedback_Row_View::get_columns_strings(),
'screen_reader' => array(
'select_all' => __( 'Select All', 'sitepress' ),
),
'pagination' => array(
'list_navigation' => __( 'Feedback list navigation', 'sitepress' ),
'first_page' => __( 'First page', 'sitepress' ),
'previous_page' => __( 'Previous page', 'sitepress' ),
'next_page' => __( 'Next page', 'sitepress' ),
'last_page' => __( 'Last page', 'sitepress' ),
'current_page' => __( 'Current page', 'sitepress' ),
'of' => __( 'of', 'sitepress' ),
),
'bulk_actions' => array(
'select' => __( 'Select bulk action', 'sitepress' ),
'apply_button' => __( 'Apply', 'sitepress' ),
'options' => array(
'-1' => __( 'Bulk Actions', 'sitepress' ),
'fixed' => __( 'Mark as fixed', 'sitepress' ),
'pending' => __( 'Mark as new', 'sitepress' ),
'trash' => __( 'Move to trash', 'sitepress' ),
),
),
'row_summary' => WPML_TF_Backend_Feedback_Row_View::get_summary_strings(),
'row_details' => WPML_TF_Backend_Feedback_Row_View::get_details_strings(),
'no_feedback' => __( 'No feedback found.', 'sitepress' ),
);
if ( $this->feedback_query->is_in_trash() ) {
$strings['bulk_actions']['options'] = array(
'-1' => __( 'Bulk Actions', 'sitepress' ),
'untrash' => __( 'Restore', 'sitepress' ),
'delete' => __( 'Delete permanently', 'sitepress' ),
);
}
return $strings;
}
/** @return array */
private function get_columns() {
$this->table_sort->set_primary_column( 'feedback' );
return array(
'feedback' => array(
'url' => $this->table_sort->get_column_url( 'feedback' ),
'classes' => $this->table_sort->get_column_classes( 'feedback' ),
),
'rating' => array(
'url' => $this->table_sort->get_column_url( 'rating' ),
'classes' => $this->table_sort->get_column_classes( 'rating' ),
),
'status' => array(
'url' => $this->table_sort->get_column_url( 'status' ),
'classes' => $this->table_sort->get_column_classes( 'status' ),
),
'document_url' => array(
'url' => $this->table_sort->get_column_url( 'document_title' ),
'classes' => $this->table_sort->get_column_classes( 'document_title' ),
),
'date' => array(
'url' => $this->table_sort->get_column_url( 'date' ),
'classes' => $this->table_sort->get_column_classes( 'date' ),
),
);
}
/**
* @param array $args
*
* @return array
*/
private function get_pagination( array $args ) {
$this->pagination->set_total_items( $this->feedback_query->get_filtered_items_count() );
$this->pagination->set_items_per_page( $args['items_per_page'] );
$this->pagination->set_current_page( $args['paged'] );
return array(
'first_page' => $this->pagination->get_first_page_url(),
'previous_page' => $this->pagination->get_previous_page_url(),
'next_page' => $this->pagination->get_next_page_url(),
'last_page' => $this->pagination->get_last_page_url(),
'current_page' => $this->pagination->get_current_page(),
'total_pages' => $this->pagination->get_total_pages(),
'total_items' => sprintf(
_n( '%s item', '%s items', $this->pagination->get_total_items() ),
$this->pagination->get_total_items()
),
);
}
/** @return array */
private function get_page_filters() {
$this->page_filter->populate_counters_and_labels();
return array(
'all_and_trash' => $this->page_filter->get_all_and_trash_data(),
'statuses' => $this->page_filter->get_statuses_data(),
'languages' => $this->page_filter->get_languages_data(),
);
}
/** @return array */
private function get_current_query() {
return array(
'filters' => $this->page_filter->get_current_filters(),
'sorters' => $this->table_sort->get_current_sorters(),
);
}
}