فهرست منبع

Added subtemplates needed for block content and used them for the default node template. Blocks not working

laceysanderson 14 سال پیش
والد
کامیت
8ed3aad450
2فایلهای تغییر یافته به همراه259 افزوده شده و 208 حذف شده
  1. 35 151
      theme_tripal/node-chado_stock.tpl.php
  2. 224 57
      tripal_stock/tripal_stock.module

+ 35 - 151
theme_tripal/node-chado_stock.tpl.php

@@ -1,159 +1,43 @@
 <?php
-// $Id: node.tpl.php,v 1.3 2010/04/12 10:04:07 antsin Exp $
-
-/*
-+----------------------------------------------------------------+
-|   BlogBuzz for Dupal 6.x - Version 1.0                         |
-|   Copyright (C) 2009 Antsin.com All Rights Reserved.           |
-|   @license - GNU GENERAL PUBLIC LICENSE                        |
-|----------------------------------------------------------------|
-|   Theme Name: BlogBuzz                                         |
-|   Description: BlogBuzz by Antsin                              |
-|   Author: Antsin.com                                           |
-|   Website: http://www.antsin.com/                              |
-|----------------------------------------------------------------+
-*/  
+// Copyright 2010 University of Saskatchewan (Lacey-Anne Sanderson)
+//
+// Purpose: This template provides the layout of the stock node (page)
+//   using the same templates used for the various stock content blocks.
+//
+// To Customize the Stock Node Page:
+//   - This Template: customize basic layout and which elements are included
+//   - Using Panels: Override the node page using Panels3 and place the blocks
+//       of content as you please. This method requires no programming. See
+//       the Tripal User Guide for more details
+//   - Block Templates: customize the content/layout of each block of stock 
+//       content. These templates are found in the tripal_stock subdirectory
+//
+// Variables Available:
+//   - $node: a standard object which contains all the fields associated with
+//       nodes including nid, type, title, taxonomy. It also includes stock
+//       specific fields such as stock_name, uniquename, stock_type, synonyms,
+//       properties, db_references, object_relationships, subject_relationships,
+//       organism, etc.
+//   NOTE: For a full listing of fields available in the node object add
+//       <pre><?php print_r($node); ?></pre> to this template or install
+//       the Drupal Devel module which provides an extra tab at the top of
+//       the node page labelled Devel
 ?>
 
-<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"><div class="node-inner">
-  <div class="content">
-    <?php print $picture; ?>
-    <?php if ($submitted): ?>
-      <div class="submitted">
-        <?php print $date ?>
-      </div>
-    <?php endif; ?>
-    <h1 class="title">
-      <a href="<?php print $node_url; ?>" title="<?php print $title ?>"><?php print $title; ?></a>
-    </h1>
-
-    <?php if ($unpublished): ?>
-      <div class="unpublished"><?php print t('Unpublished'); ?></div>
-    <?php endif; ?>
-
-    <div class="detail clear-block">
-
-<!-- Tripal Stock Starts --!>
-
-<?php if ($node->is_obsolete == 't') { print "<h4><i>This Stock is obsolete.</i></h4>"; } ?>
-<table>
-  <?php if(!empty($node->stock_name)) { ?>
-    <tr><th>Name</th><td><?php print $node->stock_name; ?></td></tr>
-  <?php } ?>
-  <tr><th>Uniquename</th><td><?php print $node->uniquename; ?></td></tr>
-  <tr><th>Organism</th><td><?php print l($node->organism->common_name, "node/".$node->organism->nid); print " (<i>". $node->organism->genus ." ". $node->organism->species ."</i>)"; ?></td></tr>
-  <tr><th>Type</th><td><?php print $node->stock_type; ?></td></tr>
-  <?php if (!empty($node->main_db_reference->db_name)) { ?>
-    <tr><th>Database (<?php print $node->main_db_reference->db_name; ?>)</th>
-      <?php if( !empty($node->main_db_reference->urlprefix) ) { ?>
-        <td><?php print l($node->main_db_reference->accession, $node->main_db_reference->urlprefix.$node->main_db_reference->accession); ?></td></tr>
-      <?php } else { ?>
-	<td><?php print $node->main_db_reference->accession; ?></td></tr>
-      <?php } 
-  } ?>
-  <?php if(!empty($node->description)) { ?>
-    <tr><th>Description</th><td><?php print $node->description; ?></td></tr>
-  <?php } ?>
-  <?php if(!empty($node->crossingblock->season) && ($node->crossingblock->season != '---')) { ?>
-    <tr><th>Crossing Block</th><td><?php print $node->crossingblock->year.' '.$node->crossingblock->season; ?></td></tr>
-  <?php } ?>
-</table>
-
-<!-- Start of Expandable Boxes -->
-   <?php if (!$teaser) { ?>
-     <!-- Control link for the expandableBoxes -->
-       <br><a id="tripal_expandableBox_toggle_button" onClick="toggleExpandableBoxes()">[-] Collapse All</a><br><br>
-     <!-- End of Control link for the expandableBoxes -->
-
-     <!-- Display of Chado Stock Properties from table stockprop in Chado --!>
-     <?php $properties = $node->properties; 
-     if ( (sizeof($node->synonyms) + sizeof($properties)) > 0 ) { ?>
-     <div id="feature-references" class="tripal_feature-info-box">
-     <div class="tripal_expandableBox"><h3>Properties</h3></div>
-     <div class="tripal_expandableBoxContent">
-     <table>
-       <?php if(!empty($node->synonyms)) { ?>
-         <tr><th>Synonyms</th><td>
-           <?php print $node->synonyms[0]->value;
-           array_shift($node->synonyms);
-           if (sizeof($node->synonyms) >= 1) {
-             foreach($node->synonyms as $synonym) {print ", ".$synonym->value;}
-           } ?>
-	    </td></tr>
-       <?php } ?>
-      </table>
-      <table>
-       <?php if (sizeof($properties) > 0) { ?>
-         <tr><th>Type of Property</th><th>Value</th></tr>
-         <?php foreach ($properties as $result) { ?>
-           <tr><td><?php print $result->type; ?></td>
-	      <td><?php  if( $result->value == 't') { print 'TRUE';
-	           } elseif ($result->value == 'f') { print "FALSE";
-		        } else { print $result->value; } ?>
-			   </td></tr>
-         <?php } 
-	   } ?>
-     </table>
-     </div></div>
-     <br>
-     <?php } ?>
-     <br>
-
-    <!-- Display of External Database entries for the current stock --!>
-    <?php $references = $node->db_references; 
-    if ( count($references) > 0 ) { ?>
-      <div id="feature-references" class="tripal_feature-info-box">
-      <div class="tripal_expandableBox"><h3>External References</h3></div>
-      <div class="tripal_expandableBoxContent">
-      <table>
-        <tr><th>Database</th><th>Accession</th></tr>
-        <?php foreach($references as $result) { ?>
-	  <tr><td><?php print $result->db_name; ?></td><td>
-	      <?php if ( !empty($result->db_urlprefix) ) {
-	            print l($result->accession, $result->db_urlprefix.$result->accession); 
-		        } else {
-			      print $result->accession;
-			          }?>
-				    </td></tr>
-				    <?php } ?>
-      </table></div></div>
-      <br>
-    <?php } ?>
-    <br>
+<!-- Base Theme -->
+<?php include('tripal_stock/tripal_stock_base.tpl.php'); ?>
 
-    <!-- Display of Relationships between this stock and other stocks --!>
-    <?php $o_relationships = $node->object_relationships; ?>
-    <?php $s_relationships = $node->subject_relationships; ?>
-    <?php if ( (count($o_relationships) + count($s_relationships)) > 0 ) { ?>
-      <div id="feature-references" class="tripal_feature-info-box">
-      <div class="tripal_expandableBox"><h3>Relationships</h3></div>
-      <div class="tripal_expandableBoxContent">
-      <table>
-        <?php if ( count($o_relationships) > 0 ) {
-          foreach ($o_relationships as $result) { ?>
-            <tr><td><?php print $node->uniquename; ?></td><td><?php print $result->relationship_type ?></td><td><?php print l($result->object_name, "node/".$result->object_nid); ?></td></tr>
-          <?php } //end of foreach?>
-        <? } if ( count($s_relationships) > 0 ) {
-          foreach ($s_relationships as $result) { ?>
-            <tr><td><?php print l($result->subject_name, "node/".$result->subject_nid); ?></td><td><?php print $result->relationship_type ?></td><td><?php print $node->uniquename; ?></td></tr>
-          <?php } //end	    of foreach
-       } ?>
-      </table></div></div>
-      <br>
-    <?php } ?>
-    <br>
+<!-- Database References -->
+<?php include('tripal_stock/tripal_stock_references.tpl.php'); ?>
 
-  <?php } ?> <!-- End of if not Teaser --!>
+<!-- Properties -->
+<?php include('tripal_stock/tripal_stock_properties.tpl.php'); ?>
 
-<!-- Tripal Stock Ends --!>
+<!-- Synonyms -->
+<?php include('tripal_stock/tripal_stock_synonyms.tpl.php'); ?>
 
-      <?php print $content; ?>
-    </div>
-  </div>
-  
-  <div class="extra-links">
-    <div class="terms terms-inline"><?php print theme('links', $taxonomy, array('class' => 'links term-links')) ?></div>
-    <?php print $links; ?>
-  </div>
+<!-- Object Relationships -->
+<?php include('tripal_stock/tripal_stock_relationships_as_object.tpl.php'); ?>
 
-</div></div> <!-- /node-inner, /node -->
+<!-- Subject Relationships -->
+<?php include('tripal_stock/tripal_stock_relationships_as_subject.tpl.php'); ?>

+ 224 - 57
tripal_stock/tripal_stock.module

@@ -206,9 +206,56 @@ function tripal_stock_theme() {
       'arguments' => array('form'),
       'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
     ),
+//    'tripal_stock_base' => array (
+//      'arguments' => array('node'=> null),
+//      'template' => 'tripal_stock_base',
+//    ),
 	);
 }
 
+/*************************************************************************
+ * Purpose: Implement Blocks relating to stock content
+ */
+function tripal_stock_block ($op = 'list', $delta = 0, $edit=array()) {
+  switch($op) {
+    case 'list':
+      $blocks['base']['info'] = t('Tripal Stock Details');
+      $blocks['base']['cache'] = BLOCK_NO_CACHE;
+         
+      return $blocks;
+
+ 		case 'view':
+ 			if(user_access('access chado_feature 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('Stock Details');
+//						$block['content'] = theme('tripal_stock_base',$node);
+						break;
+        }
+				return $blocks;
+			}
+	}
+}
+
+/*************************************************************************
+ * Purpose:
+ */
+function tripal_stock_nodeapi (&$node, $op, $teaser, $page) {
+	if ($node->type == 'chado_stock') {
+		switch ($op) {
+			case 'view':
+				$node->content['tripal_stock_base'] = array(
+//					'#value' => theme('tripal_stock_base', $node),
+					'#weight' => 0
+				);				
+		}	
+	}
+}
+
 /*************************************************************************
  * Purpose: show stocks stored in drupals chado_stock table
  */
@@ -327,11 +374,13 @@ function chado_stock_load($node) {
     ) 
   );
   $results = tripal_core_chado_select('stockprop', $columns, $values);
-  foreach ($results as $r) {
-    $r->type = 'synonym';
-    $node->synonyms[] = $r;
-  }
-
+  if (!empty($results)) {
+  	foreach ($results as $r) {
+    	$r->type = 'synonym';
+    	$node->synonyms[] = $r;
+  	}
+	}
+	
   // Add properties for stock (not including synonyms)-------------------------------------------
   // $node->properties is an array of objects where each object describes a single property and has a type and value
   $columns = array('stockprop_id', 'type_id', 'value', 'rank');
@@ -403,9 +452,15 @@ function chado_stock_load($node) {
     $node->object_relationships = array();
     foreach ($results as $r) {
       $columns = array('name', 'uniquename', 'description', 'type_id', 'is_obsolete', 'organism_id', 'dbxref_id');
+
       $values = array('stock_id' => $r->object_id);
       $results = tripal_core_chado_select('stock', $columns, $values);
 
+			// Type
+			$type_results = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id' => $r->type_id));
+			$r->type = $type_results[0]->name;
+			
+			// Object
       $r->object->stock_id = $r->object_id;
       unset($r->object_id);
       
@@ -434,6 +489,11 @@ function chado_stock_load($node) {
       $values = array('stock_id' => $r->subject_id);
       $results = tripal_core_chado_select('stock', $columns, $values);
 
+			// Type
+			$type_results = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id' => $r->type_id));
+			$r->type = $type_results[0]->name;
+			
+			// Subject
       $r->subject->stock_id = $r->subject_id;
       unset($r->subject_id);  
       
@@ -441,7 +501,8 @@ function chado_stock_load($node) {
       $r->subject->uniquename = $results[0]->uniquename;
       $r->subject->description = $results[0]->description;
       $r->subject->stock_type_id = $results[0]->type_id;
-      $r->subject->organism->organism_id = $results[0]->organism_id;        $r->subject->main_db_reference->dbxref_id = $results[0]->dbxref_id;        
+      $r->subject->organism->organism_id = $results[0]->organism_id;        
+      $r->subject->main_db_reference->dbxref_id = $results[0]->dbxref_id;        
 
       $sql = "SELECT nid FROM {chado_stock} WHERE stock_id=%d";
       $subject_node = db_fetch_object(db_query($sql, $r->subject->stock_id));
@@ -666,64 +727,93 @@ function chado_stock_validate($node, &$form) {
  */
 function chado_stock_insert($node) {
 
-  $previous_db = tripal_db_set_active('chado');
 	// create dbxref
   if ( !empty($node->accession) ) {
     if ( !empty($node->database) ) { 
-      db_query(
-        "INSERT INTO dbxref (db_id, accession, description) VALUES (%d, '%s', '%s')",
-        $node->database,
-        $node->accession,
-				$node->db_description	
+      $values = array(
+      	'db_id' => $node->database,
+      	'accession' => $node->accession,
       );
-
-  		$dbxref = tripal_db_get_dbxref_by_accession($node->accession, $node->database);
+      if (!tripal_core_chado_select('dbxref',array(dbxref_id), $values)) {
+      	$values['description'] = $node->db_description;
+      	$values['version'] = '1';
+      	$dbxref_status = tripal_core_chado_insert('dbxref', $values);
+      	if (!$dbxref_status) {
+      		drupal_set_message('Unable to add database reference to this stock.', 'warning');
+      		watchdog('tripal_stock', 
+      			'Insert Stock: Unable to create dbxref where values:%values', 
+      			array('%values' => print_r($values, TRUE)),
+      			WATCHDOG_WARNING
+      		);
+      	}
+      } else { $dbxref_status = 1; }
   	}
   }
   
   // create stock
-  if($dbxref->dbxref_id != 0) {
-    db_query(
-      "INSERT INTO stock (dbxref_id, organism_id, name, uniquename, description, type_id, is_obsolete) VALUES (%d, %d, '%s', '%s', '%s', %d, 'f')",
-      $dbxref->dbxref_id,
-      $node->organism_id,
-      $node->title,
-      $node->uniquename,
-      $node->description,
-      $node->type_id
+  if($dbxref_status) {
+		$values = array(
+      'dbxref_id' => array(
+      	'db_id' => $node->database, 
+      	'accession' => $node->accession
+      ),
+      'organism_id' => $node->organism_id,
+      'name' => $node->title,
+      'uniquename' => $node->uniquename,
+      'description' => $node->description,
+      'type_id' => $node->type_id
     );
+    $stock_status = tripal_core_chado_insert('stock', $values);
   } else {
-    db_query(
-      "INSERT INTO stock (organism_id, name, uniquename, description, type_id, is_obsolete) VALUES (%d, '%s', '%s', '%s', %d, 'f')",
-      $node->organism_id,
-      $node->title,
-      $node->uniquename,
-      $node->description,
-      $node->type_id
+		$values = array(
+      'organism_id' => $node->organism_id,
+      'name' => $node->title,
+      'uniquename' => $node->uniquename,
+      'description' => $node->description,
+      'type_id' => $node->type_id
     );
+    $stock_status = tripal_core_chado_insert('stock', $values);
   }
-  tripal_db_set_active($previous_db);
 
   // create drupal chado_stock entry
-  $previous_db = tripal_db_set_active('chado');
-  $chado_stock = db_fetch_object(db_query("SELECT stock_id FROM stock WHERE uniquename='".$node->uniquename."' AND type_id=".$node->type_id.' AND organism_id='.$node->organism_id));
-	tripal_db_set_active($previous_db);
-  if (!empty($chado_stock->stock_id)) {
-  	db_query(
-    	"INSERT INTO {chado_stock} (nid, vid, stock_id) "
-    	."VALUES (%d, %d, %d)",
-    	$node->nid,
-    	$node->vid,
-    	$chado_stock->stock_id
+  if ($stock_status) {
+	  $values = array(
+    	'organism_id' => $node->organism_id,
+    	'uniquename' => $node->uniquename,
+    	'type_id' => $node->type_id
   	);
-
-  	//Move on to next stage of Stock Creation based on next_stage_path field
-  	if ($node->simulate_multipart) {
-    	$next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);  
-    	$_REQUEST['destination'] = $next_stage_path;
+  	$chado_stock = tripal_core_chado_select('stock', array('stock_id'), $values);
+  	if (!empty($chado_stock[0]->stock_id)) {
+  		db_query(
+    		"INSERT INTO {chado_stock} (nid, vid, stock_id) "
+    		."VALUES (%d, %d, %d)",
+    		$node->nid,
+    		$node->vid,
+    		$chado_stock[0]->stock_id
+  		);
+
+ 	 		//Move on to next stage of Stock Creation based on next_stage_path field
+  		if ($node->simulate_multipart) {
+    		$next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);  
+    		$_REQUEST['destination'] = $next_stage_path;
+  		}
+  	} else {
+			drupal_set_message('Error during stock creation.', 'error');
+			watchdog('tripal_stock', 
+      	'Insert Stock: Unable to find newly created stock where values:%values', 
+      	array('%values' => print_r($values, TRUE)),
+      	WATCHDOG_ERROR
+      );
+      return FALSE;
   	}
   } else {
-		drupal_set_message('Error during stock creation.', 'error');
+  	drupal_set_message('Error during stock creation.', 'error');
+    watchdog('tripal_stock', 
+    	'Insert Stock: Unable to create stock where values:%values', 
+      array('%values' => print_r($values, TRUE)),
+      WATCHDOG_WARNING
+    );
+    return FALSE;
   }
 
 }
@@ -739,18 +829,95 @@ function chado_stock_update($node) {
     chado_stock_insert($node);
   } else {
 
+		//update dbxref
+		if ($node->database) {
+			if($node->accession) {
+				$dbxref_mode = '';
+				$stock = tripal_core_chado_select(
+					'stock', 
+					array('dbxref_id', 'type_id'), 
+					array('stock_id' => $node->stock_id)
+				);
+			
+				if ($stock[0]->dbxref_id) {
+					$values = array(
+						'db_id' => $node->database,
+						'accession' => $node->accession,
+						'description' => $node->db_description
+					);
+					$dbxref_status = tripal_core_chado_update(
+						'dbxref', 
+						array('dbxref_id' => $stock[0]->dbxref_id), 
+						$values
+					);
+					$dbxref_mode = 'Update';
+				} else {
+					if ($stock[0]->type_id) {
+						//create the dbxref
+						//used the type_id as a control to check we have a stock but not a dbxref
+						$values = array(
+							'db_id' => $node->database,
+							'accession' => $node->accession,
+							'description' => $node->db_description,
+							'version' => '1',
+						);						
+						$dbxref_status = tripal_core_chado_insert(
+							'dbxref',
+							$values
+						);
+						$dbxref_mode = 'Create';
+					} else {
+						drupal_set_message('Unable to find stock to Update', 'error');
+						watchdog(
+							'tripal_stock',
+							'Stock Update: Unable to find stock to update using values: %values',
+							array('%values', print_r($values, TRUE)),
+							WATCHDOG_ERROR
+						);
+						return FALSE;
+					}
+				}
+			}
+		}
+		
+		if (!$dbxref_status) {
+			watchdog(
+				'tripal_stock',
+				'Stock Update: Unable to %mode main stock dbxref with values: %values',
+				array('%values' => print_r($values,TRUE), '%mode' => $dbxref_mode),
+				WATCHDOG_WARNING
+			);
+		}
+
     //can't change stock id which is all thats stored in drupal thus only update chado
-    $previous_db = tripal_db_set_active('chado');
-    db_query(
-      "UPDATE stock SET organism_id=%d, name='%s', uniquename='%s', description='%s', type_id=%d WHERE stock_id=%d",
-      $node->organism_id,
-      $node->title,
-      $node->uniquename,
-      $node->description,
-      $node->type_id,
-      $node->stock_id
+		$update_values = array(
+      'organism_id' => $node->organism_id,
+      'name' => $node->title,
+      'uniquename' => $node->uniquename,
+      'description' => $node->description,
+      'type_id' => $node->type_id,
     );
-    tripal_db_set_active($previous_db);
+    if ($dbxref_status) {
+    	$update_values['dbxref_id'] = array(
+    		'db_id' => $node->database, 
+    		'accession' => $node->accession
+    	);
+    }
+    $status = tripal_core_chado_update(
+    	'stock',
+    	array('stock_id' => $node->stock_id), 
+    	$update_values
+    );
+    
+    if (!$status) {
+    	drupal_set_message('Unable to update stock', 'error');
+    	watchdog(
+    		'tripal_stock',
+    		'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
+				array('%mvalues' => print_r(array('stock_id' => $node->stock_id),TRUE), '%uvalues' => print_r($update_values,TRUE)),
+				WATCHDOG_ERROR
+    	);
+    }
   }
 
 }