GravityView
2.17
The best, easiest way to display Gravity Forms entries on your website.
includes
fields
class-gravityview-field-is-starred.php
Go to the documentation of this file.
1
<?php
2
/**
3
* @file class-gravityview-field-is-starred.php
4
* @package GravityView
5
* @subpackage includes\fields
6
*/
7
8
class
GravityView_Field_Is_Starred
extends
GravityView_Field
{
9
10
var
$name
=
'is_starred'
;
11
12
var
$is_searchable
=
true
;
13
14
var
$search_operators
= array(
'is'
,
'isnot'
);
15
16
var
$group
=
'meta'
;
17
18
var
$contexts
= array(
'single'
,
'multiple'
,
'export'
);
19
20
var
$icon
=
'dashicons-star-filled'
;
21
22
private
static
$has_star_field
=
false
;
23
24
/**
25
* GravityView_Field_Is_Starred constructor.
26
*/
27
public
function
__construct
() {
28
29
$this->label = esc_html__(
'Entry Star'
,
'gk-gravityview'
);
30
$this->default_search_label = __(
'Is Starred'
,
'gk-gravityview'
);
31
$this->
description
= esc_html__(
'Display the entry\'s "star" status.'
,
'gk-gravityview'
);
32
33
34
$this->
add_hooks
();
35
36
parent::__construct();
37
}
38
39
private
function
add_hooks
() {
40
/** @see \GV\Field::get_value_filters */
41
add_filter(
"gravityview/field/{$this->name}/output"
, array( $this,
'get_content'
), 4, 2 );
42
add_action(
'gravityview/template/after'
, array( $this,
'print_script'
), 10, 1 );
43
add_filter(
'gravityview_entry_default_fields'
, array( $this,
'add_default_field'
), 10, 3 );
44
}
45
46
/**
47
* Add this field to the default fields in the GV field picker
48
*
49
* @param array $entry_default_fields Array of fields shown by default
50
* @param string|array $form form_ID or form object
51
* @param string $zone Either 'single', 'directory', 'header', 'footer'
52
*
53
* @return array
54
*/
55
function
add_default_field
( $entry_default_fields = array(),
$form
= array(), $zone =
''
) {
56
57
if
(
'edit'
!== $zone ) {
58
$entry_default_fields[
$this->name
] = array(
59
'label'
=> $this->label,
60
'desc'
=> $this->
description
,
61
'type'
=> $this->name,
62
);
63
}
64
65
return
$entry_default_fields;
66
}
67
68
/**
69
* Show the star image
70
*
71
* @since 2.0
72
*
73
* @param string $output HTML value output
74
* @param \GV\Field_Template $template The field template being rendered
75
*
76
* @return string Image of the star
77
*/
78
public
function
get_content
(
$output
,
$template
) {
79
$entry
=
$template
->entry;
80
81
$star_url = GFCommon::get_base_url() .
'/images/star'
. intval(
$entry
[
'is_starred'
] ) .
'.png'
;
82
83
$entry_id =
''
;
84
85
if
(
GravityView_Roles_Capabilities::has_cap
(
'gravityview_edit_entries'
) ) {
86
$entry_id =
"data-entry-id='{$entry->ID}'"
;
87
}
88
89
// if( $show_as_star )
90
$output
=
'<img class="gv-star-image" '
.$entry_id.
' data-is_starred="'
. intval(
$entry
[
'is_starred'
] ) .
'" src="'
. esc_attr( $star_url ) .
'" />'
;
91
92
self::$has_star_field =
true
;
93
94
return
$output
;
95
}
96
97
/**
98
* Add JS to the bottom of the View if there is a star field and user has `gravityview_edit_entries` cap
99
*
100
* @param \GV\Template_Context $context The template context
101
* @since 2.0
102
*
103
* @return void
104
*/
105
public
function
print_script
( $context ) {
106
107
if
( ! self::$has_star_field ) {
108
return
;
109
}
110
111
if
( !
GravityView_Roles_Capabilities::has_cap
(
'gravityview_edit_entries'
) ) {
112
return
;
113
}
114
115
?>
116
<style>
117
.gv-star-image[data-entry-id] {
118
cursor: pointer;
119
}
120
</style>
121
<script>
122
jQuery( document ).ready(
function
( $ ) {
123
$(
'[class*=is_starred] img.gv-star-image[data-entry-id]'
).on(
'click'
,
function
() {
124
125
var is_starred = $(
this
).data(
'is_starred'
),
126
update = ( is_starred ? 0 : 1 ),
127
entry_id = $(
this
).data(
'entry-id'
),
128
$star = $( this );
129
130
$.ajax({
131
type:
"POST"
,
132
url:
"<?php echo esc_js( admin_url( 'admin-ajax.php' ) ); ?>"
,
133
data: {
134
action:
'rg_update_lead_property'
,
135
rg_update_lead_property:
'<?php echo wp_create_nonce( '
rg_update_lead_property
' ) ?>'
,
136
lead_id: entry_id,
137
name:
'is_starred'
,
138
value: update
139
}
140
})
141
.done(
function
() {
142
$star
143
.attr(
'src'
, $star.attr(
'src'
).replace(
"star"
+ is_starred +
".png"
,
"star"
+ update +
".png"
) )
144
.data(
'is_starred'
, update );
145
})
146
.fail(
function
() {
147
alert(<?php echo json_encode( __(
'There was an error updating the entry.'
,
'gk-gravityview'
) ); ?>);
148
});
149
});
150
});
151
</script>
152
<?php
153
}
154
155
}
156
157
new
GravityView_Field_Is_Starred
;
GravityView_Field
Modify field settings by extending this class.
Definition:
class-gravityview-field.php:11
GravityView_Field_Is_Starred\$name
$name
Definition:
class-gravityview-field-is-starred.php:10
$template
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
Definition:
views/list/list-body.php:13
GravityView_Roles_Capabilities\has_cap
static has_cap( $caps_to_check='', $object_id=null, $user_id=null)
Check whether the current user has a capability.
Definition:
class-gravityview-roles-capabilities.php:336
GravityView_Field_Is_Starred\__construct
__construct()
GravityView_Field_Is_Starred constructor.
Definition:
class-gravityview-field-is-starred.php:27
GravityView_Field_Is_Starred\add_default_field
add_default_field( $entry_default_fields=array(), $form=array(), $zone='')
Add this field to the default fields in the GV field picker.
Definition:
class-gravityview-field-is-starred.php:55
GravityView_Field_Is_Starred\print_script
print_script( $context)
Add JS to the bottom of the View if there is a star field and user has gravityview_edit_entries cap...
Definition:
class-gravityview-field-is-starred.php:105
GV\$form
if(gravityview() ->plugin->is_GF_25()) $form
Definition:
class-gv-settings-plugin.php:526
GravityView_Field_Is_Starred\$icon
$icon
Definition:
class-gravityview-field-is-starred.php:20
GravityView_Field_Is_Starred\$group
$group
Definition:
class-gravityview-field-is-starred.php:16
GravityView_Field_Is_Starred\$has_star_field
static $has_star_field
Definition:
class-gravityview-field-is-starred.php:22
GravityView_Field_Is_Starred\$is_searchable
$is_searchable
Definition:
class-gravityview-field-is-starred.php:12
GravityView_Field_Is_Starred
new GravityView_Field_Is_Starred
Definition:
class-gravityview-field-is-starred.php:157
GV\description
scale description p description
Definition:
class-gv-settings-plugin.php:405
GravityView_Field_Is_Starred\get_content
get_content( $output, $template)
Show the star image.
Definition:
class-gravityview-field-is-starred.php:78
GravityView_Field_Is_Starred\$search_operators
$search_operators
Definition:
class-gravityview-field-is-starred.php:14
GravityView_Field_Is_Starred\$contexts
$contexts
Definition:
class-gravityview-field-is-starred.php:18
GravityView_Field_Is_Starred\add_hooks
add_hooks()
Definition:
class-gravityview-field-is-starred.php:39
$output
$output
Definition:
edit_link.php:18
$entry
$entry
Definition:
notes.php:27
GravityView_Field_Is_Starred
Definition:
class-gravityview-field-is-starred.php:8