Index: noderelationships.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/noderelationships/Attic/noderelationships.install,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 noderelationships.install
--- noderelationships.install	27 Jul 2010 04:08:34 -0000	1.1.2.10
+++ noderelationships.install	21 Feb 2011 17:24:19 -0000
@@ -109,6 +109,7 @@ function noderelationships_schema() {
         'size' => 'medium',
         'not null' => TRUE,
         'description' => 'Relation settings (serialized).',
+        'serialize' => TRUE,
       ),
     ),
     'primary key' => array('type_name', 'relation_type', 'related_type', 'field_name'),
@@ -117,6 +118,30 @@ function noderelationships_schema() {
       'related_field_relation' => array('related_type', 'field_name', 'relation_type'),
       'field_name' => array('field_name'),
     ),
+    // CTools export support.
+    'export' => array(
+      'keys' => array('type_name', 'relation_type', 'related_type', 'field_name'),
+      'key' => 'type_name',
+      'key name' => 'Type',
+      'identifier' => 'noderelationship',
+      'default hook' => 'default_noderelationship',  // Function hook name.
+      'api' => array(
+        'owner' => 'noderelationships',
+        'api' => 'noderelationships',  // Base name for api include files.
+        'minimum_version' => 1,
+        'current_version' => 1,
+      ),
+      // Optional callbacks:
+      'list callback' => 'noderelationships_ctools_export_list',
+      'load callback' => 'noderelationships_ctools_export_load',
+      'load all callback' => 'noderelationships_ctools_export_load_all',
+      'to hook code callback' => 'noderelationships_ctools_export_to_hook_code',
+      'delete callback' => 'noderelationships_ctools_export_delete',
+      // create callback
+      // save callback
+      // export callback
+      // import callback
+    ),
   );
   return $schema;
 }
Index: noderelationships.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/noderelationships/Attic/noderelationships.module,v
retrieving revision 1.1.2.29
diff -u -p -r1.1.2.29 noderelationships.module
--- noderelationships.module	27 Jul 2010 04:57:10 -0000	1.1.2.29
+++ noderelationships.module	21 Feb 2011 17:24:19 -0000
@@ -481,3 +481,155 @@ function _noderelationships_child_node_f
   module_load_include('inc', 'noderelationships', 'noderelationships.pages');
   _noderelationships_child_node_form_submit($form, $form_state);
 }
+
+/**
+ * CTools exportables 'list callback'.
+ */
+function noderelationships_ctools_export_list() {
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $export = $schema['export'];
+  $list = array();
+  $field_names = implode(', ', array_keys($schema['fields']));
+
+  $query = db_query("SELECT $field_names FROM {$table}");
+  while ($object = db_fetch_object($query)) {
+    // Compile a compound key name.
+    $object->__keys = _noderelationships_ctools_export_primary_keys($object);
+    $object->__compound_key = implode(':', $object->__keys);
+    
+    $list[$object->__compound_key] = $object->__compound_key;
+  }
+
+  return $list;
+}
+
+/**
+ * CTools exportables 'load callback'.
+ */
+function noderelationships_ctools_export_load($names) {
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $export = $schema['export'];
+  $objects = array();
+  $field_names = implode(', ', array_keys($schema['fields']));
+
+  // Decrypt the $name.
+  if (!is_array($names)) {
+    $names = array($names);
+  }
+
+  foreach ($names as $name) {
+    $keys = explode(':', $name);
+    $conditions = array();
+    $args = array();
+    foreach ($keys as $key => $value) {
+      $conditions[] = "{$key} = '%s'";
+      $args[] = $value;
+    }
+    $conditions = implode(' AND ', $conditions);
+    $query = db_query("SELECT $field_names FROM {$table} WHERE $conditions", $args);
+    $object = db_fetch_object($query);
+    $object->settings = unserialize($object->settings);
+    $object->__keys = _noderelationships_ctools_export_primary_keys($object);
+    $object->__compound_key = implode(':', $object->__keys);
+    $objects[] = $object;
+  }
+
+  return $objects;
+}
+
+/**
+ * CTools exportables 'load all callback'.
+ */
+function noderelationships_ctools_export_load_all($reset = FALSE) {
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $export = $schema['export'];
+  $list = array();
+  $field_names = implode(', ', array_keys($schema['fields']));
+
+  if ($reset) {
+    ctools_export_load_object_reset($table);
+  }
+
+  $query = db_query("SELECT $field_names FROM {$table}");
+  while ($object = db_fetch_object($query)) {
+    // Compile a compound key name.
+    $object->__keys = _noderelationships_ctools_export_primary_keys($object);
+    $object->__compound_key = implode(':', $object->__keys);
+    $object->table = $table;
+    $object->type = t('Normal');
+    $object->export_type = EXPORT_IN_DATABASE;
+    $object->disabled = FALSE;
+
+    $list[$object->__compound_key] = $object;
+  }
+
+  return $list;
+}
+
+/**
+ * CTools exportables 'to hook code callback'.
+ */
+function noderelationships_ctools_export_to_hook_code($names, $name) {
+  // Some redundant code, necessary to keep the customizations minimal for the
+  // rest of the function.
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $export = $schema['export'];
+
+  $output = '';
+  $objects = noderelationships_ctools_export_load($names);
+  if (!empty($objects)) {
+    $output = "/**\n";
+    $output .= " * Implementation of hook_{$export['default hook']}()\n";
+    $output .= " */\n";
+    $output .= "function " . $name . "_{$export['default hook']}() {\n";
+    $output .= "  \${$export['identifier']}s = array();\n\n";
+    foreach ($objects as $object) {
+      $output .= ctools_export_crud_export($table, $object, '  ');
+      $output .= "  \${$export['identifier']}s['" . check_plain($object->__compound_key) . "'] = \${$export['identifier']};\n\n";
+    }
+    $output .= "  return \${$export['identifier']}s;\n";
+    $output .= "}\n";
+  }
+
+  return $output;
+}
+
+/**
+ * CTools exportables 'delete callback'.
+ */
+function noderelationships_ctools_export_delete($object) {
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $conditions = array();
+  $args = array();
+
+  foreach ($schema['primary key'] as $export_key) {
+    $conditions[] = "{$export_key} = '%s'";
+    $args[] = $object->$export_key;
+  }
+  $conditions = implode(' AND ', $conditions);
+
+  // Delete the record.
+  db_query("DELETE FROM {$table} WHERE $conditions", $args);
+}
+
+/**
+ * Create an associated array of the primary key values for a given object.
+ */
+function _noderelationships_ctools_export_primary_keys($object) {
+  $table = 'noderelationships_settings';
+  $schema = ctools_export_get_schema($table);
+  $export = $schema['export'];
+
+  // Build an array of the primary 
+  $keys = array();
+  foreach ($schema['primary key'] as $export_key) {
+    $keys[$export_key] = $object->$export_key;
+  }
+
+  return $keys;
+}
