You are here

function reviews_edit_review_submit in Reviews 7

Submit handler for reviews_edit_review form.

File

includes/reviews.pages.inc, line 271
This file contain all function necessary for displaying and leaving reviews.

Code

function reviews_edit_review_submit($form, &$form_state) {
  $rid = $form_state['values']['rid'];
  $nid = $form_state['values']['nid'];
  $review = $form_state['values']['review'];

  // Get the node type to work out if it needs to be re-moderated.
  $node = node_load($nid);
  $status = in_array($node->type, array_filter(variable_get('reviews_moderate_content_types', ''))) ? 1 : 0;
  $record = array(
    'rid' => $rid,
    'nid' => $nid,
    'review' => serialize($review),
    'status' => $status,
  );
  if (variable_get('reviews_use_rating') and module_exists('fivestar')) {
    $record['rating'] = $form_state['values']['rating'];
  }
  $result = drupal_write_record('reviews', $record, 'rid');
  if ($result == SAVED_UPDATED) {
    reviews_update_review_count_for_node($nid);
    drupal_set_message(t('Your edited review has been saved. It will be moderated again before it is re-published.'), '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);
  }
}