Ver Fonte

Tripal Project: Added node support -Chad Krilow

laceysanderson há 13 anos atrás
pai
commit
409cb33da6
2 ficheiros alterados com 357 adições e 2 exclusões
  1. 67 0
      tripal_project/tripal_project.install
  2. 290 2
      tripal_project/tripal_project.module

+ 67 - 0
tripal_project/tripal_project.install

@@ -0,0 +1,67 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * This file contains all the functions which describe and implement drupal database tables
+ * needed by this module. This module was developed by Chad N.A. Krilow and Lacey-Anne Sanderson, 
+ * University of Saskatchewan. 
+ *
+ * The project manamgenet module allows you to sync data in a chado/Tripal instance with
+ * multiple project/mysql instances as well as manage and create such project instances
+ */
+
+/**
+ * Implementation of hook_install()
+ */
+function tripal_project_install() {
+	drupal_install_schema('tripal_project');
+}
+
+/**
+ * Implementation of hook_uninstall() 
+ */
+function tripal_project_uninstall() {
+	drupal_uninstall_schema('tripal_project');
+}
+
+/**
+ * Implementation of hook_schema()
+ */
+function tripal_project_schema() {
+
+	//specification for 'tripal_project_instances'
+	$schema['chado_project'] = array(
+		
+		'fields' => array(
+      
+	    //a int field that cannot be null and acts as a unique identifier for all nid's
+      'nid' => array(
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+ 	 	  ),
+		
+	    //a int field that cannot be null and is vid 	  
+  		'vid' => array(
+   	   	'type' => 'int',
+   	   	'not null' => TRUE,
+  	  ),
+   	 	
+      //a intfield, not null and project_id is the unique_id of the project in chado
+    	 'project_id' => array(
+   	   	'type' => 'int',
+   	   	'unsigned' => TRUE,
+   	   	'not null' => TRUE,
+    	),
+    	 	
+  	  	
+    ),//end of shema
+  	
+  	'primary key' => array('nid','vid','project_id'),
+	
+	);
+
+  return $schema;
+}
+

+ 290 - 2
tripal_project/tripal_project.module

@@ -9,14 +9,302 @@
  * @see http://gmod.org/wiki/Chado_General_Module
  */
 
-/*************************************************************************
+//-----------------------------------------------------------------------------
+//  SECTION: Main Outline for Tripal Project Module
+//-----------------------------------------------------------------------------
+
+
+/**
  * Implements hook_views_api()
+ *
  * Purpose: Essentially this hook tells drupal that there is views support for
  *  for this module which then includes tripal_project.views.inc where all the
  *  views integration code is
+ *
  */ 
 function tripal_project_views_api() {
    return array(
       'api' => 2.0,
    );
-}
+}
+
+
+/**
+* Implementation of hook_node_info()
+*
+* This node_info, is a simple node that describes the functionallity of the module. It specifies
+* that the title(Project Name) and body(Description) set to true so that they information can be
+* entered
+*
+*/
+function tripal_project_node_info() {
+  return array(
+    'tripal_project' => array(
+      'name' => t('Project'),
+      'module' => 'tripal_project',
+      'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of projects'),
+    	'has_title' => TRUE,
+    	'title_label' =>t('Project Name'),
+    	'had_body' => TRUE,
+    	'body_label' =>t('Description'),
+    )
+  );
+}
+
+
+/**
+* Implementation of hook_form().
+*
+*  This form takes the Project Title infromation and the Project description from the user. It 
+*  then puts the infromation into the Chado_project database table.
+*
+*  @parm &$node
+*    The node that is created when the database is initialized
+*
+*  @parm $form_state
+*    The state of the form, that has the user entered information that is neccessary for, setting
+*    up the database of the project
+*
+*  @return $form
+*    The information that was enterd allong with   
+*
+*/
+function tripal_project_form(&$node, $form_state) {
+  
+  $type = node_get_types('type', $node);
+
+  //define form elements for the node's title and body.
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => check_plain($type->title_label),
+    '#required' => TRUE,
+    '#default_value' => $node->title,
+    '#weight' => -5
+  );
+  
+  // Putting body and filter elements to be adjacent them into a sub-array together
+  $form['body_filter']['body'] = array(
+    '#type' => 'textarea',
+    '#title' => check_plain($type->body_label),
+    '#default_value' => $node->body,
+    '#required' => FALSE
+  );
+  
+  $form['body_filter']['filter'] = filter_form($node->format);
+
+  return $form;
+}
+
+
+/**
+ *  Implements Hook_help()
+ *
+ *  This function simply states, in HTML tags, the creator of the the module and the contact	
+ *  for the programmer
+ *
+ *  @parm $path
+ *    The absolute path of the module and help information
+ *
+ *  @parm $arg
+ *    The argument
+ */
+function tripal_project_help($path, $arg) {
+
+  switch ($path) {
+  
+    case 'admin/help#tripal_project':
+      
+      return '<p>'. t('Module created by:Chad Krilow (e-mail:cnk046@mail.usask.ca)') .'</p>';
+			
+			break;
+  }
+}
+
+
+/**
+ * Implements hook_perm()
+ *
+ *  This function sets the permission for the user to access the information in the database.
+ *  This includes creating, inserting, deleting and updating of information in the database
+ *
+ */
+function tripal_project_perm() {
+
+  return array('create tripal_project', 'edit own tripal_project');
+  
+}
+
+
+/**
+ * Implements hook_access()
+ *
+ *  This function sets the access permission for operations on the database.
+ *
+ *  @parm $op
+ *    The operation that is to be performed
+ *
+ *  @parm $node
+ *    The specific node that is to have the operation performed  
+ *
+ *  @parm $account
+ *    The account of the user that is performing the operations  
+ *
+ *  @return
+ *    True if a operation was performed
+ *
+ */
+function tripal_project_access($op, $node, $account) {
+
+  if ($op == 'create') {
+  
+    // Only users with permission to do so may create this node type.
+    return user_access('create tripal_project', $account);
+  }
+
+  // Users who create a node may edit or delete it later, assuming they have the necessary permissions.
+  if ($op == 'update' || $op == 'delete') {
+  
+    if (user_access('edit own tripal_project',$account) && ($account->uid == $node->uid)) {
+    
+      return TRUE;
+    }
+  }
+}
+
+
+/**
+* Implementation of hook_insert()
+*
+*  @parm $node
+*    Then node that has the information stored within, accessed given the node-Id
+*
+*/
+function tripal_project_insert($node) {
+		
+	$values =  array(
+     'name' => $node->title,
+     'description' => $node->body,
+   );
+   
+   //inserts info into chado table.
+   $result = tripal_core_chado_insert('project',$values);
+
+	//inserts the row of vid,nid,project_id into the chado_project table
+  db_query("INSERT INTO {chado_project} (vid, nid, project_id) VALUES (%d, %d, %d)", $node->vid, $node->nid, $result['project_id']);
+  
+}
+
+
+/**
+*
+* Implementation of hook_delete().
+*
+* @param $node
+* The node which is to be deleted, automagically by Drupal Black Box
+*
+*/
+function tripal_project_delete($node) {
+  // Notice that we're matching all revision, by using the node's nid.
+  
+  $values =  array(
+     'name' => $node->title,
+     'description' => $node->body,
+   );
+  
+  //deleting row in chado table
+  tripal_core_chado_delete('project',$values);
+  
+  //deleteing in drupal chado_project table
+  db_query('DELETE FROM {chado_project} WHERE nid = %d', $node->nid);
+
+}
+
+
+/**
+* Implements hook_update()
+*
+* @param $node
+*  The node which is to have its containing information updated when the user modifys information
+*  pertaining to the specific project
+*
+*/
+function tripal_project_update($node){
+	
+	$result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
+	
+	$match= array(
+		'project_id'=>$result->project_id,
+	);
+	
+	$values =  array(
+    'name' => $node->title,
+    'description' => $node->body,
+  );
+   
+  //selects:$table, $match, $value when updating 
+  $result = tripal_core_chado_update('project',$match,$values);
+
+}
+
+
+/**
+* Implementation of tripal_project_load().
+*
+* @param $node
+*   The node that is to have its containing infromation loaded
+*
+* @return $node
+*   The node, containing the loaded project with the current node-Id
+*
+*/
+function tripal_project_load($node) {
+
+	//selecting the coresponding table information
+	$result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
+	
+	//assigning the project-Id to a variable
+	$values = array(
+	  'project_id' => $result->project_id,
+  );
+	
+	//the current project set to the 'project' with the $values(project-Id)
+  $node->project = tripal_core_generate_chado_var('project',$values);
+  
+  return $node;
+
+}
+
+
+//-----------------------------------------------------------------------------
+//  END OF SOFTWARE
+//-----------------------------------------------------------------------------
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+