'',
'form_key' => NULL,
'email' => 1,
'mandatory' => 0,
'pid' => 0,
'weight' => 0,
'value' => '',
'extra' => array(
'items' => '',
'email' => 0,
'multiple' => NULL,
'aslist' => NULL,
'description' => '',
),
);
}
/**
* Create a set of form items to be displayed on the form for editing this
* component. Use care naming the form items, as this correlates directly to the
* database schema. The component "Name" and "Description" fields are added to
* every component type and are not necessary to specify here (although they may
* be overridden if desired).
* @return
* An array of form items to be displayed on the edit component page.
*/
function _webform_edit_nodequeue($currfield) {
$opts = $edit_fields = array();
$queues = nodequeue_load_queues(nodequeue_get_all_qids(0));
foreach ($queues as $q) {
$subqueues = nodequeue_load_subqueues_by_queue($q->qid);
foreach ($subqueues as $sq) {
$opts["{$sq->qid}-{$sq->sqid}"] = $q->subqueues > 1 ? "{$q->title} - {$sq->title}" : $q->title;
}
}
$edit_fields['extra']['nq'] = array(
'#type' => 'select',
'#title' => t('Select the Nodequeue'),
'#default_value' => $currfield['extra']['nq'],
'#description' => t('Select a nodequeue from the dropdown list to populate the options'),
'#weight' => -2,
'#required' => TRUE,
'#options' => $opts,
);
$edit_fields['extra']['type'] = array(
'#type' => 'select',
'#title' => t('Selector Type'),
'#default_value' => $currfield['extra']['type'],
'#description' => t('Choose how you would like the list of nodes to be presented.'),
'#options' => array('select' => t('Select'), 'checkboxes' => t('Checkboxes'), 'radios' => t('Radios')),
);
$edit_fields['extra']['email'] = array(
'#type' => 'checkbox',
'#title' => t('E-mail a submission copy'),
'#return_value' => 1,
'#default_value' => $currfield['extra']['email'],
'#description' => t('Check this option if this component contains an e-mail address that should get a copy of the submission. Emails are sent individually so other emails will not be shown to the recipient.') .' '.
t('To use the option with a select component, you must use key-value pairs seperated by pipes. i.e. user@example.com|Sample user.'),
);
return $edit_fields;
}
/**
* Build a form item array containing all the properties of this component.
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema.
* @return
* An array of a form item to be displayed on the client-side webform.
*/
function _webform_render_nodequeue($component) {
$form_item = array(
'#title' => $component['name'],
'#required' => $component['mandatory'],
'#weight' => $component['weight'],
'#type' => $component['extra']['type'],
'#description' => _webform_filter_descriptions($component['extra']['description']),
'#prefix' => '
',
'#suffix' => '
',
);
// Set the component options.
list($qid, $sqid) = explode('-', $component['extra']['nq']);
$form_item['#options'] = _webform_get_nodequeue_options($sqid);;
return $form_item;
}
/**
* Drupal 6 hack that properly *renders* checkboxes in multistep forms. This is
* different than the value hack needed in Drupal 5, which is no longer needed.
*/
function webform_expand_nodequeue_checkboxes($element) {
// Elements that have a value set are already in the form structure cause
// them not to be written when the expand_checkboxes function is called.
$default_value = array();
foreach (element_children($element) as $key) {
if (isset($element[$key]['#default_value'])) {
$default_value[] = $key;
unset($element[$key]);
}
}
$element = expand_checkboxes($element);
foreach ($default_value as $key) {
$element[$key]['#default_value'] = 1;
}
return $element;
}
/**
* Display the result of a textfield submission. The output of this function
* will be displayed under the "results" tab then "submissions".
* @param $data
* An array of information containing the submission result, directly
* correlating to the webform_submitted_data database schema.
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema.
* @param $enabled
* If enabled, the value may be changed. Otherwise it will set to readonly.
* @return
* Textual output formatted for human reading.
*/
function _webform_submission_display_nodequeue($data, $component, $enabled = FALSE) {
$items = array();
$result = _webform_query_for_nodes_nodequeue($data['value']);
while($n = db_fetch_object($result)) {
$items[] = l($n->title, 'node/'. $n->nid);
}
$form_item = array(
'#type' => 'item',
'#title' => $component['name'],
'#value' => theme('item_list', $items),
'#weight' => $component['weight'],
'#prefix' => '',
'#suffix' => '
',
);
return $form_item;
}
/**
* Convert FAPI 0/1 values into something saveable.
*
* @param $data
* The POST data associated with the component.
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema.
* @return
* Nothing.
*/
function _webform_submit_nodequeue(&$data, $component) {
// We need to fiter out any 0-value entries (from the checkboxes)
if (is_array($data)) {
$data = array_filter($data);
}
}
/**
* Format the output of emailed data for this component.
*
* @param $data
* A string or array of the submitted data.
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema.
* @return
* Textual output to be included in the email.
*/
function theme_webform_mail_nodequeue($data, $component) {
// Get a list of options
list($qid, $sqid) = explode('-', $component['extra']['nq']);
$options = _webform_get_nodequeue_options($sqid);
// Generate the output.
$output = '';
switch ($component['extra']['type']) {
case 'checkboxes':
$output .= $component['name'] .":\n";
foreach ((array)$data as $value) {
if ($value) {
if ($options[$value]) {
$output .= ' - '. $options[$value] ."\n";
}
}
}
break;
case 'radios':
case 'select':
if ($data !== '' && $options[$data]) {
$output .= $component['name'] .": ". $options[$data] ."\n";
}
break;
}
return $output;
}
/**
* Module specific instance of hook_help().
*/
function _webform_help_nodequeue($section) {
switch ($section) {
case 'admin/settings/webform#nodequeue_description':
return t('Allows creation of checkboxes, radio buttons, or select menus with options populated from a nodequeue.');
}
}
/**
* Module specific instance of hook_theme().
*/
function _webform_theme_nodequeue() {
return array(
'webform_mail_nodequeue' => array(
'arguments' => array('data' => NULL, 'component' => NULL),
),
);
}
/**
* Calculate and returns statistics about results for this component from all
* submission to this webform. The output of this function will be displayed
* under the "results" tab then "analysis".
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema
* @param $sids
* An optional array of submission IDs (sid). If supplied, the analysis will be limited
* to these sids.
* @return
* An array of data rows, each containing a statistic for this component's
* submissions.
*/
function _webform_analysis_rows_nodequeue($component, $sids = array()) {
// Get a list of options
list($qid, $sqid) = explode('-', $component['extra']['nq']);
$options = _webform_get_nodequeue_options($sqid);
$sidfilter = count($sids) ? ' AND sid in ('. db_placeholders($sids, 'varchar') .')' : "";
$query = 'SELECT data, count(data) AS datacount '.
'FROM {webform_submitted_data} '.
'WHERE nid = %d '.
'AND cid = %d '.
"AND data != '0' AND data != '' $sidfilter ".
'GROUP BY data ';
$result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids));
$rows = array();
$errors = array();
while ($data = db_fetch_array($result)) {
if (isset($options[$data['data']])) {
$display_option = l($options[$data['data']], 'node/'. $data['data']);
}
else {
// This nid is no longer part of the node queue...
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $data['data']));
if ($title) {
if (!$errors['nodequeue']) {
drupal_set_message(t('Some nodes listed in !name are no longer in the queue.', array('!name' => $component['name'])), 'error');
$errors['nodequeue'] = TRUE;
}
$display_option = l($title, 'node/'. $data['data']);
}
else {
if (!$errors['missingnode']) {
drupal_set_message(t('A node listed in !name are no longer exists on this site.', array('!name' => $component['name'])), 'error');
$errors['nodequeue'] = TRUE;
}
$display_option = t('Node !nid no longer exists', array('!nid' => $data['data']));
}
}
$rows[] = array($display_option, $data['datacount']);
}
return $rows;
}
/**
* Return the result of this component's submission for display in a table. The
* output of this function will be displayed under the "results" tab then "table".
* @param $data
* An array of information containing the submission result, directly
* correlating to the webform_submitted_data database schema
* @return
* Textual output formatted for human reading.
*/
function _webform_table_data_nodequeue($data) {
$result = _webform_query_for_nodes_nodequeue($data['value']);
$items = array();
while($n = db_fetch_object($result)) {
$items[] = l($n->title, 'node/'. $n->nid);
}
return theme('item_list', $items);
}
/**
* Return the header information for this component to be displayed in a comma
* seperated value file. The output of this function will be displayed under the
* "results" tab then "download".
* @param $component
* An array of information describing the component, directly correlating to
* the webform_component database schema.
* @return
* An array of data to be displayed in the first three rows of a CSV file, not
* including either prefixed or trailing commas.
*/
function _webform_csv_headers_nodequeue($component) {
$headers = array(
0 => array(),
1 => array(),
2 => array(),
);
switch ($component['extra']['type']) {
case 'checkboxes':
$headers[0][] = '';
$headers[1][] = $component['name'];
list($qid, $sqid) = explode('-', $component['extra']['nq']);
$items = _webform_get_nodequeue_options($sqid);
$count = 0;
foreach ($items as $key => $item) {
// Empty column per sub-field in main header.
if ($count != 0) {
$headers[0][] = '';
$headers[1][] = '';
}
$headers[2][] = $item;
$count++;
}
break;
case 'radios':
case 'select':
$headers[0][] = '';
$headers[1][] = '';
$headers[2][] = $component['name'];
break;
}
return $headers;
}
/**
* Return the result of a textfield submission. The output of this function will
* be displayed under the "results" tab then "submissions".
* @param $data
* An array of information containing the submission result, directly
* correlating to the webform_submitted_data database schema.
* @return
* Textual output formatted for CSV, not including either prefixed or trailing
* commas.
*/
function _webform_csv_data_nodequeue($data, $component) {
$value = _webform_filter_values($component['value'], NULL, NULL, FALSE);
list($qid, $sqid) = explode('-', $component['extra']['nq']);
$options = _webform_get_nodequeue_options($sqid);
$return = array();
switch ($component['extra']['type']) {
case 'checkboxes':
foreach ($options as $key => $item) {
if (in_array($key, (array)$data['value']) === TRUE) {
$return[] = 'X';
}
else {
$return[] = '';
}
}
break;
case 'radios':
case 'select':
$return = $data['value'][0];
break;
}
return $return;
}
/**
* Helper function to get a list of options for a nodequeue field
* @param $sqid
* The Nodequeue Subqueue ID
* @return
* An array of node id->node title pairs for all visible nodes in this queue.
*/
function _webform_get_nodequeue_options($sqid) {
$options = array();
$nids = nodequeue_nids_visible($sqid);
$result = db_query('SELECT DISTINCT(n.nid), n.title FROM {nodequeue_nodes} nq LEFT JOIN {node} n ON n.nid = nq.nid WHERE nq.sqid = %d ORDER BY nq.position', $sqid);
while ($node = db_fetch_object($result)) {
$options[$node->nid] = $node->title;
}
return $options;
}
/**
* Helper function to return a resultset of node nid/title pairs for a given array of nids.
* @param $nids
* An array of Node ID's to load up
* @return
* An array of node ID/Title key/value pairs.
*/
function _webform_query_for_nodes_nodequeue($nids = array()) {
return db_query('SELECT n.nid, n.title FROM {node} n WHERE n.nid IN ('. db_placeholders($nids, 'int') .')', $nids);
}