diff --git computed_field.module computed_field.module index 518fc77..9fe53cf 100644 --- computed_field.module +++ computed_field.module @@ -122,6 +122,25 @@ function computed_field_field_settings($op, $field) { if ($field['data_default'] != '') { $columns['value']['default'] = $field['data_default']; } + + /// --- ADDED --- /// + if ($field['save_timestamp'] == 1) { + $columns['timestamp'] = array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ); + } + if ($field['save_logic'] == 1) { + $columns['logic'] = array( + 'type' => 'text', + 'size' => 'big', + 'not null' => FALSE, + 'serialize' => TRUE, + ); + } + /// --- END ADDED --- /// + } return $columns; @@ -192,6 +211,9 @@ function computed_field_field($op, &$node, $field, &$node_field, $teaser, $page) break; case 'presave': _computed_field_compute_value($node, $field, $node_field); + + if ($field['save_timestamp']) $node_field[0]['timestamp'] = time(); + break; } } diff --git computed_field_extra/computed_field_extra.info computed_field_extra/computed_field_extra.info new file mode 100644 index 0000000..d3eec86 --- /dev/null +++ computed_field_extra/computed_field_extra.info @@ -0,0 +1,9 @@ +; $Id$ +name = Computed Field Extra +description = "Adds Logic and Timestamp columns to Computed Fields" + +core = 6.x + +package = CCK + +dependencies[] = computed_field diff --git computed_field_extra/computed_field_extra.module computed_field_extra/computed_field_extra.module new file mode 100644 index 0000000..2c9962c --- /dev/null +++ computed_field_extra/computed_field_extra.module @@ -0,0 +1,112 @@ + 'fieldset', '#title' => 'Extra'); + + $form['extra']['save_timestamp'] = array( + '#type' => 'checkbox', + '#title' => t('Save Timestamp'), + '#default_value' => is_numeric($field['save_timestamp']) ? $field['save_timestamp'] : TRUE, + ); + + $form['extra']['save_logic'] = array( + '#type' => 'checkbox', + '#title' => t('Save Logic'), + '#default_value' => is_numeric($field['save_logic']) ? $field['save_logic'] : TRUE, + ); + + break; + + + case 'save': + $values[] = 'save_timestamp'; + $values[] = 'save_logic'; + + break; + + + case 'views data': + $data = &$values; + + // could be empty if 'allowed values' fields aren't passed from main hook + if (empty($data)) { + $data = content_views_field_views_data($field); + } + + $table_alias = content_views_tablename($field); + + // add views handler for Logic column + // (start w/ value column as template - adapting method from number.module) + if ($field['save_logic']) { + $copy = $data[$table_alias][$field['field_name'] .'_value']; + $copy['title'] = $copy['field']['title'] = t('@label Logic', array('@label' => t($field['widget']['label']))); + $copy['title short'] = $copy['field']['title short'] = t('@label Logic', array('@label' => t($field['widget']['label']))); + + $copy['field']['field'] = $field['field_name'] .'_logic'; + $copy['field']['click sortable'] = FALSE; + $copy['field']['handler'] = 'views_handler_field_serialized_list'; + + // no arg, sort, or filter + unset($copy['argument'], $copy['sort'], $copy['filter']); + + $data[$table_alias][$field['field_name'] .'_logic'] = $copy; + } + + + // add views handler for Timestamp column + if ($field['save_timestamp']) { + $copy = $data[$table_alias][$field['field_name'] .'_value']; + $copy['title'] = $copy['field']['title'] = t('@label Updated', array('@label' => t($field['widget']['label']))); + $copy['title short'] = $copy['field']['title short'] = t('@label Updated', array('@label' => t($field['widget']['label']))); + + $copy['field']['field'] = $field['field_name'] .'_timestamp'; + $copy['field']['click sortable'] = TRUE; + $copy['field']['handler'] = 'views_handler_field_date'; + + // no arg, sort, or filter + // @todo put back filter...? [sort seems to be handled automatically] + unset($copy['argument'], $copy['sort'], $copy['filter']); + + $data[$table_alias][$field['field_name'] .'_timestamp'] = $copy; + } + + break; + } + +} + + +/** + * Implementation of hook_views_handlers(). + */ +function computed_field_extra_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'computed_field_extra') . '/views', + ), + 'handlers' => array( + 'views_handler_field_serialized_list' => array( + 'parent' => 'views_handler_field', + ), + ), + ); +} \ No newline at end of file diff --git computed_field_extra/views/views_handler_field_serialized_list.inc computed_field_extra/views/views_handler_field_serialized_list.inc new file mode 100644 index 0000000..e7df2c9 --- /dev/null +++ computed_field_extra/views/views_handler_field_serialized_list.inc @@ -0,0 +1,34 @@ +{$this->field_alias}; + + if (! empty($serialized)) { + $value = unserialize($serialized); + if ($value === FALSE) $value = ''; + } + + if (is_array($value)) { + $value = implode('
', $value); + } + + return $value; + } + + function allow_advanced_render() { + return FALSE; + } + +} \ No newline at end of file