You are here

function webform_civicrm_preprocess_webform_results_submissions in Webform CiviCRM Integration 7.3

Same name and namespace in other branches
  1. 8.5 webform_civicrm.module \webform_civicrm_preprocess_webform_results_submissions()
  2. 7.5 webform_civicrm.module \webform_civicrm_preprocess_webform_results_submissions()
  3. 7.4 webform_civicrm.module \webform_civicrm_preprocess_webform_results_submissions()

Implements hook_preprocess_HOOK(). Add CiviCRM names to webform submission results table.

File

./webform_civicrm.module, line 371
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_preprocess_webform_results_submissions(&$variables) {
  if (count($variables['table']['#rows']) && !empty($variables['node']->webform_civicrm)) {
    $access = user_access('access CiviCRM');
    $temp = $variables['table']['#header'];
    $variables['table']['#header'] = array();

    // Move name to position 2
    foreach ($temp as $k => $v) {
      $variables['table']['#header'][] = $v;
      if ($k == 1) {
        $variables['table']['#header'][] = t('Name');
      }
    }
    foreach ($variables['table']['#rows'] as &$row) {
      $name = '';
      $sid = $row[0];
      if (!empty($variables['submissions'][$sid]->civicrm['contact_id'][1])) {
        $data = $variables['submissions'][$sid]->civicrm;
        if (($name = $data['display_name']) !== '') {
          if ($access) {
            $name = l($name, 'civicrm/contact/view', array(
              'query' => array(
                'reset' => 1,
                'cid' => $data['contact_id'][1],
              ),
              'alias' => TRUE,
            ));
          }
        }
      }
      $temp = $row;
      $row = array();

      // Move name to position 2
      foreach ($temp as $k => $v) {
        $row[] = $v;
        if ($k == 1) {
          $row[] = $name;
        }
      }
    }
  }
}