campaignmonitor.inc in Webform Campaign Monitor 6
Same filename and directory in other branches
Webform Campaign Monitor component.
File
components/campaignmonitor.incView source
<?php
/**
* @file
* Webform Campaign Monitor component.
*/
/**
* Implementation of _webform_defaults_component().
*/
function _webform_defaults_campaignmonitor() {
return array(
'name' => '',
'form_key' => NULL,
'pid' => 0,
'weight' => 0,
'value' => '',
'mandatory' => 0,
'extra' => array(
'description' => '',
'checked' => '',
),
);
}
/**
* Implementation of _webform_theme_component().
*/
function _webform_theme_campaignmonitor() {
return array(
'webform_display_campaignmonitor' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'components/campaignmonitor.inc',
),
);
}
/**
* Implementation of _webform_edit_component().
*/
function _webform_edit_campaignmonitor($component) {
// Textfield Components.
$textfield_components = _webform_campaignmonitor_list_components($component['nid'], 'textfield');
if ($textfield_components) {
$form['extra']['textfield_component'] = array(
'#type' => 'select',
'#title' => t('Name Component'),
'#description' => t("Select the webform component that contains the user's name."),
'#options' => array(),
'#weight' => 0,
'#required' => FALSE,
);
$form['extra']['textfield_component']['#options'][''] = t('- None -');
foreach ($textfield_components as $textfield_component) {
$form['extra']['textfield_component']['#options'][$textfield_component['cid']] = $textfield_component['name'];
}
if (isset($component['extra']['textfield_component'])) {
$form['extra']['textfield_component']['#default_value'] = $component['extra']['textfield_component'];
}
}
// Email Components.
$email_components = _webform_campaignmonitor_list_components($component['nid'], 'email');
if ($email_components) {
$form['extra']['email_component'] = array(
'#type' => 'select',
'#title' => t('Email Component'),
'#description' => t("Select the webform component that contains the user's email address."),
'#options' => array(),
'#weight' => 0,
'#required' => TRUE,
);
foreach ($email_components as $email_component) {
$form['extra']['email_component']['#options'][$email_component['cid']] = $email_component['name'];
}
if (isset($component['extra']['email_component'])) {
$form['extra']['email_component']['#default_value'] = $component['extra']['email_component'];
}
}
else {
drupal_set_message(t("You haven't created any email components for this form yet."), 'warning');
}
// Extra Options..
$form['extra']['checked'] = array(
'#type' => 'checkbox',
'#title' => t('Checked by default'),
'#default_value' => $component['extra']['checked'],
'#description' => t('Check this option if this field should be checked by default.'),
'#weight' => 5,
);
// Hide the display options.
$form['display'] = array(
'#type' => 'markup',
);
return $form;
}
/**
* Implementation of _webform_render_component().
*/
function _webform_render_campaignmonitor($component, $value = NULL, $filter = TRUE) {
$node = isset($component['nid']) ? node_load($component['nid']) : NULL;
$element = array(
'#type' => 'checkbox',
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
'#default_value' => $component['extra']['checked'],
'#required' => $component['mandatory'],
'#weight' => $component['weight'],
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
'#theme_wrappers' => array(
'webform_element_wrapper',
),
'#post_render' => array(
'webform_element_wrapper',
),
'#translatable' => array(
'title',
'description',
),
);
return $element;
}
/**
* Implementation of _webform_display_component().
*/
function _webform_display_campaignmonitor($component, $value, $format = 'html') {
return array(
'#title' => $component['name'],
'#weight' => $component['weight'],
'#theme' => 'webform_display_campaignmonitor',
'#theme_wrappers' => $format == 'html' ? array(
'webform_element',
'webform_element_wrapper',
) : array(
'webform_element_text',
),
'#post_render' => array(
'webform_element_wrapper',
),
'#format' => $format,
'#value' => isset($value[0]) ? $value[0] : '',
'#translatable' => array(
'title',
'description',
),
);
}
/**
* Format the output of data for this component.
*/
function theme_webform_display_campaignmonitor($element) {
return $element['#value'] ? t('Yes') : t('No');
}
/**
* Implementation of _webform_analysis_component().
*/
function _webform_analysis_campaignmonitor($component, $sids = array()) {
$placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
$sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
$query = 'SELECT data FROM {webform_submitted_data} WHERE nid = %d AND cid = %d ' . $sidfilter;
$nonblanks = 0;
$submissions = 0;
$result = db_query($query, array_merge(array(
$component['nid'],
$component['cid'],
), $sids));
while ($data = db_fetch_array($result)) {
if ($data['data']) {
$nonblanks++;
}
$submissions++;
}
$rows = array();
$rows[0] = array(
t("User didn't check the box"),
$submissions - $nonblanks,
);
$rows[1] = array(
t('User did check the box'),
$nonblanks,
);
return $rows;
}
/**
* Implementation of _webform_table_component().
*/
function _webform_table_campaignmonitor($component, $value) {
return $value[0] ? t('Yes') : t('No');
}
/**
* Implementation of _webform_csv_headers_component().
*/
function _webform_csv_headers_campaignmonitor($component, $export_options) {
$header = array();
$header[0] = '';
$header[1] = '';
$header[2] = $component['name'];
return $header;
}
/**
* Implementation of _webform_csv_data_component().
*/
function _webform_csv_data_campaignmonitor($component, $export_options, $value) {
return $value[0] ? t('Yes') : t('No');
}
Functions
Name![]() |
Description |
---|---|
theme_webform_display_campaignmonitor | Format the output of data for this component. |
_webform_analysis_campaignmonitor | Implementation of _webform_analysis_component(). |
_webform_csv_data_campaignmonitor | Implementation of _webform_csv_data_component(). |
_webform_csv_headers_campaignmonitor | Implementation of _webform_csv_headers_component(). |
_webform_defaults_campaignmonitor | Implementation of _webform_defaults_component(). |
_webform_display_campaignmonitor | Implementation of _webform_display_component(). |
_webform_edit_campaignmonitor | Implementation of _webform_edit_component(). |
_webform_render_campaignmonitor | Implementation of _webform_render_component(). |
_webform_table_campaignmonitor | Implementation of _webform_table_component(). |
_webform_theme_campaignmonitor | Implementation of _webform_theme_component(). |