<?php
// $Id: importexportapi_comment.inc,v 1.9 2006/09/11 14:49:25 jaza Exp $

/**
 * @file
 * Implements data definitions on behalf of comment.module.
 */

/**
 * Implementation of hook_def().
 */
function comment_def() {
  $defs = array();

  $def = array(
    '#type' => 'entity',
    '#title' => t('Comment'),
    '#db_default_table' => 'comments',
    '#xml_plural' => 'comments',
    '#csv_plural' => 'comments'
  );

  $def['cid'] = array(
    '#type' => 'int',
    '#title' => t('Comment ID'),
    '#key' => TRUE,
    '#db_uses_sequences' => TRUE
  );
  $def['parent'] = array(
    '#type' => 'int',
    '#title' => t('Parent comment ID'),
    '#reference_entity' => 'comment',
    '#reference_field' => array('cid'),
    '#reference_delta' => 1,
    '#reference_parent' => FALSE,
    '#db_field_unaliased' => 'pid'
  );
  $def['nid'] = array(
    '#type' => 'int',
    '#title' => t('Node ID'),
    '#reference_entity' => 'node'
  );
  $def['uid'] = array(
    '#type' => 'int',
    '#title' => t('User ID'),
    '#reference_entity' => 'user'
  );
  $def['subject'] = array(
    '#title' => t('Subject'),
    '#alt_key_for' => 'cid'
  );
  $def['body'] = array(
    '#title' => t('Comment text'),
    '#db_field_unaliased' => 'comment'
  );
  $def['hostname'] = array(
    '#title' => t('Hostname')
  );
  $def['timestamp'] = array(
    '#type' => 'datetime',
    '#title' => t('Last modified date')
  );
  $def['score'] = array(
    '#type' => 'int',
    '#title' => t('Score')
  );
  $def['status'] = array(
    '#type' => 'int',
    '#title' => t('Published')
  );
  $def['format'] = array(
    '#type' => 'int',
    '#title' => t('Input format'),
    '#reference_entity' => 'input_format'
  );
  $def['thread'] = array(
    '#title' => t('Thread position')
  );
  $def['commenter_name'] = array(
    '#title' => t('Commenter name'),
    '#db_field_unaliased' => 'name'
  );
  $def['commenter_mail'] = array(
    '#title' => t('Commenter e-mail address'),
    '#db_field_unaliased' => 'mail'
  );
  $def['commenter_homepage'] = array(
    '#title' => t('Commenter home page'),
    '#db_field_unaliased' => 'homepage'
  );

  $defs['comment'] = $def;

  return $defs;
}

/**
 * Implementation of hook_def_alter().
 */
function comment_def_alter(&$def) {
  if (isset($def['user'])) {
    $def['user']['mode'] = array(
      '#type' => 'int',
      '#title' => t('Comment viewing mode')
    );
    $def['user']['sort'] = array(
      '#type' => 'int',
      '#title' => t('Comment viewing order')
    );
    $def['user']['signature'] = array(
      '#title' => t('Signature')
    );
  }
}

/**
 * Implementation of hook_node_def_alter().
 */
function comment_node_def_alter(&$def, $type) {
  $def['comment'] = array(
    '#type' => 'int',
    '#title' => 'Comment setting'
  );

  $def['comment_statistics_nid'] = array(
    '#type' => 'int',
    '#title' => t('Node ID'),
    '#reference_entity' => $type,
    '#reference_field' => array('nid'),
    '#db_table' => 'node_comment_statistics',
    '#db_field_unaliased' => 'nid',
    '#key_component' => TRUE,
    '#csv_hidden' => TRUE
  );
  $def['last_comment_timestamp'] = array(
    '#type' => 'datetime',
    '#title' => 'Last comment date',
    '#db_table' => 'node_comment_statistics'
  );
  $def['last_comment_name'] = array(
    '#title' => 'Last comment username',
    '#default_value' => NULL,
    '#db_table' => 'node_comment_statistics',
    '#reference_entity' => 'user',
    '#reference_field' => array('uid'),
    '#alt_key_ignore' => TRUE
  );
  $def['last_comment_uid'] = array(
    '#type' => 'int',
    '#title' => 'Last comment user ID',
    '#db_table' => 'node_comment_statistics',
    '#reference_entity' => 'user',
    '#reference_field' => array('uid')
  );
  $def['comment_count'] = array(
    '#type' => 'int',
    '#title' => 'Comment count',
    '#db_table' => 'node_comment_statistics'
  );
}

/**
 * Implementation of hook_db_def_tables().
 */
function comment_db_def_tables() {
  $tables = array();

  $tables['comments'] = 'c';
  $tables['node_comment_statistics'] = 'ncs';

  return $tables;
}
