array( 'label' => t('Plan line field'), 'description' => t('Store items operative plan data in the database.'), ), ); } /** * Implementation of hook_field_settings(). */ function cck_plan_fields_field_settings($op, $field) { switch ($op) { case 'form': $form = array(); $vocabularies = taxonomy_get_vocabularies(); $vocabulary_options = array(); foreach($vocabularies as $vocabulary) { $vocabulary_options[$vocabulary->vid] = $vocabulary->name; } $traslate_labels = array( 'vid' => t('Taxonomy'), ); $form['vid'] = array( '#type' => 'select', '#title' => t('Taxonomy'), '#default_value' => !empty($field['vid']) ? $field['vid'] : '', '#options' => $vocabulary_options, ); if (!empty($field['vid'])) { $vid = $field['vid']; //$terms = taxonomy_get_tree($vid); $tree = taxonomy_get_tree($vid); $options = array(); if ($tree) { foreach ($tree as $term) { $choice = new stdClass(); $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); $options[] = $choice; } } $form['vtid'] = array( '#type' => 'select', '#default_value' => isset($field['vtid']) ? $field['vtid'] : array(), '#options' => $options, '#multiple' => TRUE, ); } $types = array( 'int' => t('Integer'), 'float' => t('Float'), ); $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, ); $form['cck_plan_fields_simple_titulo'] = array( '#type' => 'textfield', '#title' => t('Titulo del total'), //'#required' => TRUE, '#weight' => -9, '#default_value' => !empty($field['cck_plan_fields_simple_titulo']) ? $field['cck_plan_fields_simple_titulo'] : '', ); return $form; case 'save': $save_settings = array( 'vid', 'vtid', 'cck_plan_fields_simple_type', 'cck_plan_fields_simple_titulo', ); return $save_settings; case 'database columns': $columns['tid'] = array( 'type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE, ); for ($i = 0; $i < 12; $i++) { $field_id = $i ? 'value_' . $i : 'value'; $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( 'tid' => t('Plan Account'), '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_content_is_empty($item, $field) { $flat = TRUE; foreach (array_keys($field['columns']) as $ftype) { if ($ftype != 'tid' && !empty($item[$ftype])) { $flat = FALSE; } } return $flat; } /** * Implementation of hook_field_formatter_info(). */ function cck_plan_fields_field_formatter_info() { $formatters = array( 'default' => array( 'label' => t('Default'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('cck_plan_fields_field'), ), 'single_line' => array( 'label' => t('Single Line'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('cck_plan_fields_field'), ), ); $ftypes = array( 'tid' => t('Partidas'), '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_field'), ); } return $formatters; } /** * Implementation of hook_theme(). */ function cck_plan_fields_theme() { return array( // Shows address in the default view: Multilines 'cck_plan_fields_formatter_default' => array( 'arguments' => array('element'), ), // Shows address in only one line 'cck_plan_fields_formatter_single_line' => array( 'arguments' => array('element'), ), 'cck_plan_fields_formatter_single_line_tid' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value1' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value2' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value3' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic' ), 'cck_plan_fields_formatter_single_line_value4' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value5' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value6' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value7' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value8' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value9' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value10' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_formatter_single_line_value11' => array( 'arguments' => array('form' => NULL), 'function' => 'theme_cck_plan_fields_formatter_generic', ), 'cck_plan_fields_table' => array( 'arguments' => array('form' => NULL), ), ); } /** * Proxy theme function for cck_plan_fields formatters. */ function theme_cck_plan_fields_formatter_generic($element) { $output = ''; $flag = explode('single_line_', $element['#formatter']); $ftypes = array( 'tid' => t('Partidas'), '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'), ); if ($flag[1] == 'tid') { $term = taxonomy_get_term($element['#item'][$flag[1]]); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $output = ''. $ftypes[$flag[1]] .': '. check_plain($term->name); } else { $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_formatter_default($element) { $output = ''; // If all fields are hidden, return '' if (empty($element['#item']['tid'])) { return $output; } $ftypes = array( 'tid' => t('Partidas'), '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'), ); $ftypes['total'] = !empty($field['cck_plan_fields_simple_titulo']) ? $field['cck_plan_fields_simple_titulo'] : t('Total'); $headers = array(); $rows = array(); $row = array(); $total = 0; foreach ($ftypes as $value => $label) { $headers[] = array('data' => $label); if ($value != 'tid') { if ($value != 'total') { $total += $element['#item'][$value]; $row[] = array('data' => number_format($element['#item'][$value], 2, '.', ',')); } else { $row[] = array('data' => $total); } } else { $term = taxonomy_get_term($element['#item'][$value]); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $row[] = array('data' => $term->name); } } $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_formatter_single_line($element) { $output = ''; // If all fields are hidden, return '' if (empty($element)) { return $output; } $ftypes = array( 'tid' => t('Partidas'), '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) { if ($value != 'tid') { $output .= ' '. $label .': '. number_format($element['#item'][$value], 2, '.', ','); } else { $term = taxonomy_get_term($element['#item'][$value]); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $output .= ''. $label .': '. check_plain($term->name); } } return '