<?php

// $Id: sciencecommons_geneproxy.module $

/**
 * @file
 * sciencecommons_geneproxy module
 */

module_load_include("php", "sciencecommons_geneproxy", "ScienceCommonsGeneProxyModule");


/**
 * Implementation of hook_menu().
 */
function sciencecommons_geneproxy_menu () {
  return sciencecommons_geneproxy()->menu();
}

/**
 * Implementation of hook_perm()
 */
function sciencecommons_geneproxy_perm () {
  return sciencecommons_geneproxy()->perm();
}

/**
 * Implementation of hook_search()
 */
function sciencecommons_geneproxy_search ($op = 'search', $keys = NULL) {
  return sciencecommons_geneproxy()->search($op, $keys);
}

/**
 * Implementation of hook_nodeproxy_info().
 */
function sciencecommons_geneproxy_nodeproxy_info () {
  $info = array();
  $info[] = array(
    'name' => variable_get('sciencecommons_geneproxy_proxyname', t('ScienceCommons RDF Entrez Gene database')),
    // default to 24 hrs
    'expires' => variable_get('sciencecommons_geneproxy_expires_sec', (60 * 60 * 24)),
    'source' => variable_get('sciencecommons_geneproxy_sparql_url', 'http://sparql.neurocommons.org:8890/sparql/'),
    'type' => 'gene',
    'idtype' => 'sc_uri',
    'coverage' => 'primary',
    // 'fields' not used yet...
    'fields' => array(
      'title' => NODEPROXY_READONLY,
      'body' => NODEPROXY_READONLY,
    ),
    'weight' => 0
  );
  return $info;
}


/**
 * admin form
 */
function sciencecommons_geneproxy_admin_settings_form () {
  $form['default_menu']['sciencecommons_geneproxy_proxyname'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => variable_get('sciencecommons_geneproxy_proxyname', t('ScienceCommons RDF Entrez Gene database')),
    '#description' => t('User-friendly name for this NodeProxy (for use in warning messages).')
  );
  $form['default_menu']['sciencecommons_geneproxy_sparql_url'] = array(
    '#type' => 'textfield',
    '#title' => t('SPARQL Endpoint URL'),
    '#default_value' => variable_get('sciencecommons_geneproxy_sparql_url', 'http://sparql.neurocommons.org:8890/sparql/'),
    '#description' => t('URL for SPARQL queries to this database.')
  );
  $form['default_menu']['sciencecommons_geneproxy_expires_sec'] = array(
    '#type' => 'select',
    '#title' => t('Expiration time'),
    '#options' => array(
      '60' => t('1 minute'),
      '3600' => t('1 hour'),
      '14400' => t('4 hours'),
      '86400' => t('24 hours'),
      '0' => t('Never (manual)')
    ),
    '#default_value' => variable_get('sciencecommons_geneproxy_expires_sec', '3600'),
    '#description' => t('How often should proxied information be refreshed?')
  );

  return system_settings_form($form);
}


/**
 * Implementation of nodeproxy module's hook_nodeproxy_lookup ().
 */
function sciencecommons_geneproxy_nodeproxy_lookup (&$node, $info) {
  return sciencecommons_geneproxy()->proxyLookup($node, $info);
}

/**
 * Implementation of nodeproxy module's hook_nodeproxy_sync ().
 */
function sciencecommons_geneproxy_nodeproxy_sync (&$node, $info) {
  return sciencecommons_geneproxy()->proxySync($node, $info);
}

/**
 * Implementation of nodeproxy module's hook_nodeproxy_affect_node_form ().
 */
function sciencecommons_geneproxy_nodeproxy_affect_node_form (&$form, $info) {
  return sciencecommons_geneproxy()->proxyAffectNodeForm($form, $info);
}