|  | @@ -18,6 +18,7 @@ require('api/tripal_analysis.api.inc');
 | 
	
		
			
				|  |  |  require('includes/tripal_analysis_privacy.inc');
 | 
	
		
			
				|  |  |  require('includes/tripal_analysis.admin.inc');
 | 
	
		
			
				|  |  |  require('includes/tripal_analysis.form.inc');
 | 
	
		
			
				|  |  | +require('includes/tripal_analysis.sync.inc');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -57,40 +58,45 @@ function tripal_analysis_node_info() {
 | 
	
		
			
				|  |  |  function tripal_analysis_menu() {
 | 
	
		
			
				|  |  |    //Sync analysis
 | 
	
		
			
				|  |  |    $items['chado_sync_analyses'] = array(
 | 
	
		
			
				|  |  | -     'title' => 'Sync Data',
 | 
	
		
			
				|  |  | -     'page callback' => 'tripal_analysis_sync_analyses',
 | 
	
		
			
				|  |  | -     'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | -     'type' => MENU_CALLBACK
 | 
	
		
			
				|  |  | +    'title' => 'Sync Data',
 | 
	
		
			
				|  |  | +    'page callback' => 'tripal_analysis_sync_analyses',
 | 
	
		
			
				|  |  | +    'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | +    'type' => MENU_CALLBACK
 | 
	
		
			
				|  |  |    );
 | 
	
		
			
				|  |  |    // Tripal Analysis administrative settings
 | 
	
		
			
				|  |  |    $items['admin/tripal/chado/tripal_analysis'] = array(
 | 
	
		
			
				|  |  | -      'title' => 'Analyses',
 | 
	
		
			
				|  |  | -      'description' => 'A bioinformatics analysis producing features.',
 | 
	
		
			
				|  |  | -      'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | -      'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  | +    'title' => 'Analyses',
 | 
	
		
			
				|  |  | +    'description' => 'A bioinformatics analysis producing features.',
 | 
	
		
			
				|  |  | +    'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | +    'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  |    );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    $items['admin/tripal/chado/tripal_analysis/help'] = array(
 | 
	
		
			
				|  |  | -      'title' => 'Help',
 | 
	
		
			
				|  |  | -      'description' => "A description of the Tripal Analysis module including a short description of it's usage.",
 | 
	
		
			
				|  |  | -      'page callback' => 'theme',
 | 
	
		
			
				|  |  | -      'page arguments' => array('tripal_analysis_help'),
 | 
	
		
			
				|  |  | -      'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | -      'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  | -      'file' => 'includes/tripal_analysis.admin.inc',
 | 
	
		
			
				|  |  | -      'weight' => 10
 | 
	
		
			
				|  |  | +    'title' => 'Help',
 | 
	
		
			
				|  |  | +    'description' => "A description of the Tripal Analysis module including a short description of it's usage.",
 | 
	
		
			
				|  |  | +    'page callback' => 'theme',
 | 
	
		
			
				|  |  | +    'page arguments' => array('tripal_analysis_help'),
 | 
	
		
			
				|  |  | +    'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | +    'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  |    );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    $items['admin/tripal/chado/tripal_analysis/configuration'] = array(
 | 
	
		
			
				|  |  | -      'title' => 'Configuration',
 | 
	
		
			
				|  |  | -      'description' => 'Settings for the displays of analysis results.',
 | 
	
		
			
				|  |  | -      'page callback' => 'drupal_get_form',
 | 
	
		
			
				|  |  | -      'page arguments' => array('tripal_analysis_help'),
 | 
	
		
			
				|  |  | -      'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | -      'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  | -      'file' => 'includes/tripal_analysis.admin.inc',
 | 
	
		
			
				|  |  | +    'title' => 'Configuration',
 | 
	
		
			
				|  |  | +    'description' => 'Settings for the displays of analysis results.',
 | 
	
		
			
				|  |  | +    'page callback' => 'drupal_get_form',
 | 
	
		
			
				|  |  | +    'page arguments' => array('tripal_analysis_admin'),
 | 
	
		
			
				|  |  | +    'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | +    'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +  $items['admin/tripal/chado/tripal_analysis/sync'] = array(
 | 
	
		
			
				|  |  | +    'title' => 'Sync Analyses',
 | 
	
		
			
				|  |  | +    'description' => 'Sync Chado analyses with Drupal.',
 | 
	
		
			
				|  |  | +    'page callback' => 'drupal_get_form',
 | 
	
		
			
				|  |  | +    'page arguments' => array('tripal_analysis_sync_form'),
 | 
	
		
			
				|  |  | +    'access arguments' => array('administer tripal analyses'),
 | 
	
		
			
				|  |  | +    'type' => MENU_NORMAL_ITEM,
 | 
	
		
			
				|  |  |    );
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    $items['tripal_analysis/properties/minus/%/%'] = array(
 | 
	
		
			
				|  |  |      'page callback' => 'tripal_analysis_property_delete',
 | 
	
	
		
			
				|  | @@ -114,34 +120,197 @@ function tripal_analysis_help ($path, $arg) {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  | - *  When a new chado_analysis node is created we also need to add information
 | 
	
		
			
				|  |  | - *  to our chado_analysis table.  This function is called on insert of a new
 | 
	
		
			
				|  |  | - *  node of type 'chado_analysis' and inserts the necessary information.
 | 
	
		
			
				|  |  | + *  Set the permission types that the chado module uses.  Essentially we
 | 
	
		
			
				|  |  | + *  want permissionis that protect creation, editing and deleting of chado
 | 
	
		
			
				|  |  | + *  data objects
 | 
	
		
			
				|  |  |   *
 | 
	
		
			
				|  |  |   * @ingroup tripal_analysis
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -function chado_analysis_insert($node) {
 | 
	
		
			
				|  |  | -  global $user;
 | 
	
		
			
				|  |  | +function tripal_analysis_permission() {
 | 
	
		
			
				|  |  | +  return array(
 | 
	
		
			
				|  |  | +    'access chado_analysis content' => array(
 | 
	
		
			
				|  |  | +      'title' => t('View Analyses'),
 | 
	
		
			
				|  |  | +      'description' => t('Allow users to view analysis pages.'),
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'create chado_analysis content' => array(
 | 
	
		
			
				|  |  | +      'title' => t('Create Analyses'),
 | 
	
		
			
				|  |  | +      'description' => t('Allow users to create new analysis pages.'),
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'delete chado_analysis content' => array(
 | 
	
		
			
				|  |  | +      'title' => t('Delete Analyses'),
 | 
	
		
			
				|  |  | +      'description' => t('Allow users to delete analysis pages.'),
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'edit chado_analysis content' => array(
 | 
	
		
			
				|  |  | +      'title' => t('Edit Analyses'),
 | 
	
		
			
				|  |  | +      'description' => t('Allow users to edit analysis pages.'),
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'adminster tripal analysis' => array(
 | 
	
		
			
				|  |  | +      'title' => t('Administer Analyses'),
 | 
	
		
			
				|  |  | +      'description' => t('Allow users to administer all analyses.'),
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  // Create a timestamp so we can insert it into the chado database
 | 
	
		
			
				|  |  | -  $time  = $node->timeexecuted;
 | 
	
		
			
				|  |  | -  $month = $time['month'];
 | 
	
		
			
				|  |  | -  $day   = $time['day'];
 | 
	
		
			
				|  |  | -  $year  = $time['year'];
 | 
	
		
			
				|  |  | -  $timestamp = $month . '/' . $day . '/' . $year;
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *  We need to let drupal know about our theme functions and their arguments.
 | 
	
		
			
				|  |  | + *  We create theme functions to allow users of the module to customize the
 | 
	
		
			
				|  |  | + *  look and feel of the output generated in this module
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function tripal_analysis_theme($existing, $type, $theme, $path) {
 | 
	
		
			
				|  |  | +  $core_path = drupal_get_path('module', 'tripal_core');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
 | 
	
		
			
				|  |  | +  $items = array(
 | 
	
		
			
				|  |  | +    'node__chado_analysis' => array(
 | 
	
		
			
				|  |  | +      'template' => 'node--chado-generic',
 | 
	
		
			
				|  |  | +      'render element' => 'node',
 | 
	
		
			
				|  |  | +      'base hook' => 'node',
 | 
	
		
			
				|  |  | +      'path' => "$core_path/theme",
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'tripal_analysis_base' => array(
 | 
	
		
			
				|  |  | +      'variables' => array('node' => NULL),
 | 
	
		
			
				|  |  | +      'template' => 'tripal_analysis_base',
 | 
	
		
			
				|  |  | +      'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'tripal_feature_analyses' => array(
 | 
	
		
			
				|  |  | +      'template' => 'tripal_feature_analyses',
 | 
	
		
			
				|  |  | +      'variables' =>  array('node' => NULL),
 | 
	
		
			
				|  |  | +      'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'tripal_analysis_properties' => array(
 | 
	
		
			
				|  |  | +      'variables' => array('node' => NULL),
 | 
	
		
			
				|  |  | +      'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'tripal_analysis_help' => array(
 | 
	
		
			
				|  |  | +      'template' => 'tripal_analysis_help',
 | 
	
		
			
				|  |  | +      'variables' =>  array(NULL),
 | 
	
		
			
				|  |  | +      'path' => "$path/theme",
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +    'chado_analysis_node_form' => array(
 | 
	
		
			
				|  |  | +      'variables' => array('form'),
 | 
	
		
			
				|  |  | +      'path' => $theme_path,
 | 
	
		
			
				|  |  | +    ),
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  return $items;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function tripal_analysis_block_info() {
 | 
	
		
			
				|  |  | +  $blocks['base']['info'] = t('Tripal Analysis Details');
 | 
	
		
			
				|  |  | +  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
 | 
	
		
			
				|  |  | +  $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  return $blocks;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function tripal_analysis_block_view($delta = '') {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
 | 
	
		
			
				|  |  | +    $nid = arg(1);
 | 
	
		
			
				|  |  | +    $node = node_load($nid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  // If this analysis already exists then don't recreate it in chado
 | 
	
		
			
				|  |  | -  $analysis_id = $node->analysis_id;
 | 
	
		
			
				|  |  | -  if ($analysis_id) {
 | 
	
		
			
				|  |  | -    $values = array('analysis_id' => $node->analysis_id);
 | 
	
		
			
				|  |  | -    $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
 | 
	
		
			
				|  |  | -    if ($result and count($result) > 0) {
 | 
	
		
			
				|  |  | -      $analysis = $result[0];
 | 
	
		
			
				|  |  | +    $block = array();
 | 
	
		
			
				|  |  | +    switch ($delta) {
 | 
	
		
			
				|  |  | +      case 'base':
 | 
	
		
			
				|  |  | +        $block['subject'] = t('Analysis Details');
 | 
	
		
			
				|  |  | +        $block['content'] = theme('tripal_analysis_base', $node);
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +      case 'tripal_feature_analyses':
 | 
	
		
			
				|  |  | +        $block['subject'] = t('Feature Analyses');
 | 
	
		
			
				|  |  | +        $block['content'] = theme('tripal_feature_analyses', $node);
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +      default :
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    return $block;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_feature
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function tripal_analysis_node_view($node, $view_mode, $langcode) {
 | 
	
		
			
				|  |  | +  switch ($node->type) {
 | 
	
		
			
				|  |  | +    case 'chado_analysis':
 | 
	
		
			
				|  |  | +      // Show feature browser and counts
 | 
	
		
			
				|  |  | +      if ($view_mode == 'full') {
 | 
	
		
			
				|  |  | +        $node->content['tripal_analysis_base'] = array(
 | 
	
		
			
				|  |  | +          '#value' => theme('tripal_analysis_base', array('node' => $node)),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +        $node->content['tripal_analysis_properties'] = array(
 | 
	
		
			
				|  |  | +          '#value' => theme('tripal_analysis_properties', array('node' => $node)),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      break;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * Implements hook_views_api()
 | 
	
		
			
				|  |  | + * Purpose: Essentially this hook tells drupal that there is views support for
 | 
	
		
			
				|  |  | + *  for this module which then includes tripal_analysis.views.inc where all the
 | 
	
		
			
				|  |  | + *  views integration code is
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function tripal_analysis_views_api() {
 | 
	
		
			
				|  |  | +  return array(
 | 
	
		
			
				|  |  | +    'api' => 2.0,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/*
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | +*/
 | 
	
		
			
				|  |  | +function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
 | 
	
		
			
				|  |  | +  if ($form_id == "chado_analysis_node_form") {
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *  When a new chado_analysis node is created we also need to add information
 | 
	
		
			
				|  |  | + *  to our chado_analysis table.  This function is called on insert of a new
 | 
	
		
			
				|  |  | + *  node of type 'chado_analysis' and inserts the necessary information.
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function chado_analysis_insert($node) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  // If the analysis doesn't exist then let's create it in chado.
 | 
	
		
			
				|  |  | -  if (!$analysis) {
 | 
	
		
			
				|  |  | +  $node->analysisname = trim($node->analysisname);
 | 
	
		
			
				|  |  | +  $node->description = trim($node->description);
 | 
	
		
			
				|  |  | +  $node->program = trim($node->program);
 | 
	
		
			
				|  |  | +  $node->programversion = trim($node->programversion);
 | 
	
		
			
				|  |  | +  $node->algorithm = trim($node->algorithm);
 | 
	
		
			
				|  |  | +  $node->sourcename = trim($node->sourcename);
 | 
	
		
			
				|  |  | +  $node->sourceversion = trim($node->sourceversion);
 | 
	
		
			
				|  |  | +  $node->sourceuri = trim($node->sourceuri);
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +  // if there is an analysis_id in the $node object then this must be a sync so
 | 
	
		
			
				|  |  | +  // we can skip adding the analysis as it is already there, although
 | 
	
		
			
				|  |  | +  // we do need to proceed with the rest of the insert
 | 
	
		
			
				|  |  | +  if (!property_exists($node,'analysis_id')) {
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    // Create a timestamp so we can insert it into the chado database
 | 
	
		
			
				|  |  | +    $time  = $node->timeexecuted;
 | 
	
		
			
				|  |  | +    $month = $time['month'];
 | 
	
		
			
				|  |  | +    $day   = $time['day'];
 | 
	
		
			
				|  |  | +    $year  = $time['year'];
 | 
	
		
			
				|  |  | +    $timestamp = $month . '/' . $day . '/' . $year;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |      // insert and then get the newly inserted analysis record
 | 
	
		
			
				|  |  |      $values = array(
 | 
	
		
			
				|  |  |        'name'           => $node->analysisname,
 | 
	
	
		
			
				|  | @@ -154,37 +323,28 @@ function chado_analysis_insert($node) {
 | 
	
		
			
				|  |  |        'sourceuri'      => $node->sourceuri,
 | 
	
		
			
				|  |  |        'timeexecuted'   => $timestamp
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  | -    if (tripal_core_chado_insert('analysis', $values)) {
 | 
	
		
			
				|  |  | -      $analysis = tripal_core_chado_select('analysis', array('*'), $values);
 | 
	
		
			
				|  |  | -      $analysis_id = $analysis[0]->analysis_id;
 | 
	
		
			
				|  |  | +    $analysis = tripal_core_chado_insert('analysis', $values);
 | 
	
		
			
				|  |  | +    if (!$analysis) {
 | 
	
		
			
				|  |  | +      drupal_set_message(t('Unable to add analysis.', 'warning'));
 | 
	
		
			
				|  |  | +      watchdog('tripal_analysis', 'Insert analysis: Unable to create analysis where values:%values',
 | 
	
		
			
				|  |  | +      array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
 | 
	
		
			
				|  |  | +      return;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    $analysis_id = $analysis['analysis_id'];
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +  else {
 | 
	
		
			
				|  |  | +    $analysis_id = $node->analysis_id;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    // Make sure the entry for this analysis doesn't already exist in the
 | 
	
		
			
				|  |  |    // chado_analysis table if it doesn't exist then we want to add it.
 | 
	
		
			
				|  |  | -  $node_check_sql = "SELECT * FROM {chado_analysis} " .
 | 
	
		
			
				|  |  | -                    "WHERE analysis_id = :analysis_id";
 | 
	
		
			
				|  |  | -  $node_check = db_query($node_check_sql, array(':analysis_id' => $analysis_id))->fetchObject();
 | 
	
		
			
				|  |  | -  if (!$node_check) {
 | 
	
		
			
				|  |  | -    // next add the item to the drupal table
 | 
	
		
			
				|  |  | -    $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) " .
 | 
	
		
			
				|  |  | -           "VALUES (:nid, :vid, :analysis_id)";
 | 
	
		
			
				|  |  | -    db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':analysis_id' => $analysis_id));
 | 
	
		
			
				|  |  | -    // Create a title for the analysis node using the unique keys so when the
 | 
	
		
			
				|  |  | -    // node is saved, it will have a title
 | 
	
		
			
				|  |  | +  $check_org_id = chado_get_id_for_node('analysis', $node->nid);  
 | 
	
		
			
				|  |  | +  if (!$check_org_id) {
 | 
	
		
			
				|  |  |      $record = new stdClass();
 | 
	
		
			
				|  |  | -    // If the analysis has a name, use it as the node title. If not, construct
 | 
	
		
			
				|  |  | -    // the title using program, programversion, and sourcename
 | 
	
		
			
				|  |  | -    if ($node->analysisname) {
 | 
	
		
			
				|  |  | -      $record->title = $node->analysisname;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    else {
 | 
	
		
			
				|  |  | -      //Construct node title as "program (version)
 | 
	
		
			
				|  |  | -      $record->title = "$node->program ($node->programversion)";
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |      $record->nid = $node->nid;
 | 
	
		
			
				|  |  | -    drupal_write_record('node', $record, 'nid');
 | 
	
		
			
				|  |  | -    drupal_write_record('node_revisions', $record, 'nid');
 | 
	
		
			
				|  |  | +    $record->vid = $node->vid;
 | 
	
		
			
				|  |  | +    $record->analysis_id = $analysis_id;
 | 
	
		
			
				|  |  | +    drupal_write_record('chado_analysis', $record);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // add the analysis to the node object for
 | 
	
	
		
			
				|  | @@ -261,17 +421,11 @@ function chado_analysis_delete($node) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
 | 
	
		
			
				|  |  | -  $sql_del = "DELETE FROM {chado_analysis} " .
 | 
	
		
			
				|  |  | -              "WHERE nid = :nid " .
 | 
	
		
			
				|  |  | -              "AND vid = :vid";
 | 
	
		
			
				|  |  | +  $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
 | 
	
		
			
				|  |  |    db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 | 
	
		
			
				|  |  | -  $sql_del = "DELETE FROM {node} " .
 | 
	
		
			
				|  |  | -              "WHERE nid = :nid " .
 | 
	
		
			
				|  |  | -              "AND vid = :vid";
 | 
	
		
			
				|  |  | +  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
 | 
	
		
			
				|  |  |    db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 | 
	
		
			
				|  |  | -  $sql_del = "DELETE FROM {node_revision} " .
 | 
	
		
			
				|  |  | -              "WHERE nid = :nid " .
 | 
	
		
			
				|  |  | -              "AND vid = :vid";
 | 
	
		
			
				|  |  | +  $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
 | 
	
		
			
				|  |  |    db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    //Remove from analysis and analysisprop tables of chado database as well
 | 
	
	
		
			
				|  | @@ -287,7 +441,15 @@ function chado_analysis_delete($node) {
 | 
	
		
			
				|  |  |   * @ingroup tripal_analysis
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  function chado_analysis_update($node) {
 | 
	
		
			
				|  |  | -  global $user;
 | 
	
		
			
				|  |  | +  $node->analysisname = trim($node->analysisname);
 | 
	
		
			
				|  |  | +  $node->description = trim($node->description);
 | 
	
		
			
				|  |  | +  $node->program = trim($node->program);
 | 
	
		
			
				|  |  | +  $node->programversion = trim($node->programversion);
 | 
	
		
			
				|  |  | +  $node->algorithm = trim($node->algorithm);
 | 
	
		
			
				|  |  | +  $node->sourcename = trim($node->sourcename);
 | 
	
		
			
				|  |  | +  $node->sourceversion = trim($node->sourceversion);
 | 
	
		
			
				|  |  | +  $node->sourceuri = trim($node->sourceuri);
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |    if ($node->revision) {
 | 
	
		
			
				|  |  |      // TODO -- decide what to do about revisions
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -429,17 +591,21 @@ function chado_analysis_update($node) {
 | 
	
		
			
				|  |  |    *
 | 
	
		
			
				|  |  |    * @ingroup tripal_analysis
 | 
	
		
			
				|  |  |    */
 | 
	
		
			
				|  |  | -function chado_analysis_load($node) {
 | 
	
		
			
				|  |  | +function chado_analysis_load($nodes) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -   // get the feature details from chado
 | 
	
		
			
				|  |  | -  $analysis_id = chado_get_id_for_node('analysis', $node->nid);
 | 
	
		
			
				|  |  | +  foreach ($nodes as $nid => $node) {
 | 
	
		
			
				|  |  | +    // find the analysis and add in the details
 | 
	
		
			
				|  |  | +    $analysis_id = chado_get_id_for_node('analysis', $nid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  $values = array('analysis_id' => $analysis_id);
 | 
	
		
			
				|  |  | -  $analysis = tripal_core_generate_chado_var('analysis', $values);
 | 
	
		
			
				|  |  | +    // build the analysis variable
 | 
	
		
			
				|  |  | +    $values = array('analysis_id' => $analysis_id);
 | 
	
		
			
				|  |  | +    $analysis = tripal_core_generate_chado_var('analysis', $values);
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  $additions = new stdClass();
 | 
	
		
			
				|  |  | -  $additions->analysis = $analysis;
 | 
	
		
			
				|  |  | -  return $additions;
 | 
	
		
			
				|  |  | +    // add in the description field
 | 
	
		
			
				|  |  | +    $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
 | 
	
		
			
				|  |  | +    $nodes[$nid]->analysis = $analysis;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -515,164 +681,3 @@ function chado_analysis_node_access($node, $op, $account) {
 | 
	
		
			
				|  |  |    return NULL;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - *  Set the permission types that the chado module uses.  Essentially we
 | 
	
		
			
				|  |  | - *  want permissionis that protect creation, editing and deleting of chado
 | 
	
		
			
				|  |  | - *  data objects
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_permission() {
 | 
	
		
			
				|  |  | -  return array(
 | 
	
		
			
				|  |  | -    'access chado_analysis content' => array(
 | 
	
		
			
				|  |  | -      'title' => t('View Analyses'),
 | 
	
		
			
				|  |  | -      'description' => t('Allow users to view analysis pages.'),
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'create chado_analysis content' => array(
 | 
	
		
			
				|  |  | -      'title' => t('Create Analyses'),
 | 
	
		
			
				|  |  | -      'description' => t('Allow users to create new analysis pages.'),
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'delete chado_analysis content' => array(
 | 
	
		
			
				|  |  | -      'title' => t('Delete Analyses'),
 | 
	
		
			
				|  |  | -      'description' => t('Allow users to delete analysis pages.'),
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'edit chado_analysis content' => array(
 | 
	
		
			
				|  |  | -      'title' => t('Edit Analyses'),
 | 
	
		
			
				|  |  | -      'description' => t('Allow users to edit analysis pages.'),
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'adminster tripal analysis' => array(
 | 
	
		
			
				|  |  | -      'title' => t('Administer Analyses'),
 | 
	
		
			
				|  |  | -      'description' => t('Allow users to administer all analyses.'),
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -  );
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - *  We need to let drupal know about our theme functions and their arguments.
 | 
	
		
			
				|  |  | - *  We create theme functions to allow users of the module to customize the
 | 
	
		
			
				|  |  | - *  look and feel of the output generated in this module
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_theme($existing, $type, $theme, $path) {
 | 
	
		
			
				|  |  | -  $core_path = drupal_get_path('module', 'tripal_core');
 | 
	
		
			
				|  |  | -  
 | 
	
		
			
				|  |  | -  $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
 | 
	
		
			
				|  |  | -  $items = array(
 | 
	
		
			
				|  |  | -    'node__chado_analysis' => array(
 | 
	
		
			
				|  |  | -      'template' => 'node--chado-generic',
 | 
	
		
			
				|  |  | -      'render element' => 'node',
 | 
	
		
			
				|  |  | -      'base hook' => 'node',
 | 
	
		
			
				|  |  | -      'path' => "$core_path/theme",
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'tripal_analysis_base' => array(
 | 
	
		
			
				|  |  | -      'variables' => array('node' => NULL),
 | 
	
		
			
				|  |  | -      'template' => 'tripal_analysis_base',
 | 
	
		
			
				|  |  | -      'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'tripal_feature_analyses' => array(
 | 
	
		
			
				|  |  | -      'template' => 'tripal_feature_analyses',
 | 
	
		
			
				|  |  | -      'variables' =>  array('node' => NULL),
 | 
	
		
			
				|  |  | -      'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -   'tripal_analysis_properties' => array(
 | 
	
		
			
				|  |  | -     'variables' => array('node' => NULL),
 | 
	
		
			
				|  |  | -     'path' => "$path/theme/tripal_analysis",
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'tripal_analysis_help' => array(
 | 
	
		
			
				|  |  | -      'template' => 'tripal_analysis_help',
 | 
	
		
			
				|  |  | -      'variables' =>  array(NULL),
 | 
	
		
			
				|  |  | -      'path' => "$path/theme",
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -    'chado_analysis_node_form' => array(
 | 
	
		
			
				|  |  | -      'variables' => array('form'),
 | 
	
		
			
				|  |  | -      'path' => $theme_path,
 | 
	
		
			
				|  |  | -    ),
 | 
	
		
			
				|  |  | -  );
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  return $items;
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_block_info() {
 | 
	
		
			
				|  |  | -  $blocks['base']['info'] = t('Tripal Analysis Details');
 | 
	
		
			
				|  |  | -  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
 | 
	
		
			
				|  |  | -  $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  return $blocks;
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_block_view($delta = '') {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
 | 
	
		
			
				|  |  | -    $nid = arg(1);
 | 
	
		
			
				|  |  | -    $node = node_load($nid);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    $block = array();
 | 
	
		
			
				|  |  | -    switch ($delta) {
 | 
	
		
			
				|  |  | -      case 'base':
 | 
	
		
			
				|  |  | -        $block['subject'] = t('Analysis Details');
 | 
	
		
			
				|  |  | -        $block['content'] = theme('tripal_analysis_base', $node);
 | 
	
		
			
				|  |  | -        break;
 | 
	
		
			
				|  |  | -      case 'tripal_feature_analyses':
 | 
	
		
			
				|  |  | -        $block['subject'] = t('Feature Analyses');
 | 
	
		
			
				|  |  | -        $block['content'] = theme('tripal_feature_analyses', $node);
 | 
	
		
			
				|  |  | -        break;
 | 
	
		
			
				|  |  | -      default :
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    return $block;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * Implements hook_node_view()
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_node_view($node, $view_mode, $langcode) {
 | 
	
		
			
				|  |  | -  if ($node->type == 'chado_feature') {
 | 
	
		
			
				|  |  | -    if ($view_mode == 'search_index') {
 | 
	
		
			
				|  |  | -       // return results for searching
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    if ($view_mode == 'full') {
 | 
	
		
			
				|  |  | -       // return normal results
 | 
	
		
			
				|  |  | -       $node->content['tripal_feature_analyses'] = array(
 | 
	
		
			
				|  |  | -         '#markup' => theme('tripal_feature_analyses',  $node),
 | 
	
		
			
				|  |  | -       );
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - * Implements hook_views_api()
 | 
	
		
			
				|  |  | - * Purpose: Essentially this hook tells drupal that there is views support for
 | 
	
		
			
				|  |  | - *  for this module which then includes tripal_analysis.views.inc where all the
 | 
	
		
			
				|  |  | - *  views integration code is
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * @ingroup tripal_analysis
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_views_api() {
 | 
	
		
			
				|  |  | -    return array(
 | 
	
		
			
				|  |  | -    'api' => 2.0,
 | 
	
		
			
				|  |  | -  );
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -/*
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
 | 
	
		
			
				|  |  | -  if ($form_id == "chado_analysis_node_form") {
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -}
 |