function activity_comments_form_submit in Activity 7
Same name and namespace in other branches
- 6.2 activity_comments/activity_comments.module \activity_comments_form_submit()
Implements hook_submit() for activity_comments_form().
File
- activity_comments/
activity_comments.module, line 168 - Provides comment handling for activity messages
Code
function activity_comments_form_submit($form, &$form_state) {
global $user;
// Store the activity comment.
$record = new stdClass();
$record->comment = $form_state['values']['activity_comment'];
$record->uid = $user->uid;
$record->aid = $form_state['values']['aid'];
$record->timestamp = REQUEST_TIME;
drupal_alter('activity_comment', $record);
// The alter could have set the record to NULL.
if (!empty($record)) {
drupal_write_record('activity_comments', $record);
$count = db_query('SELECT COUNT(cid) FROM {activity_comments} WHERE aid = :aid', array(
':aid' => $record->aid,
))
->fetchField();
if ($count > 0) {
db_update('activity_comments_stats')
->fields(array(
'comment_count' => $count,
'changed' => REQUEST_TIME,
))
->condition('aid', $form['aid']['#value'])
->execute();
}
else {
db_insert('activity_comments_stats')
->fields(array(
'aid' => $form['aid']['#value'],
'changed' => REQUEST_TIME,
'comment_count' => 1,
))
->execute();
}
}
$form_state['rebuild'] = TRUE;
}