array( 'label' => t('Plan line field simple'), 'description' => t('Store items operative plan data in the database.'), ), ); } /** * Implementation of hook_field_settings(). */ function cck_plan_fields_simple_field_settings($op, $field) { switch ($op) { case 'form': $form = array(); $types = array( 'int' => t('Integer'), 'float' => t('Floar'), ); $form['cck_plan_fields_simple_type'] = array( '#type' => 'select', '#title' => t('Type'), '#default_value' => !empty($field['cck_plan_fields_simple_type']) ? $field['cck_plan_fields_simple_type'] : 'int', '#options' => $types, ); return $form; case 'save': $save_settings = array( 'cck_plan_fields_simple_type', ); return $save_settings; case 'database columns': $type_select = !empty($field['cck_plan_fields_simple_type']) ? $field['cck_plan_fields_simple_type'] : 'int'; $types = array( 'int' => t('Integer'), 'float' => t('Floar'), ); $type_select = isset($types[$type_select]) ? $type_select : 'int'; for ($i = 0; $i < 12; $i++) { $field_id = $i ? 'value_' . $i : 'value'; if ($type_select == 'int') { $columns[$field_id] = array( 'type' => $type_select, 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE, ); } else { $columns[$field_id] = array( 'type' => 'numeric', 'size' => 'normal', 'not null' => TRUE, 'default' => 0, 'precision' => 32, 'scale' => 0, ); } } return $columns; case 'views data': $data = content_views_field_views_data($field); $db_info = content_database_info($field); $table_alias = content_views_tablename($field); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); foreach ($ftypes as $ftype => $label) { $copy = $data[$table_alias][$field['field_name'] . $ftype]; $copy['title'] = t($label); $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; $copy['filter']['numeric'] = TRUE; unset($copy['field'], $copy['argument'], $copy['sort']); $data[$table_alias][$field['field_name'] . $ftype . '_many_to_one'] = $copy; $data[$table_alias][$field['field_name'] . $ftype]['argument']['handler'] = 'content_handler_argument_many_to_one'; if ($ftype != 'description') { $data[$table_alias][$field['field_name'] . $ftype]['argument']['numeric'] = TRUE; } } return $data; } } /** * Implementation of hook_content_is_empty(). */ function cck_plan_fields_simple_content_is_empty($item, $field) { $flat = TRUE; foreach (array_keys($field['columns']) as $ftype) { if (!empty($item[$ftype])) { return FALSE; } } return $flat; } /** * Implementation of hook_field_formatter_info(). */ function cck_plan_fields_simple_field_formatter_info() { $formatters = array( 'default' => array( 'label' => t('Default'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('cck_plan_fields_simple_field'), ), 'single_line' => array( 'label' => t('Single Line'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('cck_plan_fields_simple_field'), ), ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); foreach ($ftypes as $value => $label) { $formatters['single_line_' . $value] = array( 'label' => t('Single Line ') . $label, 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('cck_plan_fields_simple_field'), ); } return $formatters; } /** * Implementation of hook_theme(). */ function cck_plan_fields_simple_theme() { return array( 'cck_plan_fields_simple_formatter_default' => array( 'arguments' => array('element'), ), 'cck_plan_fields_simple_formatter_single_line' => array( 'arguments' => array('element'), ), 'cck_plan_fields_simple_formatter_single_line_value' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value1' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value2' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value3' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic' ), 'cck_plan_fields_simple_formatter_single_line_value4' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value5' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value6' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value7' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value8' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value9' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value10' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_formatter_single_line_value11' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_simple_formatter_generic', ), 'cck_plan_fields_simple_table' => array( 'arguments' => array('form' => NULL), ), ); } /** * Proxy theme function for cck_plan_fields_simple formatters. */ function theme_cck_plan_fields_simple_formatter_generic($element) { $output = ''; $flag = explode('single_line_', $element['#formatter']); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $output = ''. $ftypes[$flag[1]] .': '. number_format($element['#item'][$flag[1]], 2, '.', ','); return $output; } /** * theme_cck_plan_fields_formatter_default(). * default formatter theme */ function theme_cck_plan_fields_simple_formatter_default($element) { $output = ''; $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), 'total' => t('Total'), ); $headers = array(); $rows = array(); $row = array(); $empty = TRUE; $total = 0; foreach ($ftypes as $value => $label) { $headers[] = array('data' => $label); if (!empty($element['#item'][$value])) { $empty = FALSE; } $total += $element['#item'][$value]; if ($value != 'total') { $row[] = array('data' => number_format($element['#item'][$value], 2, '.', ',')); } } if ($empty) { return ''; } $row[] = array('data' => number_format($total, 2, '.', ',')); $rows[] = $row; return theme('table', $headers, $rows); } /** * theme_cck_plan_fields_formatter_single_line(). * display line items products in a single line */ function theme_cck_plan_fields_simple_formatter_single_line($element) { $output = ''; // If all fields are hidden, return '' if (empty($element)) { return $output; } $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); foreach ($ftypes as $value => $label) { $output .= ' '. $label .': '. number_format($element['#item'][$value], 2, '.', ','); } return '