Newer
Older
/**
* @file
* Installation file for fivestar module.
*/
function fivestar_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE 'fivestar_%'");
}
/**
* hook_field_schema().
Nate Lampton
committed
*/
function fivestar_field_schema() {
return array(
'columns' => array(
'rating' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'sortable' => TRUE
),
'target' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE
),
),
);
}
James Elliott
committed
/**
* Fixes the axis value stored for fivestar fields
*/
Eric J. Duran
committed
function fivestar_update_7201() {
James Elliott
committed
$fields = field_read_fields(array('module' => 'fivestar'));
$tags_numeric = array_values(fivestar_get_tags());
foreach($fields as $field) {
if (is_numeric($field['settings']['axis'])) {
$field['settings']['axis'] = $tags_numeric[$field['settings']['axis']];
}
}
}
/**
* Moves the field settings to field instance settings
*/
function fivestar_update_7202() {
$fields = field_read_fields(array('module' => 'fivestar'));
foreach($fields as $field) {
$instances = field_read_instances(array('field_name' => $field['field_name']));
foreach($instances as $instance) {
$instance['settings'] = $field['settings'];
field_update_instance($instance);
}
}
}
James Elliott
committed
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
/**
* Convert all existing fivestar/node_type settings into fields with exposed fivestar formatters
*/
function fivestar_update_7203() {
// Gather the node types
$query = db_select('node_type', 'n');
$query->addField('n', 'type');
$result = $query->execute();
$types = $result->fetchCol();
// Gather the tags. In the case that fivestar_get_tags() is ever removed from
// the module, this update still needs to run.
$tags_txt = variable_get('fivestar_tags', 'vote');
$tags_exploded = explode(',', $tags_txt);
$tags = array();
$got_vote = false;
foreach ($tags_exploded as $tag) {
$tag_trimmed = trim($tag);
if ($tag_trimmed) {
$tags[] = $tag_trimmed;
if ($tag_trimmed == 'vote') {
$got_vote = true;
}
}
}
if (!$got_vote) {
$tags[] = 'vote';
}
$tags;
foreach($tags as $tag) {
$suffix = '';
foreach($types as $type) {
$var_suffix = $type . ($tag == 'vote' ? '' : '_' . $tag);
$settings = array(
'stars' => variable_get('fivestar_stars_' . $var_suffix, 6),
'allow_clear' => variable_get('fivestar_unvote_' . $var_suffix, 0),
'feedback_enable' => variable_get('fivestar_feedback_'. $var_suffix, 1),
'style' => variable_get('fivestar_style_' . $var_suffix, 'average'),
'text' => variable_get('fivestar_text_' . $var_suffix, 'dual'),
);
if (variable_get('fivestar_' . $var_suffix, FALSE)) {
// Check to see if a field for this tag exists and create one if needed
$field_name = 'field_' . $tag;
$field = field_read_field($field_name . $suffix, array('include_deleted' => TRUE));
$i = 0;
while(!empty($field) && $field['type'] != 'fivestar') {
$suffix = '_' . $i;
$field = field_read_field($field_name . $suffix, array('include_deleted' => TRUE));
$i++;
}
if (empty($field)) {
$field_values = array(
'field_name' => $field_name . $suffix,
'type' => 'fivestar',
'settings' => array(
'axis' => $tag,
),
);
$field = field_create_field($field_values);
}
// Create an instance of the field in this bundle
$instance = field_read_instance('node', $field['field_name'], $type, array('include_deleted' => TRUE));
if (empty($instance)) {
$settings['allow_clear'] = $settings['unvote_enable'];
$settings['style'] = $settings['star_display'];
$settings['text'] = $settings['text_display'];
$instance_info = array(
'field_name' => $field['field_name'],
'entity_type' => 'node',
'bundle' => $type,
'widget' => array(
'type' => 'stars',
),
'display' => array(
'default' => array(
'type' => 'fivestar_formatter_exposed_stars',
'settings' => $settings,
),
),
'settings' => array(
'stars' => $settings['stars'],
'target' => 'self',
),
);
if (variable_get('fivestar_position_teaser_' . $var_suffix, 'hidden') != 'hidden') {
$instance_info['display']['teaser'] = array(
'type' => 'fivestar_formatter_exposed_stars',
'settings' => $settings,
);
}
field_create_instance($instance_info);
}
}
}
}
// Rebuild the menu to remove the node type tag form paths
menu_rebuild();
_field_info_collate_fields(TRUE);
}
Eric J. Duran
committed
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
/**
* Preserve settings from fivestar_formatter_exposed_stars and convert to
* fivestar_formatter_default.
*/
function fivestar_update_7204() {
$fields = field_read_fields(array('type' => 'fivestar'));
foreach($fields as $field) {
// Iterate through the instances of the field.
$instances = field_read_instances(array('field_name' => $field['field_name']));
foreach($instances as $instance) {
// The default should be to not allow clearing.
$instance['settings']['allow_clear'] = FALSE;
// Check each of the displays on the field instance an convert the formatter
// from fivestar_formatter_exposed_stars to fivestar_formatter_default.
foreach($instance['display'] as $key => $display) {
if ($display['type'] == 'fivestar_formatter_exposed_stars') {
// Convert the formatter and set the exposed settings.
$instance['display'][$key]['type'] == 'fivestar_formatter_default';
$instance['display'][$key]['settings']['expose'] = TRUE;
// The widget type needs to be exposed for the widget to be exposed.
$instance['widget']['type'] = 'exposed';
// If one of the displays allowed clearing change the field settings
// to allow clearing.
if ($display['settings']['allow_clear'] == TRUE) {
$instance['settings']['allow_clear'] = TRUE;
}
}
}
// Update the instance
field_update_instance($instance);
}
}
}