[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/webform/components/ -> textarea.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Webform module textarea component.
   6   */
   7  
   8  /**
   9   * Implements _webform_defaults_component().
  10   */
  11  function _webform_defaults_textarea() {
  12    return array(
  13      'name' => '',
  14      'form_key' => NULL,
  15      'pid' => 0,
  16      'weight' => 0,
  17      'value' => '',
  18      'mandatory' => 0,
  19      'extra' => array(
  20        'cols' => '',
  21        'rows' => '',
  22        'title_display' => 0,
  23        'resizable' => 1,
  24        'disabled' => 0,
  25        'description' => '',
  26        'attributes' => array(),
  27        'private' => FALSE,
  28      ),
  29    );
  30  }
  31  
  32  
  33  /**
  34   * Implements _webform_theme_component().
  35   */
  36  function _webform_theme_textarea() {
  37    return array(
  38      'webform_display_textarea' => array(
  39        'arguments' => array('element' => NULL),
  40        'file' => 'components/textarea.inc',
  41      ),
  42    );
  43  }
  44  
  45  /**
  46   * Implements _webform_edit_component().
  47   */
  48  function _webform_edit_textarea($component) {
  49    $form = array();
  50    $form['value'] = array(
  51      '#type' => 'textarea',
  52      '#title' => t('Default value'),
  53      '#default_value' => $component['value'],
  54      '#description' => t('The default value of the field.') . theme('webform_token_help'),
  55      '#cols' => 60,
  56      '#rows' => 5,
  57      '#weight' => 0,
  58    );
  59    $form['display']['cols'] = array(
  60      '#type' => 'textfield',
  61      '#title' => t('Width'),
  62      '#default_value' => $component['extra']['cols'],
  63      '#description' => t('Width of the textarea in columns. This property might not have a visual impact depending on the CSS of your site.') . ' ' . t('Leaving blank will use the default size.'),
  64      '#size' => 5,
  65      '#maxlength' => 10,
  66      '#parents' => array('extra', 'cols'),
  67    );
  68    $form['display']['rows'] = array(
  69      '#type' => 'textfield',
  70      '#title' => t('Height'),
  71      '#default_value' => $component['extra']['rows'],
  72      '#description' => t('Height of the textarea in rows.') . ' ' . t('Leaving blank will use the default size.'),
  73      '#size' => 5,
  74      '#maxlength' => 10,
  75      '#parents' => array('extra', 'rows'),
  76    );
  77    $form['display']['resizable'] = array(
  78      '#type' => 'checkbox',
  79      '#title' => t('Resizable'),
  80      '#description' => t('Make this field resizable by the user.'),
  81      '#weight' => 2,
  82      '#default_value' => $component['extra']['resizable'],
  83      '#parents' => array('extra', 'resizable'),
  84    );
  85    $form['display']['disabled'] = array(
  86      '#type' => 'checkbox',
  87      '#title' => t('Disabled'),
  88      '#return_value' => 1,
  89      '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
  90      '#weight' => 11,
  91      '#default_value' => $component['extra']['disabled'],
  92      '#parents' => array('extra', 'disabled'),
  93    );
  94    return $form;
  95  }
  96  
  97  /**
  98   * Implements _webform_render_component().
  99   */
 100  function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
 101    $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 102  
 103    $element = array(
 104      '#type' => 'textarea',
 105      '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
 106      '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
 107      '#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
 108      '#required' => $component['mandatory'],
 109      '#weight' => $component['weight'],
 110      '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
 111      '#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
 112      '#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
 113      '#attributes' => $component['extra']['attributes'],
 114      '#resizable' => (bool) $component['extra']['resizable'], // MUST be FALSE to disable.
 115      '#theme_wrappers' => array('webform_element_wrapper'),
 116      '#pre_render' => array('webform_element_title_display'),
 117      '#post_render' => array('webform_element_wrapper'),
 118      '#translatable' => array('title', 'description'),
 119    );
 120  
 121    if ($component['extra']['disabled']) {
 122      if ($filter) {
 123        $element['#attributes']['readonly'] = 'readonly';
 124      }
 125      else {
 126        $element['#disabled'] = TRUE;
 127      }
 128    }
 129  
 130    if (isset($value)) {
 131      $element['#default_value'] = $value[0];
 132    }
 133  
 134    return $element;
 135  }
 136  
 137  /**
 138   * Implements _webform_display_component().
 139   */
 140  function _webform_display_textarea($component, $value, $format = 'html') {
 141    return array(
 142      '#title' => $component['name'],
 143      '#weight' => $component['weight'],
 144      '#theme' => 'webform_display_textarea',
 145      '#theme_wrappers' => $format == 'html' ? array('webform_element', 'webform_element_wrapper') : array('webform_element_text'),
 146      '#post_render' => array('webform_element_wrapper'),
 147      '#format' => $format,
 148      '#value' => isset($value[0]) ? $value[0] : '',
 149      '#translatable' => array('title'),
 150    );
 151  }
 152  
 153  /**
 154   * Format the output of data for this component.
 155   */
 156  function theme_webform_display_textarea($element) {
 157    $output = $element['#format'] == 'html' ? nl2br(check_plain($element['#value'])) : $element['#value'];
 158    if (drupal_strlen($output) > 80) {
 159      $output = ($element['#format'] == 'html') ? '<div class="webform-long-answer">' . $output . '</div>' : $output;
 160    }
 161    return $output !== '' ? $output : ' ';
 162  }
 163  
 164  /**
 165   * Implements _webform_analysis_component().
 166   */
 167  function _webform_analysis_textarea($component, $sids = array()) {
 168    $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
 169    $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
 170    $query = 'SELECT data ' .
 171      ' FROM {webform_submitted_data} ' .
 172      ' WHERE nid = %d ' .
 173      ' AND cid = %d ' . $sidfilter;
 174    $nonblanks = 0;
 175    $submissions = 0;
 176    $wordcount = 0;
 177  
 178    $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids));
 179    while ($data = db_fetch_array($result)) {
 180      if (drupal_strlen(trim($data['data'])) > 0) {
 181        $nonblanks++;
 182        $wordcount += str_word_count(trim($data['data']));
 183      }
 184      $submissions++;
 185    }
 186  
 187    $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
 188    $rows[1] = array(t('User entered value'), $nonblanks);
 189    $rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0'));
 190    return $rows;
 191  }
 192  
 193  /**
 194   * Implements _webform_table_component().
 195   */
 196  function _webform_table_textarea($component, $value) {
 197    return empty($value[0]) ? '' : check_plain($value[0]);
 198  }
 199  
 200  /**
 201   * Implements _webform_csv_headers_component().
 202   */
 203  function _webform_csv_headers_textarea($component, $export_options) {
 204    $header = array();
 205    $header[0] = '';
 206    $header[1] = '';
 207    $header[2] = $component['name'];
 208    return $header;
 209  }
 210  
 211  /**
 212   * Implements _webform_csv_data_component().
 213   */
 214  function _webform_csv_data_textarea($component, $export_options, $value) {
 215    return empty($value[0]) ? '' : $value[0];
 216  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7