function reviews_add_review_submit in Reviews 7
Submit handler for reviews_add_review form.
File
- includes/
reviews.pages.inc, line 146 - This file contain all function necessary for displaying and leaving reviews.
Code
function reviews_add_review_submit($form, &$form_state) {
$nid = $form_state['values']['nid'];
$uid = $form_state['values']['uid'];
$review = $form_state['values']['review'];
$created = REQUEST_TIME;
if (variable_get('reviews_use_rating') and module_exists('fivestar')) {
$rating = $form_state['values']['rating'];
}
// Get the node type to see if it is moderated or not.
$node = node_load($nid);
$status = in_array($node->type, array_filter(variable_get('reviews_moderate_content_types', ''))) ? 1 : 0;
$record = array(
'nid' => $nid,
'uid' => $uid,
'review' => serialize($review),
'status' => $status,
'created' => $created,
);
if (variable_get('reviews_use_rating') and module_exists('fivestar')) {
$record['rating'] = $rating;
}
$result = drupal_write_record('reviews', $record);
if ($result == SAVED_NEW) {
reviews_update_review_count_for_node($nid);
reviews_notify_admin($nid);
if ($status == 0) {
drupal_set_message(t('Your review has been submitted. It will be moderated before it is published.'), 'status');
}
else {
drupal_set_message(t('Thankyou! Your review has been submitted.'), 'status');
}
drupal_goto('node/' . $nid);
}
else {
drupal_set_message(t('There seems to have been a problem submitting your review. Please try again later'), 'error');
drupal_goto('node/' . $nid . '/add-review');
}
}