Ratings.php
1.56 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
<?php
namespace ACA\WC\Settings\User;
use AC;
/**
* @since 3.0
*/
class Ratings extends AC\Settings\Column
implements AC\Settings\FormatValue {
/**
* @var string
*/
private $rating_display;
protected function set_name() {
$this->name = 'user_ratings';
}
protected function define_options() {
return [
'rating_display' => 'total',
];
}
public function create_view() {
$select = $this->create_element( 'select' )
->set_options( $this->get_display_options() );
return new AC\View( [
'label' => __( 'Display', 'codepress-admin-columns' ),
'setting' => $select,
] );
}
protected function get_display_options() {
$options = [
'total' => __( 'Number of ratings', 'codepress-admin-columns' ),
'avg' => __( 'Average rating', 'codepress-admin-columns' ),
];
return $options;
}
/**
* @return string
*/
public function get_rating_display() {
return $this->rating_display;
}
/**
* @param string $rating_display
*/
public function set_rating_display( $rating_display ) {
$this->rating_display = $rating_display;
}
public function format( $value, $original_value ) {
switch ( $this->get_rating_display() ) {
case 'avg':
if ( $value ) {
$value = ac_helper()->html->tooltip( ac_helper()->html->stars( $value, 5 ), $value );
}
break;
default:
if ( $value ) {
$comments_url = add_query_arg( [ 'user_id' => $original_value, 'post_type' => 'product' ], admin_url( 'edit-comments.php' ) );
$value = ac_helper()->html->link( $comments_url, $value );
}
}
return $value;
}
}