You are here

function heartbeat_user_templates_submit in Heartbeat 7

Submit handler to save a users profile templates.

1 string reference to 'heartbeat_user_templates_submit'
heartbeat_user_templates in ./heartbeat.module
Add the heartbeat template field to the user edit form.

File

./heartbeat.module, line 548
Module file for heartbeat activity. Basic hook implementations and helper functions will be found here.

Code

function heartbeat_user_templates_submit($form, $form_state) {
  if (!empty($form_state['values']['templates'])) {

    // Message templates for user will have the options:
    //  HEARTBEAT_NONE, HEARTBEAT_PRIVATE, HEARTBEAT_PUBLIC_TO_ALL, HEARTBEAT_PUBLIC_TO_CONNECTED.
    db_delete('heartbeat_user_templates')
      ->condition('uid', $form['#user']->uid)
      ->execute();
    foreach ($form_state['values']['templates'] as $template_id => $permission) {
      db_insert('heartbeat_user_templates')
        ->fields(array(
        'uid',
        'message_id',
        'status',
      ), array(
        $form['#user']->uid,
        $template_id,
        $permission,
      ))
        ->execute();
    }
    if (isset($form_state['values']['privacy']['default_template'])) {
      db_insert('heartbeat_user_templates')
        ->fields(array(
        'uid',
        'message_id',
        'status',
      ), array(
        $form['#user']->uid,
        "0",
        $form_state['values']['privacy']['default_template'],
      ))
        ->execute();
    }
  }
}