roles) && !in_array('Moderators', $user->roles)){ if(current_path() == 'admin/workbench'){ drupal_goto('admin/workbench/my-content'); } } } function planteome_utilities_menu() { $items = array(); $items['admin/workbench/my-content'] = array( 'title' => 'My content', 'page callback' => 'custom_cgrb_my_content', 'access arguments' => array('use workbench_moderation my drafts tab') ); $items['admin/workbench/needs-review'] = array( 'title' => 'Needs Review', 'page callback' => 'custom_cgrb_needs_review_page', 'access arguments' => array('use workbench_moderation needs review tab') ); $items['admin/site-content-settings'] = array( 'title' => 'Site Content Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('cgrb_site_content_settings'), 'access arguments' => array('administer content types'), ); $items['test-bilio-add'] = array( 'title' => 'My content', 'page callback' => 'drupal_get_form', 'page arguments' => array('planteome_biblio_test_import_form'), 'access callback' => true, ); $items['test-doi-add'] = array( 'title' => 'My content', 'page callback' => 'drupal_get_form', 'page arguments' => array('planteome_biblio_test_import_doi_form'), 'access callback' => true, ); return $items; } function custom_cgrb_my_content(){ global $user; $or = db_or(); $or->condition('n.uid', $user->uid) ->condition('mh.uid', $user->uid); // $subquery = db_select('workbench_moderation_node_history','nv1'); // $subquery->addExpression('MAX(stamp)'); // $subquery->condition('nv1.uid',$user->uid) // ->groupBy('nv1.nid'); $query = db_select('node', 'n'); //$query->join('node_revision', 'nv', 'n.nid = nv.nid AND nv.uid ='.$user->uid); $query->join('workbench_moderation_node_history', 'mh', 'n.nid = mh.nid AND mh.uid='.$user->uid." AND mh.is_current = 1"); $query->join('users', 'u', 'mh.uid = u.uid'); $query->leftjoin('field_data_field_gene_id', 'fg', 'n.nid = fg.entity_id'); $query->fields('n', array('title')) ->fields('n', array('type','changed')) ->fields('mh',array('state','nid','vid','stamp')) ->fields('u',array('name')) ->fields('fg', array("field_gene_id_value")) //->condition('n.type', 'page') ->condition($or) //->condition('stamp',$subquery,'IN') ->condition('mh.is_current', 1); // Conditions based $_GET params if(isset($_GET['title']) && !empty($_GET['title'])){ $query->condition('n.title', '%'.db_like($_GET['title']).'%', 'LIKE'); } if(isset($_GET['state']) && !empty($_GET['state'])){ if($_GET['state'] != 'All'){ $query->condition('mh.state', $_GET['state'], '='); }else{ $query->condition('mh.state', array('draft','needs_review','published'), 'IN'); } } if(isset($_GET['type']) && !empty($_GET['type'])){ if($_GET['type'] != 'All'){ $query->condition('n.type', $_GET['type'], '='); }else{ $query->condition('n.type', array('gene','annotation'), 'IN'); } } $query->orderBy('mh.stamp', 'DESC'); if(isset($_GET['type']) && is_numeric($_GET['items_per_page'])){ $query = $query->extend('PagerDefault')->limit($_GET['items_per_page']); }else{ $query = $query->extend('PagerDefault')->limit(25); } $results = $query->execute()->fetchAll(); $headers = array('State', //'Set moderation state', 'Original Content Link','Revised content Link','Gene ID','Type','Revised by','Last updated'); foreach($results as $value){ $url_alias = drupal_get_path_alias('node/'.$value->nid); $revised_url = 'node/'.$value->nid.'/revisions/'.$value->vid.'/view'; $node = node_load($value->nid); $gene_id = ""; if($value->type == 'annotation'){ $query1 = db_select('field_data_field_gene','fg'); $query1->join('field_data_field_gene_id', 'fgi', 'fg.field_gene_target_id = fgi.entity_id'); $query1->fields('fgi',array("field_gene_id_value")) ->condition('fg.entity_id',$value->nid); $results1 = $query1->execute()->fetchAll(); if(!empty($results1)){ $gene_id = $results1[0]->field_gene_id_value; } }else{ $gene_id = $value->field_gene_id_value; } $rows[] = array( '
'.ucfirst($value->state).'
' .'
'.l('View moderation history','node/'.$value->nid.'/moderation').'
', //theme('links', array('links' => workbench_moderation_get_moderation_links($node, array('html' => TRUE, 'query' => array('destination' => $_GET['q']))))), l($value->title,$url_alias), l($value->title,$revised_url), $gene_id, ucfirst($value->type), $value->name, format_interval((time() - $value->changed) , 2) . t(' ago') ); } $form = drupal_get_form('planteom_mycontent_filter_form'); $output = drupal_render($form); $output .= theme('table', array('header' => $headers, 'rows' => $rows)); $output .= theme('pager'); return $output; } function planteom_mycontent_filter_form($form,$form_state){ $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['#method'] = 'get'; $form['title'] = array( '#title' => t('Title'), '#type' => 'textfield', '#size' => 20, '#prefix' => '
', '#suffix' => '
', '#default_value' => isset($_GET['title']) ? $_GET['title'] : "", ); $form['state'] = array( '#title' => t('State'), '#type' => 'select', '#options' => array( 'All' => t('- Any -'), 'draft' => t('Draft'), 'needs_review' => t('Needs Review'), 'published' => t('Published'), ), '#prefix' => '
', '#suffix' => '
', '#default_value' => isset($_GET['state']) ? $_GET['state'] : "All", ); $form['type'] = array( '#title' => t('Type'), '#type' => 'select', '#options' => array( 'All' => t('- Any -'), 'annotation' => t('Annotations'), 'gene' => t('Gene'), ), '#prefix' => '
', '#suffix' => '
', '#default_value' => isset($_GET['type']) ? $_GET['type'] : "All", ); $form['items_per_page'] = array( '#title' => t('Items per page'), '#type' => 'select', '#options' => array( 10 => '10', 25 => '25', 50 => '50', 100 => '100', 200 => '200', ), '#default_value' => isset($_GET['items_per_page']) ? $_GET['items_per_page'] : 25, '#prefix' => '
', '#suffix' => '
', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Apply'), '#prefix' => '
', '#suffix' => '
', ); return $form; } function custom_cgrb_needs_review_page(){ global $user; $user_data = user_load($user->uid); $curation_species = array(); foreach ($user_data->field_curation_species['und'] as $key => $value) { $curation_species[] = $value['target_id']; } // $or = db_or(); // $or->condition('n.uid', $user->uid) // ->condition('nv.uid', $user->uid); // $subquery = db_select('node_revision','nv1'); // $subquery->addExpression('MAX(timestamp)'); // $subquery->groupBy('nv1.nid'); $query = db_select('node', 'n'); //$query->join('node_revision', 'nv', 'n.nid = nv.nid'); $query->join('workbench_moderation_node_history', 'mh', 'n.nid = mh.nid'); $query->join('users', 'u', 'mh.uid = u.uid'); $query->join('field_data_field_ref_species', 'fs', 'fs.entity_id = n.nid'); $query->leftjoin('field_data_field_gene_id', 'fg', 'n.nid = fg.entity_id'); $query->fields('n', array('type','changed','title')) ->fields('mh',array('state','nid','vid','stamp')) ->fields('u',array('name')) ->fields('fg', array("field_gene_id_value")) //->condition('mh.is_current', 1) //->condition('timestamp',$subquery,'IN') ->condition('fs.field_ref_species_target_id',$curation_species,'IN') ->condition('mh.state','needs_review','=') ->condition('mh.is_current', 1); // Conditions based $_GET params if(isset($_GET['title']) && !empty($_GET['title'])){ $query->condition('n.title', '%'.db_like($_GET['title']).'%', 'LIKE'); } if(isset($_GET['type']) && !empty($_GET['type'])){ if($_GET['type'] != 'All'){ $query->condition('n.type', $_GET['type'], '='); }else{ $query->condition('n.type', array('gene','annotation'), 'IN'); } } $query->orderBy('mh.stamp', 'DESC'); if(isset($_GET['type']) && is_numeric($_GET['items_per_page'])){ $query = $query->extend('PagerDefault')->limit($_GET['items_per_page']); }else{ $query = $query->extend('PagerDefault')->limit(25); } $results = $query->execute()->fetchAll(); $headers = array('State', //'Set moderation state', 'Original Content Link','Revised content Link','Gene ID','Type','Revised by','Last updated'); foreach($results as $value){ $url_alias = drupal_get_path_alias('node/'.$value->nid); $revised_url = 'node/'.$value->nid.'/revisions/'.$value->vid.'/view'; $node = node_load($value->nid); $gene_id = ""; if($value->type == 'annotation'){ $query1 = db_select('field_data_field_gene','fg'); $query1->join('field_data_field_gene_id', 'fgi', 'fg.field_gene_target_id = fgi.entity_id'); $query1->fields('fgi',array("field_gene_id_value")) ->condition('fg.entity_id',$value->nid); $results1 = $query1->execute()->fetchAll(); if(!empty($results1)){ $gene_id = $results1[0]->field_gene_id_value; } }else{ $gene_id = $value->field_gene_id_value; } $rows[] = array( '
'.ucfirst($value->state).'
' .'
'.l('View moderation history','node/'.$value->nid.'/moderation').'
', //theme('links', array('links' => workbench_moderation_get_moderation_links($node, array('html' => TRUE, 'query' => array('destination' => $_GET['q']))))), l($value->title,$url_alias), l($value->title,$revised_url), $gene_id, ucfirst($value->type), $value->name, format_interval((time() - $value->changed) , 2) . t(' ago') ); } $form = drupal_get_form('planteom_needs_review_filter_form'); $output = drupal_render($form); $output .= theme('table', array('header' => $headers, 'rows' => $rows)); $output .= theme('pager'); return $output; } function planteom_needs_review_filter_form($form,$form_state){ $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['#method'] = 'get'; $form['title'] = array( '#title' => t('Title'), '#type' => 'textfield', '#size' => 20, '#prefix' => '
', '#suffix' => '
', '#default_value' => isset($_GET['title']) ? $_GET['title'] : "", ); $form['type'] = array( '#title' => t('Type'), '#type' => 'select', '#options' => array( 'All' => t('- Any -'), 'annotation' => t('Annotations'), 'gene' => t('Gene'), ), '#prefix' => '
', '#suffix' => '
', '#default_value' => isset($_GET['type']) ? $_GET['type'] : "All", ); $form['items_per_page'] = array( '#title' => t('Items per page'), '#type' => 'select', '#options' => array( 10 => '10', 25 => '25', 50 => '50', 100 => '100', 200 => '200', ), '#default_value' => isset($_GET['items_per_page']) ? $_GET['items_per_page'] : 25, '#prefix' => '
', '#suffix' => '
', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Apply'), '#prefix' => '
', '#suffix' => '
', ); return $form; } // function planteome_utilities_query_alter(QueryAlterableInterface $query) { // if($query->hasTag('WorkbenchModeration')) // } // function cafetree_form($form, &$form_state) { // //$result = $_SESSION['result']; // $form['input'] = array( // '#type' => 'textfield', // '#title' => 'Enter Ensembl genetree id', // '#default_value' => t('ENSGT00390000003602'), // '#required' => TRUE, // ); // $form['submit_button'] = array( // '#type' => 'button', // '#value' => t('Retrieve cafetree'), // '#ajax' => array( // 'callback' => 'results_ajax_callback', // 'wrapper' => 'results-div', // 'method' => 'replace', // ), // ); // $form['results'] = array( // '#type' => 'textarea', // //'#value' => $result, // '#prefix' => '
', // '#suffix' => '
', // ); // return $form; // } // function results_ajax_callback($form, $form_state) { // $genetreeID = $form_state['values']['input']; // // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/ // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, "https://rest.ensembl.org/cafe/genetree/id/".$genetreeID."?"); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // $headers = array(); // $headers[] = "Content-Type: application/json"; // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // $result = curl_exec($ch); // if (curl_errno($ch)) { // echo 'Error:' . curl_error($ch); // } // curl_close ($ch); // //$_SESSION['result'] = $result; // $form['results']['#value'] = $result; // return $form['results']; // } // function cafetree_form_validate($form, &$form_state) { // } // function cafetree_form_submit($form, &$form_state) { // } // function testing_function() { // return t('this is a test.'); // } // function testing_function2() { // // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/ // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, "https://rest.ensembl.org/cafe/genetree/id/ENSGT00390000003602?"); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // $headers = array(); // $headers[] = "Content-Type: application/json"; // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // $result = curl_exec($ch); // if (curl_errno($ch)) { // echo 'Error:' . curl_error($ch); // } // curl_close ($ch); // return t($result); // } // function access_function() { // global $user; // if (in_array('administrator', $user->roles)) { // return true; // } else { // return false; // } // } function map_1($obj){ return node_load($obj->nid)/*->title*/; } function map_2($obj){ return node_load($obj->nid)->field_ref_species; } function test($in){ return get_ontology_term_from_id($in); } function build_tree($target_id, $remaining_taxons){ $return = ''; global $base_url; foreach ($remaining_taxons as $index => $taxon){ //var_dump($taxon->field_taxon_ncbi_id[$taxon->language][0]['value']);exit; if($taxon->field_taxon_ncbi_id[$taxon->language][0]['value'] == $target_id){ if($target_id == 1){ $return.=''; } return $return; } } } function print_taxon_html_tree_string(){ $cached_tree = cache_get('taxon_tree_cgrb','cache'); //THIS NEEDS TO BE REMOVED // $cached_tree = false; if($cached_tree){ print($cached_tree->data); }else{ $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','taxon') ->propertyCondition('type',array('taxon')); $results = $query->execute(); if($results['node']){ // echo '
';var_dump($results['node']);
			$results2 = array_map("map_1", $results['node']);
			// echo '

Results 2

';var_dump($results2);
			//$taxon no longer seems needed - verify this
			$taxon_tree = return_taxon_gene_count();
			// $tree = taxon_build_tree($taxon_tree);
			cache_set('taxon_tree_cgrb',$taxon_tree,'cache',CACHE_TEMPORARY);
			print($taxon_tree);
		}
	}
	
}

function taxon_build_tree($taxon_tree){
	global $base_url;
	foreach($taxon_tree as $value){
		if(empty($value['parent'])){
			$output = "";
		}
	}

	return $output;
}

function print_ten_most_recent_genes(){

	$query = db_select('node', 'n');
	$query->join('field_data_field_gene', 'g', 'n.nid = g.entity_id');
	$query->join('field_data_field_date', 'd', 'n.nid = d.entity_id');
	$query->join('node', 'sn', 'sn.nid = g.field_gene_target_id');
	//$query->AddExpression('distinct sn.nid', 'nid');
	$result = $query
	  ->fields('sn', array('nid', 'title'))
	  ->distinct()
	  ->condition('n.type', 'annotation')
	  ->condition('n.status', '1')
	  ->orderBy('d.field_date_value', 'DESC')
	  ->range(0,10)
	  ->execute();

	$results = $result->fetchAll();
	
	$html = '

10 most recently annotated genes:

'; print($html); } function print_taxon_parent_and_child($node){ global $base_url; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','taxon') ->propertyCondition('type',array('taxon')) ->fieldCondition('field_taxon_parent', 'target_id', $node->nid); $results = $query->execute(); // $parent = node_load($node->field_taxon_parent[$node->language][0]['target_id']); // $tmp = '

None

'; // $out = '

Parent:

'; // if($parent != NULL){ // $tmp =''; // } // $out.= $tmp; $out = '

Children:

'; $tmp = '

None

'; if($results['node']){ $tmp = ''; $out.= ''; } print $out; //echo '
'; var_dump($parent);exit;
}

function return_taxon_gene_count(){
	//$query = new EntityFieldQuery();
	// $query->entityCondition('entity_type', 'node')
	// 	->entityCondition('bundle','gene')
	// 	->propertyCondition('type',array('gene'))
	// 	->fieldCondition('field_ref_species', 'target_id', $node->nid);
	// // $results = $query->execute();
	// $results = $query->count()->execute();
	$query = db_select('node','n');
	$query->leftjoin("field_data_field_gene_count","gc","gc.entity_id = n.nid");
	$query->leftjoin("field_data_field_taxon_parent","tp","tp.entity_id = n.nid");
	$query->leftjoin("field_data_field_taxon_rank","tr","tr.entity_id = n.nid");
	$all_taxons= $query->fields('n',array('nid','title'))
					->fields('gc',array('field_gene_count_value'))
					->fields('tp',array('field_taxon_parent_target_id'))
					->fields('tr',array('field_taxon_rank_tid'))
                   ->condition('n.type',"taxon",'=')
                   ->condition('n.status',1,'=')
                   ->execute()
                   ->fetchAll(); 
    
    $taxon_list = array();
    foreach($all_taxons as $value){
    	/*if($value->nid != '363'){
    		echo'
';var_dump(node_load($value->nid));exit;
    	}*/
    	$taxon_list[$value->nid]['nid'] = $value->nid;
    	$taxon_list[$value->nid]['title'] = $value->title;
    	$taxon_list[$value->nid]['gene_count'] = $value->field_gene_count_value;
    	$taxon_list[$value->nid]['parent'] = $value->field_taxon_parent_target_id;
    	$taxon_list[$value->nid]['rank'] = $value->field_taxon_rank_tid;
    }

    $taxon_tree = array();

    foreach ($taxon_list as $key => $value) {
    	if(!empty($value['parent'])){
    		if(isset($taxon_tree[$value['parent']])){
    			$taxon_tree[$value['parent']]['children'][] = $value;
    			unset($taxon_list[$key]);
    		}
    	}else{

    	}
    }

    $taxon_tree = convertToTree($taxon_list,'nid','parent','childnodes');
    $return_tree = return_html_array_tree_titles($taxon_tree, 0, 1, 1);
    // echo "
"; var_dump($return_tree);exit;
    return $return_tree['out_str'];
    /*echo "
"; print_r($taxon_list); exit;
	$q = new EntityFieldQuery();
	$q->entityCondition('entity_type', 'node')
		->entityCondition('bundle','taxon')
		->propertyCondition('type',array('taxon'))
		->fieldCondition('field_taxon_parent', 'target_id', $node->nid);
	$r = $q->execute();
	//echo '
';var_dump($r);exit;
	// if(!array_key_exists('node', $r)){
	// 	echo '
';var_dump($r);
	// }
	if(count($r) && $r['node']){
		$ret_count = 0;
		foreach($r['node'] as $child_taxon){
			$ret_count+= return_taxon_gene_count($child_taxon);
		}
		// return count($results['node'])+$ret_count;
		return $results+$ret_count;
	} else {
		// return count($results['node']);
		return $results;
	}*/
}

function return_html_array_tree_titles($array, $count, $rank_index_init, $rank_index_full){
    // echo "
"; var_dump($array);exit;
    $out_str = '
    '; $parent_count = 0; $rank_to_hide = array(11,9,7,6,13,15,14,20,17,16); //can add 5 to remove "no rank" taxons, but this cuts off the entire arabidopsis branch. Needs another look. foreach($array as $k => $v) { // echo "
    "; var_dump($v['title']);var_dump($rank_index_init);
        	// if($v['rank'] == 4 && $v['title'] == 'Eukaryota'){
        	// 	exit;
        	// }
            if(is_array($v['childnodes']) && count($v['childnodes'])) {
            	// if($v['title'] == 'Streptophyta'){
            	// 	echo'
    ';var_dump($rank_index_init);exit;
            	// }
            	if(!in_array($v['rank'], $rank_to_hide)){
            		$tmp = return_html_array_tree_titles($v['childnodes'], 0, $rank_index_init+1, $rank_index_full+1);
            	} else {
            		// exit($v['title']);
            		$tmp = return_html_array_tree_titles($v['childnodes'], 0, $rank_index_init, $rank_index_full+1);
            	}
            	// if($v['title'] == 'Viridiplantae'){
            	// 	echo'
    ';var_dump($rank_index_init);exit;
            	// }
            	
            	$cnt = $tmp['count']+(int)$v['gene_count'];
            	$parent_count+= $cnt;
            	if(in_array($v['rank'], $rank_to_hide)){
            		$class = '';
            		// $class = 'class="hide-rank"';
            		// $rank_index_init = 0;
            		$out_str.= '
  • '.$tmp['out_str'].'
  • '; }else{ $class = ''; $out_str.= '
  • '.$tmp['out_str'].'
  • '; } // $out_str.= '
  • '.$tmp['out_str'].'
  • '; // if($v['title'] == 'Oryza sativa'){ // echo "
    ";var_dump($cnt);var_dump($out_str);exit;
    		    // }
                // printArrayList($v);
                // continue;
            } else {
            	if(in_array($v['rank'], $rank_to_hide)){
            		$class = '';
            		// $class = 'class="hide-rank"';
            		// $rank_index_init = 0;
            	}else{
            		$class = '';
            		$rank_index_init = $rank_index_init+1;
            	}
            	$out_str.= '
  • '; $cnt = (int)$v['gene_count']; $parent_count+= $cnt; // echo "
    ";var_dump($out_str);exit;
            }
            // echo "
  • " . $v . "
  • "; } $out_str.= '
'; return ['out_str' => $out_str, 'count' => $parent_count]; } function convertToTree(array $flat, $idField = 'id', $parentIdField = 'parentId', $childNodesField = 'childNodes') { $indexed = array(); // first pass - get the array indexed by the primary id foreach ($flat as $row) { $indexed[$row[$idField]] = $row; $indexed[$row[$idField]][$childNodesField] = array(); } //second pass $root = null; foreach ($indexed as $id => $row) { $indexed[$row[$parentIdField]][$childNodesField][$id] =& $indexed[$id]; if (!$row[$parentIdField]) { $root = $id; } } return array($root => $indexed[$root]); } function return_ontology_summary($node){ $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','annotation') ->fieldCondition('field_gene','target_id',$node->nid,'='); // ->addTag('WorkbenchModerationPublished'); $results = $query->execute(); $aspects = array(); $out = ''; if(count($results['node'])){ foreach($results['node'] as $ann){ $annotation = node_load($ann->nid); $aspect = taxonomy_term_load($annotation->field_aspect[$annotation->language][0]['tid']); $aspects[$aspect->name][] = $annotation->field_ontology_id[$annotation->language][0]['value']; /*if(array_key_exists($aspect->name, $aspects)){ $aspects[$aspect->name][] = get_ontology_term_from_id($annotation->field_ontology_id[$annotation->language][0]['value']); } else { }*/ } if(count($aspects)){ $out.= '
'; // echo'
';
			foreach ($aspects as $aspect_name => $terms_unfiltered) {
				$terms = array_values(array_unique($terms_unfiltered));
				// $terms = $terms_unfiltered;
				// var_dump(count($terms));continue;
				$out.= '
'; } // exit; $out.= '
ASPECT ONTOLOGY TERMS
'.$aspect_name.''; for($x=0;$x';var_dump($test);exit; // echo'
';var_dump(get_ontology_id_from_term('(R,R)-butanediol dehydrogenase activity'));exit;
					// }
					// var_dump($terms);
					// var_dump($terms[$x]);continue;
					$out.= ''.get_ontology_term_from_id($terms[$x]).' ('.$terms[$x].')';
					if($x+1 < count($terms)){
						$out.= ', ';
					}
				}
				$out.= '
'; // echo'
';var_dump($out);exit;
		} else {
			$out.= '

No Onotology Summary to show

'; } } else { $out.= '

No Onotology Summary to show

'; } return $out; } function return_gene_annotations($node){ global $base_url; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','annotation') ->fieldCondition('field_gene','target_id',$node->nid,'='); $results = $query->execute(); $out = '';/*'

Annotations Table:

';*/ if(count($results['node'])){ $out.= ''; /*for($x=0;$xnid); $aspect = taxonomy_term_load($annotation->field_aspect[$annotation->language][0]['tid']); $data_source_fc_id = $annotation->field_data_source[$annotation->language][0]['value']; $data_source = entity_load('field_collection_item', array($data_source_fc_id)); $source_term = taxonomy_term_load($data_source[$data_source_fc_id]->field_source_name[$annotation->language][0]['tid']); $db = $source_term->field_machine_name['und'][0]['value']; $db_object_id = $data_source[$data_source_fc_id]->field_object_id[$annotation->language][0]['value']; $gpfid = $annotation->field_gene_product_form_id[$annotation->language][0]['value']; $qual = $annotation->field_qualifier[$annotation->language][0]['value']; $extension = $annotation->field_extension[$annotation->language][0]['value']; $evidence = taxonomy_term_load($annotation->field_evidence_code[$annotation->language][0]['tid']); $evid = $evidence->field_machine_name[$annotation->language][0]['value']; $by = $annotation->field_assigned_by[$annotation->language][0]['value']; $date = date('Y/m/d', $annotation->field_date[$annotation->language][0]['value']); $out.= ''; } $out.= '
ANNOTATION ACCESSION GENE PRODUCT FORM ID ASPECT ONTOLOGY TERMS QUALIFIER EXTENSION EVIDENCE CODE ASSIGNED BY DATE
'.$annotation->title.' '.$gpfid.' '.$aspect->name.' '.$annotation->field_ontology_id[$annotation->language][0]['value'].' - '.get_ontology_term_from_id($annotation->field_ontology_id[$annotation->language][0]['value']).' '.$qual.' '.$extension.' '.$evid.' '.$by.' '.$date.'
'; return $out; } else { return '

No annotations currently

'; } //echo'
';var_dump($results);exit;
}
function print_annotation_sources($node){
	$out = '';
	// echo '
';var_dump($node->field_db_reference);
	if(count($node->field_db_reference) && count($node->field_db_reference[$node->language])){
		//echo 'good count';
		for($x=0;$xfield_db_reference[$node->language]);$x++){
			$db_reference_fc_id = $node->field_db_reference[$node->language][$x]['value'];
			$db_reference = entity_load('field_collection_item', array($db_reference_fc_id));
			$reference_term = taxonomy_term_load($db_reference[$db_reference_fc_id]->field_source_name[$node->language][0]['tid']);
			// if($x==1){
			// 	echo '
';var_dump($reference_term);
			// }
			if($reference_term->field_machine_name['und'][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] != 'PMID'){
				//echo 'good annotation';
				$out.= '
'; if($db_reference[$db_reference_fc_id]->field_object_id[$node->language][0]['value'] != ''){ $out.= ''; } else { $out.= ''; } } } } // echo '
';var_dump($node->field_with_or_from);exit;
	if(count($node->field_with_or_from) && count($node->field_with_or_from[$node->language])){
		//echo 'good count';
		for($x=0;$xfield_with_or_from[$node->language]);$x++){
			$with_from_fc_id = $node->field_with_or_from[$node->language][$x]['value'];
			$with_from = entity_load('field_collection_item', array($with_from_fc_id));
			$reference_term = taxonomy_term_load($with_from[$with_from_fc_id]->field_source_name[$node->language][0]['tid']);
			//echo '
';var_dump($annotation->field_db_reference);
			if($reference_term->field_machine_name['und'][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] != 'PMID'){
				//echo 'good annotation';
				$out.= '
'; if($with_from[$with_from_fc_id]->field_object_id[$node->language][0]['value'] != ''){ $out.= ''; } else { $out.= ''; } } } } $out.= '
Source Name Source ID
'.$reference_term->field_machine_name['und'][0]['value'].''.$db_reference[$db_reference_fc_id]->field_object_id[$node->language][0]['value'].'
'.$reference_term->field_machine_name['und'][0]['value'].''.$with_from[$with_from_fc_id]->field_object_id[$node->language][0]['value'].'
'; print $out; } function print_gene_annotation_sources($node){ $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','annotation') ->fieldCondition('field_gene','target_id',$node->nid,'='); $results = $query->execute(); $out = '

Citations:

'; if(count($results['node'])){ $out.= '
    '; foreach($results['node'] as $ann){ $annotation = node_load($ann->nid); //var_dump($annotation); //echo '
    ';var_dump($annotation->field_with_or_from);
    
    			if(count($annotation->field_db_reference) > 0){
    				//echo 'good count';
    				for($x=0;$xfield_db_reference[$annotation->language]);$x++){
    					$db_reference_fc_id = $annotation->field_db_reference[$annotation->language][$x]['value'];
    					$db_reference = entity_load('field_collection_item', array($db_reference_fc_id));
    					$reference_term = taxonomy_term_load($db_reference[$db_reference_fc_id]->field_source_name[$annotation->language][0]['tid']);
    					// if($x==1){
    					// 	echo '
    ';var_dump($reference_term);
    					// }
    					if($reference_term->field_machine_name['und'][0]['value'] == 'PMID'){
    						$pminfoarray = pubmed_id_to_article_info($db_reference[$db_reference_fc_id]->field_object_id[$annotation->language][0]['value']);
    						$out.= '
  1. '.$pminfoarray['authors'].', '.$pminfoarray['title'].', '.$pminfoarray['journal'].', '.$pminfoarray['volume'].', '.$pminfoarray['issue'].', '.$pminfoarray['epubdate'].'
  2. '; } else if($reference_term->field_machine_name['und'][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] != 'PMID'){ //echo 'good annotation'; $out.= '
  3. '.$reference_term->field_machine_name['und'][0]['value'].', '.$db_reference[$db_reference_fc_id]->field_object_id[$annotation->language][0]['value'].'
  4. '; } } } if(count($annotation->field_with_or_from) > 0){ //echo 'good count'; for($x=0;$xfield_with_or_from[$annotation->language]);$x++){ $with_from_fc_id = $annotation->field_with_or_from[$annotation->language][$x]['value']; $with_from = entity_load('field_collection_item', array($with_from_fc_id)); $reference_term = taxonomy_term_load($with_from[$with_from_fc_id]->field_source_name[$annotation->language][0]['tid']); //echo '
    ';var_dump($annotation->field_db_reference);
    					if($reference_term->field_machine_name['und'][0]['value'] == 'PMID'){
    						$pminfoarray = pubmed_id_to_article_info($with_from[$with_from_fc_id]->field_object_id[$annotation->language][0]['value']);
    						$out.= '
  5. '.$pminfoarray['authors'].', '.$pminfoarray['title'].', '.$pminfoarray['journal'].', '.$pminfoarray['volume'].', '.$pminfoarray['issue'].', '.$pminfoarray['epubdate'].'
  6. '; } else if($reference_term->field_machine_name['und'][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] != 'PMID'){ //echo 'good annotation'; $out.= '
  7. '.$reference_term->field_machine_name['und'][0]['value'].', '.$with_from[$with_from_fc_id]->field_object_id[$annotation->language][0]['value'].'
  8. '; } } } } $out.= '
'; print $out; } else { print '

No source information to show

'; } } function print_annotation_pubmed_citations($node){ $out = '

PubMED Citations:

    '; if(count($node->field_db_reference) > 0){ //echo 'good count'; for($x=0;$xfield_db_reference[$node->language]);$x++){ $db_reference_fc_id = $node->field_db_reference[$node->language][$x]['value']; $db_reference = entity_load('field_collection_item', array($db_reference_fc_id)); $reference_term = taxonomy_term_load($db_reference[$db_reference_fc_id]->field_source_name[$node->language][$x]['tid']); //echo '
    ';var_dump($annotation->field_db_reference);
    			if($reference_term->field_machine_name['und'][0]['value'] != '' && $db_reference[$db_reference_fc_id]->field_object_id[$node->language][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] == 'PMID'){
    				//echo 'good annotation';
    				$pminfoarray = pubmed_id_to_article_info($db_reference[$db_reference_fc_id]->field_object_id[$node->language][0]['value']);
    				$out.= '
  1. '.$pminfoarray['authors'].', '.$pminfoarray['title'].', '.$pminfoarray['journal'].', '.$pminfoarray['volume'].', '.$pminfoarray['issue'].', '.$pminfoarray['epubdate'].'
  2. '; } } } $out.= '
'; print $out; } function return_pubmed_citations($node){ //TODO - find bug related to where the source terms are pointing in annotations $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle','annotation') ->fieldCondition('field_gene','target_id',$node->nid,'='); $results = $query->execute(); $out = '

Citations

    '; if(count($results['node'])){ foreach($results['node'] as $ann){ $annotation = node_load($ann->nid); //var_dump($annotation); if(count($annotation->field_db_reference) > 0){ // echo 'good count'; for($x=0;$xfield_db_reference[$annotation->language]);$x++){ $db_reference_fc_id = $annotation->field_db_reference[$annotation->language][$x]['value']; $db_reference = entity_load('field_collection_item', array($db_reference_fc_id)); $reference_term = taxonomy_term_load($db_reference[$db_reference_fc_id]->field_source_name[$annotation->language][$x]['tid']); // echo '
    ';var_dump($reference_term->field_machine_name['und'][0]['value']);exit;
    					if($reference_term->field_machine_name['und'][0]['value'] != '' && $db_reference[$db_reference_fc_id]->field_object_id[$annotation->language][0]['value'] != '' && $reference_term->field_machine_name['und'][0]['value'] == 'PMID'){
    						// echo 'good annotation';
    						$pminfoarray = pubmed_id_to_article_info($db_reference[$db_reference_fc_id]->field_object_id[$annotation->language][0]['value']);
    						// print_r($pminfoarray);exit;
    						$out.= '
  1. '.$pminfoarray['authors'].', '.$pminfoarray['title'].', '.$pminfoarray['journal'].', '.$pminfoarray['volume'].', '.$pminfoarray['issue'].', '.$pminfoarray['epubdate'].'
  2. '; } else if($reference_term->field_machine_name['und'][0]['value'] != ''){ $out.= '
  3. '.$reference_term->field_machine_name['und'][0]['value'].':'.$db_reference[$db_reference_fc_id]->field_object_id[$annotation->language][0]['value'].'
  4. '; } } } } $out.= '
'; return $out; } else { return '

No citation information to show

'; } } // returns an associative array with authors, title, journal, vol, issue, epubdate // https://www.ncbi.nlm.nih.gov/pmc/tools/get-metadata/ function pubmed_id_to_article_info($pmid){ $html = curl_get_contents("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=".$pmid."&retmode=json"); $json = json_decode($html); $trimmed_pmid = ltrim($pmid, '0'); // $tmp = isset($json->result->$trimmed_pmid->error); // $tmp2 = $tmp->$pmid; // echo'
';var_dump($tmp);
	// echo'
';var_dump($pmid);exit;
	if(isset($json->result->$trimmed_pmid->error)){
		$out_array = array(
			'authors' 	=> '',
			'title'		=> '',
			'journal'	=> '',
			'volume'	=> '',
			'issue'		=> '',
			'epubdate'	=> '',
		);
		//echo '
';var_dump($out_array);
		return $out_array;
	} else {
		$article_metadata = $json->result->$pmid;
		if(count($article_metadata->authors)>1){
			$authors = $article_metadata->authors[0]->name.', et. all';
		} else {
			$authors = $article_metadata->authors[0]->name;
		}
		$out_array = array(
			'authors' 	=> $authors,
			'title'		=> $article_metadata->title,
			'journal'	=> $article_metadata->source,
			'volume'	=> $article_metadata->volume,
			'issue'		=> $article_metadata->issue,
			'epubdate'	=> $article_metadata->epubdate
		);
		//echo '
';var_dump($out_array);
		return $out_array;
	}
}

function return_gene_synonyms($node){
	$out = [];
	if(count($node->field_synonyms)){
		foreach($node->field_synonyms['und'] as $index){
			$out[] = str_replace(' ', ' ', $index['value']);
		}
		return implode(' | ', $out);
	} else {
		return 'No synonyms to show.';
	}
}

function return_gene_location($node){
	return 'Chromosome '.$node->field_chromosome_no['und'][0]['value'].': '.$node->field_chromosome_start['und'][0]['value'].' - '.$node->field_chromosome_stop['und'][0]['value'];
}

function return_gene_phenotype($node){
	if($node->field_has_phenotype['und'][0]['value']){
		return $node->field_phenotype_description['und'][0]['value'];
	} else {
		return '';
	}
}

function return_data_source_fc($node){
	$data_source_fc_id = $node->field_data_source['und'][0]['value'];
	$data_source = entity_load('field_collection_item', [$data_source_fc_id]);
	$source_term = taxonomy_term_load($data_source[$data_source_fc_id]->field_source_name['und'][0]['tid']);
	$source_name = $source_term->name;
	$object_id = $data_source[$data_source_fc_id]->field_object_id['und'][0]['value'];
	return 'Object ID: '.$object_id.'
Source Name: '.$source_name; } function return_data_source_source($node){ $data_source_fc_id = $node->field_data_source['und'][0]['value']; $data_source = entity_load('field_collection_item', [$data_source_fc_id]); $source_term = taxonomy_term_load($data_source[$data_source_fc_id]->field_source_name['und'][0]['tid']); return $source_term->name; } function return_data_source_id($node){ $data_source_fc_id = $node->field_data_source['und'][0]['value']; $data_source = entity_load('field_collection_item', [$data_source_fc_id]); $source_term = taxonomy_term_load($data_source[$data_source_fc_id]->field_source_name['und'][0]['tid']); $object_id = $data_source[$data_source_fc_id]->field_object_id['und'][0]['value']; if($source_term->name == 'Planteome (planteome)' && $object_id == ''){ $object_id = $node->title; } return $object_id; } function return_translated_ontology_term($node){ $term = $node->field_ontology_id['und'][0]['value']; $translated = get_ontology_term_from_id($term); return $term.' - '.$translated; } function return_annotation_curators($node){ global $base_url; $result = db_select('workbench_moderation_node_history','wmnh') ->fields('wmnh') ->condition('nid', $node->nid,'=') ->execute() ->fetchAll(); $out = 'No curator data to show'; if(count($result)){ $out = ''; $exclude = []; $exclude[] = $node->uid; foreach($result as $tablerowobj){ if(isset($tablerowobj->uid) && !in_array($tablerowobj->uid, $exclude)){ $user = user_load($tablerowobj->uid); $out.= '

'.$user->name.'

'; $exclude[] = $user->uid; } } } return $out; } function return_formatted_author($node){ global $base_url; $user = user_load($node->uid); return ''.$user->name.''; } function return_related_synonyms($node){ $out = 'N/A'; if(count($node->field_taxon_related_synonyms)){ $out = ''; foreach($node->field_taxon_related_synonyms['und'] as $synonym_array){ $targ = str_replace(' ', ' ', $synonym_array['value']); $out.= ($out == '') ? ($targ) : (' | '.$targ); } } return $out; } function return_exact_synonyms($node){ $out = 'N/A'; if(count($node->field_taxon_exact_synonyms)){ $out = ''; foreach($node->field_taxon_exact_synonyms['und'] as $synonym_array){ $targ = str_replace(' ', ' ', $synonym_array['value']); $out.= ($out == '') ? ($targ) : (' | '.$targ); } } return $out; } function return_ncbi_number_link($node){ $ncbi_num = $node->field_taxon_ncbi_id['und'][0]['value']; return ''.$ncbi_num.''; } function return_gene_link($node){ return l($node->field_gene['und'][0]['entity']->title, '/node/'.$node->field_gene['und'][0]['target_id']); // return ''.$node->field_gene['und'][0]['entity']->title.''; } function return_with_or_from($node){ $out = '

N/A

'; if(count($node->field_with_or_from)){ $out = ''; foreach($node->field_with_or_from['und'] as $index){ $with_from_fc_id = $index['value']; $with_from = entity_load('field_collection_item', [$with_from_fc_id]); $source_term = taxonomy_term_load($with_from[$with_from_fc_id]->field_source_name['und'][0]['tid']); $object_id = $with_from[$with_from_fc_id]->field_object_id['und'][0]['value']; $out.= '

'.$source_term->name.', '.$object_id.'

'; } } return $out; } function return_db_ref($node){ $out = '

N/A

'; if(count($node->field_db_reference)){ $out = ''; foreach($node->field_db_reference['und'] as $index){ $db_ref_fc_id = $index['value']; $db_ref = entity_load('field_collection_item', [$db_ref_fc_id]); $source_term = taxonomy_term_load($db_ref[$db_ref_fc_id]->field_source_name['und'][0]['tid']); $object_id = $db_ref[$db_ref_fc_id]->field_object_id['und'][0]['value']; $out.= '

'.$source_term->name.', '.$object_id.'

'; } } return $out; } function return_data_source($node){ $out = '

N/A

'; if(count($node->field_data_source)){ $out = ''; foreach($node->field_data_source['und'] as $index){ $data_source_fc_id = $index['value']; $data_source = entity_load('field_collection_item', [$data_source_fc_id]); $source_term = taxonomy_term_load($data_source[$data_source_fc_id]->field_source_name['und'][0]['tid']); $object_id = $data_source[$data_source_fc_id]->field_object_id['und'][0]['value']; $out.= $source_term->name.', '.$object_id; } } return $out; } function return_gene_counts($node){ // $vocab = taxonomy_vocabulary_machine_name_load('gene_type'); // $terms = entity_load('taxonomy_term', FALSE, ['vid'=>$vocab->vid]); // // echo'
';var_dump($terms);exit;
	// foreach($terms as $term){
	// 	$q = new EntityFieldQuery();
	// }

	// $query = db_select('node',"n");
	// $query->leftjoin("field_data_field_gene_type","gt","gt.entity_id = n.nid");
	// $query->leftjoin("field_data_field_ref_species","rf","rf.entity_id = n.nid");
	// $all_taxons= $query->fields('n',array('nid','title'))
	// 				->fields('gc',array('field_gene_count_value'))
	// 				->fields('tp',array('field_taxon_parent_target_id'))
 //                   ->condition('n.type',"taxon",'=')
 //                   ->condition('n.status',1,'=')
 //                   ->execute()
 //                   ->fetchAll(); 
    $taxon_id = arg(1);

    $query = db_query("SELECT gt.field_gene_type_tid, count(n.nid) as total_gene FROM {node} as n
    	LEFT JOIN {field_data_field_gene_type} as gt ON gt.entity_id = n.nid
    	LEFT JOIN {field_data_field_ref_species} as rf ON rf.entity_id = n.nid
    	WHERE n.type = 'gene' AND n.status = 1 AND rf.field_ref_species_target_id = ".$taxon_id." 
    	GROUP BY gt.field_gene_type_tid
	");
	
	$result = $query->fetchAll();

	if(is_array($result)){
		$total = 0;
		foreach ($result as $key => $value) {
			$total += $value->total_gene;
		}

		$output = "

Total - ".$total."

"; foreach ($result as $key => $value) { $term = taxonomy_term_load($value->field_gene_type_tid); $output .= "

".$term->field_human_name['und'][0]['value']." - ".$value->total_gene."

"; } return $output; }else{ return ""; } } function return_species_link($node){ return l($node->field_ref_species['und'][0]['entity']->title, '/node/'.$node->field_ref_species['und'][0]['entity']->nid); } /* * builds two arrays, each 5 elements long, for paralogs/orthologs * $base_gene - base gene, sent to justin's api * at# -> ok * os# -> replace first G w/ T * zm# -> need to translate to GRMZM number * $base_species - base species, sent to justin's api. Transformed first as follows: * Oryza Sativa Japonica Group -> Oryza_sativa.japonica.IRGSP * Zea Mays -> Zea_mays * Arabidopsis Thaliana -> Arabidopsis_thaliana * * More IDs will need to be added * $gene_synonyms - used for zea mays only * return: [[$paralogs],[$orthologs]] */ function return_homolog_array($base_gene_id, $base_species, $gene_synonyms){ //transform gene/species as needed //send gene/species to API //transform JSON into array & iterate // first 5 paralogs go into paralog array // maintain array of species in ortholog array // first 5 orthologs go into ortholog array // continue iterating over homologs, if encounter a species not in ortholog array already, replace index of array based on species in ortholog array +1 // when species in ortholog array = 5, break, or let loop run its course. switch ($base_species) { case '433': //Zea Mays foreach($gene_synonyms['und'] as $synonym){ if(strpos($synonym['value'], 'GRMZM') !== false){ //break out of both //this might actually need to be break 3 since we're in the if statement? $base_gene_id = $synonym['value']; $base_species = 'Zea_mays'; break 2; } } //either synonyms are empty or synonyms don't contain a GRMZM, can't query API return [[],[]]; break; case '465': // Oryza Sativa Japonica Group if($base_gene_id[4] == 'G'){ $base_gene_id[4] = 'T'; $base_species = 'Oryza_sativa.japonica.IRGSP'; } else { //incorrect gene ID, can't query API return [[],[]]; } break; case '636': // Arabidopsis Thaliana $base_species = 'Arabidopsis_thaliana'; break; default: return [[],[]]; break; } //if we reach here, the data should have been cleaned. // echo'
';
	// var_dump($base_gene_id);
	// var_dump($base_species);
	// exit;
	$availible_species = ['Arabidopsis_thaliana', 'Oryza_sativa.japonica.IRGSP', 'Zea_mays'];
	$json = htmlspecialchars(curl_get_contents("http://dev.planteome.org/ortho_service/?q=".$base_gene_id."&species=".$base_species.""));
	$json_arr = json_decode(html_entity_decode($json));
	$ortholog_species = [];
	$paralogs = [];
	$orthologs = [];
	// $needed_unique_num = 
	foreach ($json_arr as $homolog_json_obj) {
		if($homolog_json_obj->species == $base_species){
			//paralog
			if(count($paralogs) < 5){
				$paralogs[] = $homolog_json_obj->gene;
				if(count($ortholog_species == 5) && count($paralogs) == 5){
					//multiple break levels?
					break;
				}
			}

		} else {
			//ortholog
			if(in_array($homolog_json_obj->species, $availible_species)){
				if(count($orthologs) < 5){
					//add ortholog
					$orthologs[] = $homolog_json_obj->gene;
					$ortholog_species[] = $homolog_json_obj->species;
				} elseif (count(array_unique($ortholog_species)) < min(count($availible_species)-1, 5)){
					//need more species in ortholog_species, can find indexes of species and then replace corresponding index in $orthologs?
				}
			}
		}
	}

	// echo'
';var_dump($json_arr);exit;
}

//follows the methodology of the register preapproved module, and checks if the registering user has a .edu address
function planteome_utilities_user_presave(&$edit, $account, $category){
	if(isset($account->is_new)){
		$domain = array_reverse(explode('.', $account->mail))[0];
		if($domain == 'edu') {
			// $account->status = TRUE;
			// $account->roles['5'] = 'Contributors';

			$edit["status"] = true;
			// $edit["roles"]['5'] = "Contributors";

			// echo'
';var_dump($edit);exit;
			// user_save($account);


		}
	}
	// echo'
';var_dump($edit);var_dump($account);var_dump($category);exit;
}

function check_ontology_type_and_id($ontology_type, $ontology_id) {
	$html_json = htmlspecialchars(curl_get_contents("http://browser.planteome.org/api/autocomplete/ontology?q=".url_encode_2($id_string)));
	$tmp = html_entity_decode($html_json);
	$json_obj = json_decode($tmp);
	$output = $id_string;
	if(is_object($json_obj) && count($json_obj->data)){
		//first data is target term
		$data = $json_obj->data[0];
		switch($data->source) {
			case 'biological_process':
				if($ontology_type == 603){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'cellular_component':
				if($ontology_type == 609){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'molecular_function':
				if($ontology_type == 605){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'plant_anatomy':
				if($ontology_type == 614){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'plant_environment_ontology':
				if($ontology_type == 2328){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'plant_structure_development_stage':
				if($ontology_type == 2329){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			case 'plant_trait_ontology':
				if($ontology_type == 2327){
					return [true,''];
				} else {
					return [false,'Ontology term type and submitted ontology type do not match.'];
				}
				break;
			default:
				break;
		}
		// foreach($json_obj->data as $data){
		// 	if($data->id == $id_string){
		// 		$output = $data->annotation_class_label;
		// 	}
		// }
	}
	return $output;
}

function planteome_utilities_views_query_alter(&$views){
	if($views->name == 'workbench_moderation' && $views->current_display == 'page_3'){
		global $user;
		//$views->query->where[2]['conditions'][0]['value'][0] = $user->uid;
		//$views->query->where[2]['conditions'][1]['value'][':node_uid_revision'][0] = $user->uid;

		//unset($views->query->where[2]['conditions'][0]);
		//unset($views->query->where[2]['conditions'][1]);
		//echo "
"; print_r($views->query->where);exit;		
	}
}


// /**************theme_hooks*****************/

// function cgrb_preprocess_page(&$variables){
// 	// if($variables[''])
// 	// echo'
';print_r($variables['node']->type);exit;
// 	if($variables['is_front']){
// 		// $tmp = drupal_get_path('theme', 'cgrb');
// 		// echo'
';var_dump($tmp);exit;
// 		drupal_add_css(drupal_get_path('theme', 'cgrb').'/js/themes/default/style.min.css');
// 		drupal_add_js(drupal_get_path('theme', 'cgrb').'/js/jstree.min.js');
// 		// /*echo'
';*/print_r(drupal_get_js());exit;
// 		// $variables['scripts'] = drupal_get_js();
// 		drupal_add_js(drupal_get_path('theme', 'cgrb').'/js/fp_scripts.js');
// 	} elseif(isset($variables['node']->type) && $variables['node']->type == 'taxon'){
// 		drupal_add_css(drupal_get_path('theme', 'cgrb').'/js/themes/default/style.min.css');
// 		drupal_add_js(drupal_get_path('theme', 'cgrb').'/js/jstree.min.js');
// 		// /*echo'
';*/print_r(drupal_get_js());exit;
// 		// $variables['scripts'] = drupal_get_js();
// 		drupal_add_js(drupal_get_path('theme', 'cgrb').'/js/taxon_scripts.js');
// 	}
// 	// echo'
';var_dump($variables['is_front']);exit;
// }

// function cgrb_preprocess_user_login(&$variables) {
// 	$varr = user_login(array(),$form_state);
// 	$variables['form'] = drupal_build_form('user_login', $varr); ## I have to build the user login myself.
// }

// function cgrb_theme(&$existing, $type, $theme, $path) {
//   return array(
//     'user_login' => array(
//       'template' => 'user-login',
//       'variables' => array('form' => NULL), ## you may remove this line in this case
//     ),
//   );

// }

// function cgrb_form_alter(&$form, &$form_state, $form_id){
// 	if ($form_id == 'user_register_form'){
// 		//echo "
"; print_r($form); exit();
// 		$form['#prefix'] = '
//
//
//
//
//

User Register

'; // $form['#suffix'] = '
'; // } // if($form_id == 'user_pass'){ // $form['#prefix'] = '
//
//
//
//
//

Forgot password?

'; // $form['#suffix'] = '
'; // } // if ($form_id == 'views_exposed_form') { // $view = $form_state['view']; // if ($view->name == 'search_for_gene' && $view->current_display == 'page') { // $form['field_aspect_tid']['#attributes']['class'][] = 'selectpicker'; // $form['field_aspect_tid']['#prefix'] = '
'; // $form['field_aspect_tid']['#suffix'] = '
'; // $form['field_gene_type_tid_1']['#attributes']['class'][] = 'selectpicker'; // $form['field_gene_type_tid_1']['#prefix'] = '
'; // $form['field_gene_type_tid_1']['#suffix'] = '
'; // $options = array(); // $query = db_select('node', 'n'); // $query->leftjoin("field_data_field_taxon_rank","tr","tr.entity_id = n.nid"); // $nodes = $query->fields('n', array('nid','title')) // ->orderBy('n.title', 'ASC') // ->condition('n.type', 'taxon') // ->condition('tr.field_taxon_rank_tid', array(10,18),'IN') // ->execute()->fetchAll(); // //$query; // returns an indexed array // $options[''] = '- Any -'; // foreach ($nodes as $key => $value) { // $options[$value->nid] = $value->title; // } // //echo "
"; print_r($options); exit();
//             $form['field_ref_species_target_id']['#attributes']['class'][] = 'selectpicker selectpicker-species';
//             $form['field_ref_species_target_id']['#type'] = 'select';
//             $form['field_ref_species_target_id']['#size'] = '';
//             $form['field_ref_species_target_id']['#default_value'] = '';
//             $form['field_ref_species_target_id']['#options'] = $options;

//             $form['submit']['#value'] = html_entity_decode('');
//             $form['field_ref_species_target_id']['#prefix'] = '
'; // $form['field_ref_species_target_id']['#suffix'] = '
'; // //echo "
"; print_r($form); exit();
//         // $form['keys']['#prefix'] = '
'; // // $form['keys']['#suffix'] = '
'; // } // } // // echo "
"; print_r($form_id); exit();
// 	// function cgrb_preprocess_node(&$variables){

// 	// }
// }


/**
 * Implements hook_node_update().
 */    
function planteome_utilities_node_update($node) {
  db_update('node_revision')
    ->fields(array('uid' => $node->uid))
    ->condition('nid', $node->nid)
    ->condition('vid', $node->vid)
    ->execute();
}

/*
 * Implements hook_workbench_moderation_transition().
*/
function planteome_utilities_workbench_moderation_transition($node, $previous_state, $new_state) {
  if (isset($node->nid) && isset($node->vid) && isset($node->uid)) {
    planteome_utilities_node_update($node);
  }
}

/*
* form for site content settings
*/
function cgrb_site_content_settings($form,$form_state){
	$form['example_search'] = array(
		'#title' => t('Example search text'),
		'#type' => 'textfield',
		'#default_value' => variable_get('example_search_text'),
	);

	$form['advanced_search_text'] = array(
		'#title' => t('Advanced Search text'),
		'#type' => 'textfield',
		'#default_value' => variable_get('advanced_search_text'),
	);

	$form['about_us_heading'] = array(
		'#title' => t('About us block heading'),
		'#type' => 'textfield',
		'#default_value' => variable_get('about_us_heading_text'),
	);

	$form['about_us_body'] = array(
		'#title' => t('About us block body'),
		'#type' => 'textarea',
		'#default_value' => variable_get('about_us_body_text'),
	);

	$form['taxonomy_tree_block_title'] = array(
		'#title' => t('Taxonomy Tree Block title'),
		'#type' => 'textfield',
		'#default_value' => variable_get('taxonomy_tree_block_title'),
	);

	$form['taxonomy_tree_block_subheading'] = array(
		'#title' => t('Taxonomy Tree Block Subheading'),
		'#type' => 'textarea',
		'#default_value' => variable_get('taxonomy_tree_block_subheading'),
	);

	$form['right_side_block_title'] = array(
		'#title' => t('Right Side block title'),
		'#type' => 'textfield',
		'#default_value' => variable_get('right_side_block_title'),
	);

	$form['footer_text'] = array(
		'#title' => t('Footer text'),
		'#type' => 'text_format',
		'#format' => variable_get('footer_text_format'),
		'#default_value' => variable_get('footer_text_value'),
	);

	$form['optional_divider_text'] = array(
		'#title' => t('Required/Optional Field Divider text'),
		'#type' => 'textfield',
		'#default_value' => variable_get('optional_divider_text')

	);

	$form['export_gaf_header'] = array(
		'#title' => t('Export Annotations text'),
		'#type' => 'text_format',
		'#format' => variable_get('export_gaf_header_format'),
		'#default_value' => variable_get('export_gaf_header_value'),
	);

	/*$form['export_gaf_pager_limit'] = array(
		'#title' => t('Export '),
		'#type' => 'textfield',
		'#default_value' => variable_get('about_us_heading_text'),
	);*/

	$form['export_gaf_annotation_limit'] = array(
		'#title' => t('Annotation export limit (number)'),
		'#type' => 'textfield',
		'#element_validate' => array('element_validate_number'), 
		'#default_value' => variable_get('export_gaf_annotation_limit'),
	);

	// $form['test2'] = array(
	// 	'#title' => t('Annotation export limit (number)'),
	// 	'#type' => 'textfield',
	// 	'#element_validate' => array('element_validate_number'), 
	// 	'#default_value' => variable_get('test2'),
	// );

	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => t('Save'),
	);

	return $form;
}

function cgrb_site_content_settings_submit($form,&$form_state){
	if(isset($form_state['values']['advanced_search_text'])){
		variable_set('advanced_search_text', $form_state['values']['advanced_search_text']);
		// echo'
';var_dump(variable_get('advanced_search_text'));exit;
	}

	if(isset($form_state['values']['example_search'])){
		variable_set('example_search_text ', $form_state['values']['example_search']);
	}

	if(isset($form_state['values']['about_us_heading'])){
		variable_set('about_us_heading_text', $form_state['values']['about_us_heading']);
	}

	if(isset($form_state['values']['about_us_body'])){
		variable_set('about_us_body_text', $form_state['values']['about_us_body']);
	}

	if(isset($form_state['values']['taxonomy_tree_block_title'])){
		variable_set('taxonomy_tree_block_title', $form_state['values']['taxonomy_tree_block_title']);
	}

	if(isset($form_state['values']['taxonomy_tree_block_subheading'])){
		variable_set('taxonomy_tree_block_subheading', $form_state['values']['taxonomy_tree_block_subheading']);
	}

	if(isset($form_state['values']['right_side_block_title'])){
		variable_set('right_side_block_title', $form_state['values']['right_side_block_title']);
	}

	if(isset($form_state['values']['footer_text'])){
		variable_set('footer_text_array', $form_state['values']['footer_text']);
		variable_set('footer_text_format', $form_state['values']['footer_text']['format']);
		variable_set('footer_text_value', $form_state['values']['footer_text']['value']);
	}

	if(isset($form_state['values']['optional_divider_text'])){
		variable_set('optional_divider_text', $form_state['values']['optional_divider_text']);
	}

	if(isset($form_state['values']['export_gaf_header'])){
		variable_set('export_gaf_header_array', $form_state['values']['export_gaf_header']);
		variable_set('export_gaf_header_format', $form_state['values']['export_gaf_header']['format']);
		variable_set('export_gaf_header_value', $form_state['values']['export_gaf_header']['value']);
	}

	if(isset($form_state['values']['export_gaf_annotation_limit'])){
		variable_set('export_gaf_annotation_limit', $form_state['values']['export_gaf_annotation_limit']);
	}
	// if(isset($form_state['values']['test2'])){
	// 	variable_set('test2', $form_state['values']['test2']);
	// }

	drupal_set_message('Settings saved successfully!');
}

function planteome_biblio_test_import_form($form, &$form_state) {
  
  $form['pmid'] = array(
    '#type' => 'textfield',
    '#title' => 'PMID'
  );

  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click Here!'),
  );
  
  return $form;
}


function planteome_biblio_test_import_form_submit($form, &$form_state) {
	if(module_exists('biblio_pm')){
		if (strlen($pmid = $form_state['values']['pmid'])) {
			$node = biblio_pm_fetch_pmid($pmid);
			if(!empty($node)){
				$dup = false;
				if(biblio_crossref_check_doi($node->biblio_doi)){
					$dup =biblio_crossref_check_doi($node->biblio_doi);
				}else if(biblio_pm_check_pmid($node->biblio_pubmed_id)){
					$dup = biblio_pm_check_pmid($node->biblio_pubmed_id);
				}
				if (!$dup) {
					$node->comment = 0;
					$node = node_submit($node);
					node_save($node);
					$node->nid; //node id of newly created node
				}else{
					$dup; //node id of already existing node
				}
			}						
		}				
	}
}

function planteome_biblio_test_import_doi_form($form, &$form_state) {
  
  $form['doi_data'] = array(
    '#type' => 'textfield',
    '#title' => 'DOI'
  );

  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click Here!'),
  );
  
  return $form;
}

function planteome_biblio_test_import_doi_form_submit($form, &$form_state) {
	if(module_exists('biblio_crossref')){
		global $user;
  		$node = array();
		if (strlen($doi = $form_state['values']['doi_data'])) {
			if (($doi_start = strpos($form_state['values']['doi_data'], '10.')) !== FALSE) {
				$crossref_pid = variable_get('biblio_crossref_pid', '');
				$user_pid = (isset($user->data['biblio_crossref_pid']) && !empty($user->data['biblio_crossref_pid'])) ? $user->data['biblio_crossref_pid'] : '';
		        if (variable_get('biblio_show_crossref_profile_form', '1') && !empty($user_pid)) {
		          $crossref_pid = $user_pid;
		        }

		        if(!empty($crossref_pid)){
		        	module_load_include('php', 'biblio_crossref', 'biblio.crossref.client');
			        $client = new BiblioCrossRefClient($doi, $crossref_pid);
			        $node = $client->fetch();
			        if(!empty($node)){
			        	if (!($dup = biblio_crossref_check_doi($doi))) {
			        		$node->comment = 0;
							$node = node_submit($node);
							node_save($node);
							$node->nid; //node id of newly created node
			        	}else{
			        		$dup;
			        	}	        	
			        }
		        }
			}
		}			
	}
}