| 152 |
*/ |
*/ |
| 153 |
function views_calc_fields_form() { |
function views_calc_fields_form() { |
| 154 |
$i = 0; |
$i = 0; |
| 155 |
$substitutions = _views_calc_substitutions(); |
$substitutions = array(); |
| 156 |
$reverse = array_flip($substitutions); |
$help = t('<p>The specific fields that are available in any view depend on the base table used for that view.</p>'); |
| 157 |
|
require_once(drupal_get_path('module', 'views') .'/includes/admin.inc'); |
| 158 |
|
$base_tables = views_fetch_base_tables(); |
| 159 |
|
foreach ($base_tables as $base => $data) { |
| 160 |
|
$base_subs = _views_calc_substitutions($base); |
| 161 |
|
$substitutions += $base_subs; |
| 162 |
|
$fieldset = array( |
| 163 |
|
'#title' => t('Base table: !name', array('!name' => t($data['title']))), |
| 164 |
|
'#value' => theme('item_list', $base_subs), |
| 165 |
|
'#collapsible' => TRUE, |
| 166 |
|
'#collapsed' => TRUE, |
| 167 |
|
); |
| 168 |
|
$help .= theme('fieldset', $fieldset); |
| 169 |
|
} |
| 170 |
|
|
| 171 |
// display current views calcs fields |
// display current views calcs fields |
| 172 |
$fields = _views_calc_fields(); |
$fields = _views_calc_fields(); |
| 180 |
$form[] = views_calc_field_form_item($i, $field, $substitutions); |
$form[] = views_calc_field_form_item($i, $field, $substitutions); |
| 181 |
} |
} |
| 182 |
$form['#prefix'] = '<div class="views-calc-field-settings">'; |
$form['#prefix'] = '<div class="views-calc-field-settings">'; |
| 183 |
$form['#suffix'] = '</div><div class="views-calc-field-names"><strong>Field Substitutions</strong><div class="form-item">'. theme('item_list', _views_calc_substitutions()) .'</div></div>'; |
$form['#suffix'] = '</div><div class="views-calc-field-names"><strong>Field Substitutions</strong><div class="form-item">'. $help .'</div></div>'; |
| 184 |
$form['submit'] = array( |
$form['submit'] = array( |
| 185 |
'#type' => 'submit', |
'#type' => 'submit', |
| 186 |
'#value' => t('Save'), |
'#value' => t('Save'), |
| 195 |
if (empty($field)) { |
if (empty($field)) { |
| 196 |
$field = array('cid' => 0, 'label' => '', 'tablelist' => '', 'calc' => '', 'format' => '', 'custom' => ''); |
$field = array('cid' => 0, 'label' => '', 'tablelist' => '', 'calc' => '', 'format' => '', 'custom' => ''); |
| 197 |
} |
} |
| 198 |
|
require_once(drupal_get_path('module', 'views') .'/includes/admin.inc'); |
| 199 |
|
$options = array(); |
| 200 |
|
$base_tables = views_fetch_base_tables(); |
| 201 |
|
foreach ($base_tables as $base => $data) { |
| 202 |
|
$options[$base] = t($data['title']); |
| 203 |
|
} |
| 204 |
$form['group'][$i] = array( |
$form['group'][$i] = array( |
| 205 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 206 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 223 |
'#default_value' => str_replace('ViewsCalc: ', '', $field['label']), |
'#default_value' => str_replace('ViewsCalc: ', '', $field['label']), |
| 224 |
'#description' => t('The views field name for this field (i.e. Views Calc: My Calculation).'), |
'#description' => t('The views field name for this field (i.e. Views Calc: My Calculation).'), |
| 225 |
); |
); |
| 226 |
|
$form['group'][$i]['base'] = array( |
| 227 |
|
'#type' => 'select', |
| 228 |
|
'#title' => t('Base table'), |
| 229 |
|
'#options' => $options, |
| 230 |
|
'#default_value' => !empty($field['base']) && array_key_exists($field['base'], $options) ? $field['base'] : 'node', |
| 231 |
|
'#description' => t('The base table for this field.'), |
| 232 |
|
); |
| 233 |
$form['group'][$i]['calc'] = array( |
$form['group'][$i]['calc'] = array( |
| 234 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 235 |
'#title' => t('Calculation'), |
'#title' => t('Calculation'), |
| 236 |
'#default_value' => strtr($field['calc'], $substitutions), |
'#default_value' => strtr($field['calc'], $substitutions), |
| 237 |
'#description' => t('<p>The query operation to be performed, using numbers, field substitutions, and '. implode(' ', _views_calc_operators()) .'.</p>'), |
'#description' => t('<p>The query operation to be performed, using numbers, field substitutions, and '. implode(' ', _views_calc_operators()) .'. <strong>'. t('Note that all fields must be from the base table selected above!') .'</strong></p>'), |
| 238 |
); |
); |
| 239 |
$form['group'][$i]['format'] = array( |
$form['group'][$i]['format'] = array( |
| 240 |
'#type' => 'select', |
'#type' => 'select', |
| 268 |
// First, remove all field names. |
// First, remove all field names. |
| 269 |
$repl = array(); |
$repl = array(); |
| 270 |
$patterns = array(); |
$patterns = array(); |
| 271 |
foreach (_views_calc_substitutions() as $key => $value) { |
$base = $item['base']; |
| 272 |
|
foreach (_views_calc_substitutions($base) as $key => $value) { |
| 273 |
$key = trim($value); |
$key = trim($value); |
| 274 |
$count = strlen($value); |
$count = strlen($value); |
| 275 |
$replace = preg_quote($value); |
$replace = preg_quote($value); |
| 310 |
$form_values[$delta]['format'] = $value['format']; |
$form_values[$delta]['format'] = $value['format']; |
| 311 |
$form_values[$delta]['custom'] = $value['custom']; |
$form_values[$delta]['custom'] = $value['custom']; |
| 312 |
$form_values[$delta]['calc'] = $value['calc']; |
$form_values[$delta]['calc'] = $value['calc']; |
| 313 |
|
$form_values[$delta]['base'] = $value['base']; |
| 314 |
|
|
| 315 |
// Substitute field names back into the calculation. |
// Substitute field names back into the calculation. |
| 316 |
$matches = array(); |
$matches = array(); |
| 317 |
foreach (_views_calc_substitutions() as $key => $value) { |
$base = $value['base']; |
| 318 |
|
foreach (_views_calc_substitutions($base) as $key => $value) { |
| 319 |
$label_patterns[] = "`(^|[^\\\\\\\\])". preg_quote($value) ."`"; |
$label_patterns[] = "`(^|[^\\\\\\\\])". preg_quote($value) ."`"; |
| 320 |
$value_patterns[] = "`(^|[^\\\\\\\\])". preg_quote($key) ."`"; |
$value_patterns[] = "`(^|[^\\\\\\\\])". preg_quote($key) ."`"; |
| 321 |
$repl[] = '${1}'. $key; |
$repl[] = '${1}'. $key; |