<?php

/**
 *  @file
 * This file contains the basic functions needed for this drupal module.
 * The drupal tripal_genetic module maps directly to the chado X module.
 *
 * For documentation regarding the Chado X module:
 * @see http://gmod.org/wiki/Chado_General_Module
 */

require('tripal_genetic.api.inc');

/*************************************************************************
 * Implements hook_views_api()
 * Purpose: Essentially this hook tells drupal that there is views support for
 *  for this module which then includes tripal_genetic.views.inc where all the
 *  views integration code is
 */
function tripal_genetic_views_api() {
  return array(
      'api' => 2.0,
  );
}

function tripal_genetic_theme() {
  return array(
    'tripal_feature_genotypes' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_genotypes',
    ),
  );
}

/**
 *
 */
function tripal_genetic_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':
      if ($node->type == 'chado_feature') {
        if (!isset($node->content['tripal_feature_genotypes'])) {
          $node->content['tripal_feature_genotypes'] = array(
             '#value' => theme('tripal_feature_genotypes', $node),
          );
        }
      }
  }
}

/**
 *
 */
function tripal_genetic_preprocess_tripal_feature_genotypes(&$variables) {
    $feature = $variables['node']->feature;
    $variables['tripal_feature']['genotypes'] = tripal_genetic_get_genotypes_by_feature_id($feature->feature_id);
}