Browse Source

Working on Project module

Stephen Ficklin 11 years ago
parent
commit
c1cf12f0c0
31 changed files with 1488 additions and 1566 deletions
  1. 1 1
      tripal_analysis/tripal_analysis.module
  2. 467 0
      tripal_contact/includes/tripal_contact.chado_node.inc
  3. 0 211
      tripal_contact/includes/tripal_contact.form.inc
  4. 1 255
      tripal_contact/tripal_contact.module
  5. 1 1
      tripal_feature/tripal_feature.module
  6. 1 1
      tripal_featuremap/tripal_featuremap.module
  7. 0 2
      tripal_library/tripal_library.install
  8. 1 1
      tripal_natural_diversity/tripal_natural_diversity.module
  9. 1 1
      tripal_organism/tripal_organism.module
  10. 1 1
      tripal_phenotype/tripal_phenotype.module
  11. 4 4
      tripal_project/api/tripal_project.api.inc
  12. 8 333
      tripal_project/includes/tripal_project.admin.inc
  13. 395 0
      tripal_project/includes/tripal_project.chado_node.inc
  14. 0 142
      tripal_project/theme/node--chado-project.tpl.php
  15. 0 0
      tripal_project/theme/tripal_project.help.tpl.php
  16. 1 0
      tripal_project/theme/tripal_project.theme.inc
  17. 84 0
      tripal_project/theme/tripal_project/tripal_project.base.tpl.php
  18. 77 0
      tripal_project/theme/tripal_project/tripal_project.contact.tpl.php
  19. 65 0
      tripal_project/theme/tripal_project/tripal_project.properties.tpl.php
  20. 78 0
      tripal_project/theme/tripal_project/tripal_project.publications.tpl.php
  21. 129 0
      tripal_project/theme/tripal_project/tripal_project.relationships.tpl.php
  22. 36 0
      tripal_project/theme/tripal_project/tripal_project.teaser.tpl.php
  23. 0 53
      tripal_project/theme/tripal_project/tripal_project_base.tpl.php
  24. 0 50
      tripal_project/theme/tripal_project/tripal_project_contact.tpl.php
  25. 0 41
      tripal_project/theme/tripal_project/tripal_project_properties.tpl.php
  26. 0 58
      tripal_project/theme/tripal_project/tripal_project_publications.tpl.php
  27. 0 81
      tripal_project/theme/tripal_project/tripal_project_relationships.tpl.php
  28. 0 20
      tripal_project/theme/tripal_project/tripal_project_teaser.tpl.php
  29. 41 6
      tripal_project/tripal_project.install
  30. 95 303
      tripal_project/tripal_project.module
  31. 1 1
      tripal_views/tripal_views.module

+ 1 - 1
tripal_analysis/tripal_analysis.module

@@ -235,7 +235,7 @@ function tripal_analysis_block_view($delta = '') {
 
 /**
  *
- * @ingroup tripal_feature
+ * @ingroup tripal_analysis
  */
 function tripal_analysis_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {

+ 467 - 0
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -0,0 +1,467 @@
+<?php
+/**
+ * Implementation of tripal_contact_form().
+ *
+ *
+ *
+ *  @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 tables for the contact
+ *
+ *  @return $form
+ *    The information that was enterd allong with
+ *
+ */
+function chado_contact_form(&$node, $form_state) {
+  $form = array();
+  // Default values can come in the following ways:
+  //
+  // 1) as elements of the $node object.  This occurs when editing an existing contact
+  // 2) in the $form_state['values'] array which occurs on a failed validation or
+  //    ajax callbacks from non submit form elements
+  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
+  //    form elements and the form is being rebuilt
+  //
+  // set form field defaults
+  $contact_id  = null;
+  $type_id     = 0;
+  $title       = '';
+  $description = '';
+  
+  // if we are editing an existing node then the contact is already part of the node
+  if (property_exists($node, 'contact')) {
+    $contact = $node->contact;
+    $contact_id = $contact->contact_id;
+    
+    // get form defaults
+    $type_id     = $contact->type_id->cvterm_id;
+    $title       = $contact->name;
+    
+    // get the contact default values.  When this module was first created
+    // the contact description was incorrectly stored in the $node->body field.
+    // It is better to store it in the Chado tables.  However, the 'description'
+    // field of the contact table is only 255 characters.  So, we are going
+    // to follow the same as the contact module and store the description in
+    // the contactprop table and leave the contact.description field blank.
+    // however, for backwards compatibitily, we check to see if the description
+    // is in the $node->body field. If it is we'll use that.  When the node is
+    // edited the text will be moved out of the body and into the contactprop
+    // table where it should belong.
+    $description = '';
+    if (property_exists($node, 'body')) {
+      $description = $node->body;
+    }
+    else {
+      $description = $contact->description;
+    }
+    if (!$description) {
+      $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
+      $description = $contactprop->value;
+    }
+     
+    // set the contact_id in the form
+    $form['contact_id'] = array(
+      '#type' => 'value',
+      '#value' => $contact->contact_id,
+    );
+  }
+  // if we are re constructing the form from a failed validation or ajax callback
+  // then use the $form_state['values'] values
+  if (array_key_exists('values', $form_state)) {
+    $type_id     = $form_state['values']['type_id'];
+    $title       = $form_state['values']['title'];
+    $description = $form_state['values']['description'];
+  }
+  // if we are re building the form from after submission (from ajax call) then
+  // the values are in the $form_state['input'] array
+  if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
+    $type_id     = $form_state['input']['type_id'];
+    $title       = $form_state['input']['title'];
+    $description = $form_state['input']['description'];
+  }
+
+  // get the contact types. These are those that are part of the tripal_contact
+  // vocabulary and are children of the term 'Contact Type', so we need
+  // to join on the cvtermpath table and select those with a distance of 1
+  $sql = "
+    SELECT CVTS.cvterm_id, CVTS.name
+    FROM {cvtermpath} CVTP
+      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
+    WHERE 
+      CV.name = 'tripal_contact' AND 
+      CVTO.name = 'Contact Type' AND
+      CVTP.pathdistance = 1
+    ORDER BY CVTS.name ASC 
+  ";
+  $results = chado_query($sql);
+  $contact_types = array();
+  while ($contact_type = $results->fetchObject()) {
+    $contact_types[$contact_type->cvterm_id] = $contact_type->name;
+    if (strcmp($contact_type->name, "Person") == 0 and !$type_id) {
+      $type_id = $contact_type->cvterm_id;
+    }
+  }
+  $form['type_id'] = array(
+    '#type' => 'select',
+    '#title' => t('Contact Type'),
+    '#options' => $contact_types,
+    '#required' => TRUE,
+    '#default_value' => $type_id,
+  );
+  
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Contact Name'),
+    '#description'   => t('Enter the name of this contact'),
+    '#required'      => TRUE,
+    '#default_value' => $title,
+    '#maxlength'     => 255,
+  );
+
+  $form['description']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Contact Description'),
+    '#description'   => t('A brief description of the contact'),
+    '#required'      => TRUE,
+    '#default_value' => $description,
+  );
+
+  // get the contact properties that the user can use for this form
+  $properties = array();
+  $properties[] = 'Select a Property';
+  $sql = "
+    SELECT CVTS.cvterm_id, CVTS.name
+    FROM {cvtermpath} CVTP
+      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
+    WHERE
+      CV.name = 'tripal_contact' AND
+      NOT CVTO.name = 'Contact Type'
+    ORDER BY CVTS.name ASC
+  ";
+  $prop_types = chado_query($sql);
+  while ($prop = $prop_types->fetchObject()) {
+    $properties[$prop->cvterm_id] = $prop->name;
+  }
+  
+  $exclude = array('contact_description');
+  $include = array();
+  tripal_core_properties_form($form, $form_state, 'contactprop', 'contact_id', 'tripal_contact',
+    $properties, $contact_id, $exclude, $include, '', 'Properties');
+   
+  return $form;
+}
+
+/**
+ *  validates submission of form when adding or updating a contact node
+ *
+ * @ingroup tripal_contact
+ */
+function chado_contact_validate($node, $form, &$form_state) {
+  // remove surrounding white-space on submitted values
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+ 
+  // if this is a delete then don't validate
+  if($node->op == 'Delete') {
+    return;
+  }
+  
+  // we are syncing if we do not have a node ID but we do have a contact_id. We don't
+  // need to validate during syncing so just skip it.
+  if (is_null($node->nid) and property_exists($node, 'contact_id') and $node->contact_id != 0) {
+    return;
+  }
+  
+  // Validating for an update
+  if (property_exists($node, 'nid')) {    
+    // get the existing node    
+    $values = array('contact_id' => $node->contact_id);
+    $result = tripal_core_chado_select('contact', array('*'), $values);
+    $contact = $result[0];
+      
+    // if the name has changed make sure it doesn't conflict with an existing name
+    if ($contact->name != $node->title) {
+      $values = array('name' => $node->title);
+      $result = tripal_core_chado_select('contact', array('contact_id'), $values);
+      if ($result and count($result) > 0) {
+        form_set_error('title', 'Cannot update the contact with this contact name. A contact with this name already exists.');
+        return;
+      }  
+    }
+  }
+  // Validating for an insert
+  else {
+    // The unique constraint for the chado contact table is: name
+    $values = array(
+      'name' => $node->title,
+    );
+    $contact = tripal_core_chado_select('contact', array('contact_id'), $values);
+    if ($contact and count($contact) > 0) {
+      form_set_error('title', 'Cannot add the contact with this name. A contact with these values already exists.');
+      return;
+    }
+  }
+}
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ */
+function chado_contact_node_access($node, $op, $account ) {
+  if ($op == 'create') {
+    if (!user_access('create chado_contact content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+
+  if ($op == 'update') {
+    if (!user_access('edit chado_contact content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_contact content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_contact content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}
+
+
+
+/**
+ * Implementation of tripal_contact_insert().
+ *
+ * This function inserts user entered information pertaining to the contact instance into the
+ * 'contactauthor', 'contactprop', 'chado_contact', 'contact' talble of the database.
+ *
+ *  @parm $node
+ *    Then node which contains the information stored within the node-ID
+ *
+ *
+ */
+function chado_contact_insert($node) {
+
+  // remove surrounding white-space on submitted values
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+
+  // if there is a contact_id in the $node object then this must be a sync so
+  // we can skip adding the contact as it is already there, although
+  // we do need to proceed with the rest of the insert
+  if (!property_exists($node, 'contact_id')) {
+    // insert and then get the newly inserted contact record
+    $values = array(
+      'name'           => $node->title,
+      'description'    => '',
+      'type_id'        => $node->type_id,
+    );
+    $contact = tripal_core_chado_insert('contact', $values);
+    if (!$contact) {
+      drupal_set_message(t('Unable to add contact.', 'warning'));
+      watchdog('tripal_contact', 'Insert contact: Unable to create contact where values: %values',
+      array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
+      return;
+    }
+    $contact_id = $contact['contact_id'];
+
+    // now add in the properties
+    $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
+    foreach ($properties as $property => $elements) {
+      foreach ($elements as $rank => $value) {
+
+        $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
+        if (!$status) {
+          drupal_set_message("Error cannot add property: $property", "error");
+          watchdog('t_contact', "Error cannot add property: %prop",
+          array('%property' => $property), WATCHDOG_ERROR);
+        }
+      }
+    }
+
+    // add in the description as a separate property
+    tripal_contact_insert_property($contact_id, 'contact_description', $node->description, FALSE);
+  }
+  else {
+    $contact_id = $node->contact_id;
+  }
+
+  // Make sure the entry for this contact doesn't already exist in the
+  // chado_contact table if it doesn't exist then we want to add it.
+  $check_org_id = chado_get_id_for_node('contact', $node->nid);
+  if (!$check_org_id) {
+    $record = new stdClass();
+    $record->nid = $node->nid;
+    $record->vid = $node->vid;
+    $record->contact_id = $contact_id;
+    drupal_write_record('chado_contact', $record);
+  }
+  return TRUE;
+}
+
+/*
+ *
+* Implements hook_update
+*
+* The purpose of the function is to allow the module to take action when an edited node is being
+* updated. It updates any name changes to the database tables that werec reated upon registering a contact.
+* As well, the database will be changed, so the user changed information will be saved to the database.
+*
+* @param $node
+*   The node being updated
+*
+* @ingroup tripal_contact
+*/
+function chado_contact_update($node) {
+  // remove surrounding white-space on submitted values
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+
+  $contact_id = chado_get_id_for_node('contact', $node->nid) ;
+
+  // update the contact record
+  $match = array(
+    'contact_id' => $contact_id,
+  );
+  $values = array(
+    'name' => $node->title,
+    'description' => '',
+    'type_id' => $node->type_id
+  );
+  $status = tripal_core_chado_update('contact', $match, $values);
+  if (!$status) {
+    drupal_set_message("Error updating contact", "error");
+    watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
+    return;
+  }
+
+  // now add in the properties by first removing any the contact
+  // already has and adding the ones we have
+  tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
+  $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
+
+  foreach ($properties as $property => $elements) {
+    foreach ($elements as $rank => $value) {
+      $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
+      if (!$status) {
+        drupal_set_message("Error cannot add property: '$property'", "error");
+        watchdog('t_contact', "Error cannot add property: '%prop'",
+        array('%prop' => $property), WATCHDOG_ERROR);
+      }
+    }
+  }
+
+  // add in the description as a separate property
+  tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
+}
+
+
+/**
+ * Implementation of tripal_contact_load().
+ *
+ *
+ * @param $node
+ *   The node that is to be accessed from the database
+ *
+ * @return $node
+ *   The node with the information to be loaded into the database
+ *
+ */
+function chado_contact_load($nodes) {
+
+  foreach ($nodes as $nid => $node) {
+    // find the contact and add in the details
+    $contact_id = chado_get_id_for_node('contact', $nid);
+
+    // get the contact
+    $values = array('contact_id' => $contact_id);
+    $contact = tripal_core_generate_chado_var('contact', $values);
+
+    // get the contact description from the contactprop table and replace
+    // the contact.description field with this one (we don't use the contact.description
+    // field because it is only 255 characters (too small)).
+    $values = array(
+      'contact_id' => $contact->contact_id,
+      'type_id' => array(
+        'name' => 'contact_description',
+      ),
+    );
+    $options = array(
+      'return_array' => 1,
+      'include_fk' => array('type_id' => 1),
+    );
+    $description = tripal_core_generate_chado_var('contactprop', $values, $options);
+    if (count($description) == 1) {
+      $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
+      $contact->description = $description[0]->value;
+    }
+
+    $nodes[$nid]->contact = $contact;
+  }
+}
+
+/**
+ * Implementation of tripal_contact_delete().
+ *
+ * This function takes a node and if the delete button has been chosen by the user, the contact
+ * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
+ * the 'chado_contact' table.
+ *
+ *  @parm $node
+ *    Then node which contains the information stored within the node-ID
+ *
+ */
+function chado_contact_delete(&$node) {
+
+  $contact_id = chado_get_id_for_node('contact', $node->nid);
+
+  // if we don't have a contact id for this node then this isn't a node of
+  // type chado_contact or the entry in the chado_contact table was lost.
+  if (!$contact_id) {
+    return;
+  }
+
+  // Remove data from {chado_contact}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_contact} 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";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+
+  // Remove data from contact and contactprop tables of chado database as well
+  chado_query("DELETE FROM {contactprop} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
+  chado_query("DELETE FROM {contact} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
+}

+ 0 - 211
tripal_contact/includes/tripal_contact.form.inc

@@ -1,211 +0,0 @@
-<?php
-/**
- * Implementation of tripal_contact_form().
- *
- *
- *
- *  @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 tables for the contact
- *
- *  @return $form
- *    The information that was enterd allong with
- *
- */
-function chado_contact_form(&$node, $form_state) {
-  $form = array();
-  // Default values can come in the following ways:
-  //
-  // 1) as elements of the $node object.  This occurs when editing an existing contact
-  // 2) in the $form_state['values'] array which occurs on a failed validation or
-  //    ajax callbacks from non submit form elements
-  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
-  //    form elements and the form is being rebuilt
-  //
-  // set form field defaults
-  $contact_id  = null;
-  $type_id     = 0;
-  $title       = '';
-  $description = '';
-  
-  // if we are editing an existing node then the contact is already part of the node
-  if (property_exists($node, 'contact')) {
-    $contact = $node->contact;
-    $contact_id = $contact->contact_id;
-    
-    // get form defaults
-    $type_id     = $contact->type_id->cvterm_id;
-    $title       = $contact->name;
-    
-    // get the contact default values.  When this module was first created
-    // the contact description was incorrectly stored in the $node->body field.
-    // It is better to store it in the Chado tables.  However, the 'description'
-    // field of the contact table is only 255 characters.  So, we are going
-    // to follow the same as the contact module and store the description in
-    // the contactprop table and leave the contact.description field blank.
-    // however, for backwards compatibitily, we check to see if the description
-    // is in the $node->body field. If it is we'll use that.  When the node is
-    // edited the text will be moved out of the body and into the contactprop
-    // table where it should belong.
-    $description = '';
-    if (property_exists($node, 'body')) {
-      $description = $node->body;
-    }
-    else {
-      $description = $contact->description;
-    }
-    if (!$description) {
-      $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
-      $description = $contactprop->value;
-    }
-     
-    // set the contact_id in the form
-    $form['contact_id'] = array(
-      '#type' => 'value',
-      '#value' => $contact->contact_id,
-    );
-  }
-  // if we are re constructing the form from a failed validation or ajax callback
-  // then use the $form_state['values'] values
-  if (array_key_exists('values', $form_state)) {
-    $type_id     = $form_state['values']['type_id'];
-    $title       = $form_state['values']['title'];
-    $description = $form_state['values']['description'];
-  }
-  // if we are re building the form from after submission (from ajax call) then
-  // the values are in the $form_state['input'] array
-  if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
-    $type_id     = $form_state['input']['type_id'];
-    $title       = $form_state['input']['title'];
-    $description = $form_state['input']['description'];
-  }
-
-  // get the contact types. These are those that are part of the tripal_contact
-  // vocabulary and are children of the term 'Contact Type', so we need
-  // to join on the cvtermpath table and select those with a distance of 1
-  $sql = "
-    SELECT CVTS.cvterm_id, CVTS.name
-    FROM {cvtermpath} CVTP
-      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
-    WHERE 
-      CV.name = 'tripal_contact' AND 
-      CVTO.name = 'Contact Type' AND
-      CVTP.pathdistance = 1
-    ORDER BY CVTS.name ASC 
-  ";
-  $results = chado_query($sql);
-  $contact_types = array();
-  while ($contact_type = $results->fetchObject()) {
-    $contact_types[$contact_type->cvterm_id] = $contact_type->name;
-    if (strcmp($contact_type->name, "Person") == 0 and !$type_id) {
-      $type_id = $contact_type->cvterm_id;
-    }
-  }
-  $form['type_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Contact Type'),
-    '#options' => $contact_types,
-    '#required' => TRUE,
-    '#default_value' => $type_id,
-  );
-  
-  $form['title']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Contact Name'),
-    '#description'   => t('Enter the name of this contact'),
-    '#required'      => TRUE,
-    '#default_value' => $title,
-    '#maxlength'     => 255,
-  );
-
-  $form['description']= array(
-    '#type'          => 'textarea',
-    '#title'         => t('Contact Description'),
-    '#description'   => t('A brief description of the contact'),
-    '#required'      => TRUE,
-    '#default_value' => $description,
-  );
-
-  // get the contact properties that the user can use for this form
-  $properties = array();
-  $properties[] = 'Select a Property';
-  $sql = "
-    SELECT CVTS.cvterm_id, CVTS.name
-    FROM {cvtermpath} CVTP
-      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
-    WHERE
-      CV.name = 'tripal_contact' AND
-      NOT CVTO.name = 'Contact Type'
-    ORDER BY CVTS.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  
-  $exclude = array('contact_description');
-  $include = array();
-  tripal_core_properties_form($form, $form_state, 'contactprop', 'contact_id', 'tripal_contact',
-    $properties, $contact_id, $exclude, $include, '', 'Properties');
-   
-  return $form;
-}
-
-/**
- *  validates submission of form when adding or updating a contact node
- *
- * @ingroup tripal_contact
- */
-function chado_contact_validate($node, $form, &$form_state) {
-  // remove surrounding white-space on submitted values
-  $node->title          = trim($node->title);
-  $node->description    = trim($node->description);
- 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
-    return;
-  }
-  
-  // we are syncing if we do not have a node ID but we do have a contact_id. We don't
-  // need to validate during syncing so just skip it.
-  if (is_null($node->nid) and property_exists($node, 'contact_id') and $node->contact_id != 0) {
-    return;
-  }
-  
-  // Validating for an update
-  if (property_exists($node, 'nid')) {    
-    // get the existing node    
-    $values = array('contact_id' => $node->contact_id);      
-    $result = tripal_core_chado_select('contact', array('*'), $values);
-    $contact = $result[0];
-      
-    // if the name has changed make sure it doesn't conflict with an existing name
-    if ($contact->name != $node->title) {
-      $values = array('name' => $node->title);
-      $result = tripal_core_chado_select('contact', array('contact_id'), $values);
-      if ($result and count($result) > 0) {
-        form_set_error('title', 'Cannot update the contact with this contact name. A contact with this name already exists.');
-        return;
-      }  
-    }
-  }
-  // Validating for an insert
-  else {
-    // The unique constraint for the chado contact table is: name
-    $values = array(
-      'name' => $node->title,
-    );
-    $contact = tripal_core_chado_select('contact', array('contact_id'), $values);
-    if ($contact and count($contact) > 0) {
-      form_set_error('title', 'Cannot add the contact with this name. A contact with these values already exists.');
-      return;
-    }
-  }
-}

+ 1 - 255
tripal_contact/tripal_contact.module

@@ -12,7 +12,7 @@
 require('api/tripal_contact.api.inc');
 require('includes/contact_sync.inc');
 require('includes/tripal_contact.admin.inc');
-require('includes/tripal_contact.form.inc');
+require('includes/tripal_contact.chado_node.inc');
 
 /**
  * @defgroup tripal_contact Contact Module
@@ -293,261 +293,7 @@ function tripal_contact_permissions() {
   );
 }
 
-/**
- * Implement hook_access().
- *
- * This hook allows node modules to limit access to the node types they define.
- *
- *  @param $node
- *  The node on which the operation is to be performed, or, if it does not yet exist, the
- *  type of node to be created
- *
- *  @param $op
- *  The operation to be performed
- *
- *  @param $account
- *  A user object representing the user for whom the operation is to be performed
- *
- *  @return
- *  If the permission for the specified operation is not set then return FALSE. If the
- *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always
- *  return TRUE if the permission is set.
- *
- */
-function chado_contact_node_access($node, $op, $account ) {
-  if ($op == 'create') {
-    if (!user_access('create chado_contact content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
-  }
-
-  if ($op == 'update') {
-    if (!user_access('edit chado_contact content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_contact content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_contact content', $account)) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
-
-
 
-/**
- * Implementation of tripal_contact_insert().
- *
- * This function inserts user entered information pertaining to the contact instance into the
- * 'contactauthor', 'contactprop', 'chado_contact', 'contact' talble of the database.
- *
- *  @parm $node
- *    Then node which contains the information stored within the node-ID
- *
- *
- */
-function chado_contact_insert($node) {
-
-  // remove surrounding white-space on submitted values
-  $node->title          = trim($node->title);
-  $node->description    = trim($node->description);
-  
-  // if there is a contact_id in the $node object then this must be a sync so
-  // we can skip adding the contact as it is already there, although
-  // we do need to proceed with the rest of the insert
-  if (!property_exists($node, 'contact_id')) {
-    // insert and then get the newly inserted contact record
-    $values = array(
-      'name'           => $node->title,
-      'description'    => '',
-      'type_id'        => $node->type_id,
-    );
-    $contact = tripal_core_chado_insert('contact', $values);
-    if (!$contact) {
-      drupal_set_message(t('Unable to add contact.', 'warning'));
-      watchdog('tripal_contact', 'Insert contact: Unable to create contact where values: %values',
-      array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
-      return;
-    }
-    $contact_id = $contact['contact_id'];
-    
-    // now add in the properties
-    $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-    
-        $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_contact', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
-      }
-    }
-    
-    // add in the description as a separate property
-    tripal_contact_insert_property($contact_id, 'contact_description', $node->description, FALSE);
-  }
-  else {
-    $contact_id = $node->contact_id;
-  }
-  
-  // Make sure the entry for this contact doesn't already exist in the
-  // chado_contact table if it doesn't exist then we want to add it.
-  $check_org_id = chado_get_id_for_node('contact', $node->nid);
-  if (!$check_org_id) {
-    $record = new stdClass();
-    $record->nid = $node->nid;
-    $record->vid = $node->vid;
-    $record->contact_id = $contact_id;
-    drupal_write_record('chado_contact', $record);
-  }
-  return TRUE;
-}
-
-/*
- *
- * Implements hook_update
- *
- * The purpose of the function is to allow the module to take action when an edited node is being
- * updated. It updates any name changes to the database tables that werec reated upon registering a contact.
- * As well, the database will be changed, so the user changed information will be saved to the database.
- *
- * @param $node
- *   The node being updated
- *
- * @ingroup tripal_contact
- */
-function chado_contact_update($node) {
-  // remove surrounding white-space on submitted values
-  $node->title          = trim($node->title);
-  $node->description    = trim($node->description);
-
-  $contact_id = chado_get_id_for_node('contact', $node->nid) ;
-
-  // update the contact record
-  $match = array(
-    'contact_id' => $contact_id,
-  );
-  $values = array(
-    'name' => $node->title,
-    'description' => '',
-    'type_id' => $node->type_id
-  );
-  $status = tripal_core_chado_update('contact', $match, $values);
-  if (!$status) {
-    drupal_set_message("Error updating contact", "error");
-    watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
-    return;
-  }
-
-  // now add in the properties by first removing any the contact
-  // already has and adding the ones we have
-  tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
-  $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
-  
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
-      if (!$status) {
-        drupal_set_message("Error cannot add property: '$property'", "error");
-        watchdog('t_contact', "Error cannot add property: '%prop'",
-        array('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
-
-  // add in the description as a separate property
-  tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
-}
-
-
-/**
- * Implementation of tripal_contact_load().
- *
- *
- * @param $node
- *   The node that is to be accessed from the database
- *
- * @return $node
- *   The node with the information to be loaded into the database
- *
- */
-function chado_contact_load($nodes) {
-  
-  foreach ($nodes as $nid => $node) {
-    // find the contact and add in the details
-    $contact_id = chado_get_id_for_node('contact', $nid);
-  
-    // get the contact 
-    $values = array('contact_id' => $contact_id);
-    $contact = tripal_core_generate_chado_var('contact', $values);
-    
-    // get the contact description from the contactprop table and replace 
-    // the contact.description field with this one (we don't use the contact.description
-    // field because it is only 255 characters (too small)).
-    $values = array(
-      'contact_id' => $contact->contact_id,
-      'type_id' => array(
-        'name' => 'contact_description',
-      ),
-    );
-    $options = array(
-      'return_array' => 1,
-      'include_fk' => array('type_id' => 1),
-    );
-    $description = tripal_core_generate_chado_var('contactprop', $values, $options);
-    if (count($description) == 1) {
-      $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
-      $contact->description = $description[0]->value;
-    }
-    
-    $nodes[$nid]->contact = $contact;
-  }
-}
-
-/**
- * Implementation of tripal_contact_delete().
- *
- * This function takes a node and if the delete button has been chosen by the user, the contact
- * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
- * the 'chado_contact' table.
- *
- *  @parm $node
- *    Then node which contains the information stored within the node-ID
- *
- */
-function chado_contact_delete(&$node) {
-
-  $contact_id = chado_get_id_for_node('contact', $node->nid);
-
-  // if we don't have a contact id for this node then this isn't a node of
-  // type chado_contact or the entry in the chado_contact table was lost.
-  if (!$contact_id) {
-    return;
-  }
-
-  // Remove data from {chado_contact}, {node} and {node_revisions} tables of
-  // drupal database
-  $sql_del = "DELETE FROM {chado_contact} 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";
-  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
-  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
-  // Remove data from contact and contactprop tables of chado database as well
-  chado_query("DELETE FROM {contactprop} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
-  chado_query("DELETE FROM {contact} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
-}
 /**
  *
  *

+ 1 - 1
tripal_feature/tripal_feature.module

@@ -277,7 +277,7 @@ function tripal_feature_menu() {
     'title' => 'Enable feature Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_feature_admin_features', 'admin/tripal/chado/tripal_feature'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal feature'),
     'type' => MENU_CALLBACK,
   );
 

+ 1 - 1
tripal_featuremap/tripal_featuremap.module

@@ -188,7 +188,7 @@ function tripal_featuremap_menu() {
     'title' => 'Enable featuremap Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_featuremap_admin_featuremaps', 'admin/tripal/chado/tripal_featuremap'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_CALLBACK,
   );
 

+ 0 - 2
tripal_library/tripal_library.install

@@ -258,6 +258,4 @@ function tripal_library_update_7000() {
   if (!$success) {
     throw new DrupalUpdateException('Failed to move library properties to new library_property CV.');
   }
-
-  
 }

+ 1 - 1
tripal_natural_diversity/tripal_natural_diversity.module

@@ -48,7 +48,7 @@ function tripal_natural_diversity_menu() {
     'title' => 'Enable Natural Diversity Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_natural_diversity_admin_natdiv_exp', 'admin/tripal/chado/tripal_natdiv'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal natural_diversity'),
     'type' => MENU_CALLBACK,
   );
 

+ 1 - 1
tripal_organism/tripal_organism.module

@@ -140,7 +140,7 @@ function tripal_organism_menu() {
     'title' => 'Enable Organism Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_organism_admin_organisms', 'admin/tripal/chado/tripal_organism'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal organism'),
     'type' => MENU_CALLBACK,
   );
   

+ 1 - 1
tripal_phenotype/tripal_phenotype.module

@@ -44,7 +44,7 @@ function tripal_phenotype_menu() {
     'title' => 'Enable Phenotype Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_phenotype_admin_phenotypes', 'admin/tripal/chado/tripal_phenotype'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal phenotype'),
     'type' => MENU_CALLBACK,
   );
 

+ 4 - 4
tripal_project/api/tripal_project.api.inc

@@ -23,7 +23,7 @@
  * @ingroup tripal_project_api
  */
 function tripal_project_get_property($project_id, $property) {
-  return tripal_core_get_property('project', $project_id, $property, 'tripal');
+  return tripal_core_get_property('project', $project_id, $property, 'project_property');
 }
 
 /**
@@ -44,7 +44,7 @@ function tripal_project_get_property($project_id, $property) {
  * @ingroup tripal_project_api
  */
 function tripal_project_insert_property($project_id, $property, $value, $update_if_present = 0) {
-  return tripal_core_insert_property('project', $project_id, $property, 'tripal', $value, $update_if_present);
+  return tripal_core_insert_property('project', $project_id, $property, 'project_property', $value, $update_if_present);
 }
 
 /**
@@ -68,7 +68,7 @@ function tripal_project_insert_property($project_id, $property, $value, $update_
  * @ingroup tripal_project_api
  */
 function tripal_project_update_property($project_id, $property, $value, $insert_if_missing = 0) {
-  return tripal_core_update_property('project', $project_id, $property, 'tripal', $value, $insert_if_missing);
+  return tripal_core_update_property('project', $project_id, $property, 'project_property', $value, $insert_if_missing);
 }
 /**
  * Delete a given property
@@ -87,5 +87,5 @@ function tripal_project_update_property($project_id, $property, $value, $insert_
  * @ingroup tripal_project_api
  */
 function tripal_project_delete_property($project_id, $property) {
-  return tripal_core_delete_property('project', $project_id, $property, 'tripal');
+  return tripal_core_delete_property('project', $project_id, $property, 'project_property');
 }

+ 8 - 333
tripal_project/includes/tripal_project.admin.inc

@@ -36,349 +36,24 @@ function tripal_project_admin_project_view() {
 
   return $output;
 }
-
-
-function tripal_project_admin($form_state = NULL) {
+/**
+ * 
+ * @param $form_state
+ */
+function tripal_project_admin($form_state) {
   $form = array();
 
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync libraries
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_project')) {
-    $active_jobs = TRUE;
-  }
-
-  // add the field set for syncing libraries
-  if (!$active_jobs) {
-    get_tripal_project_admin_form_sync_set($form);
-    get_tripal_project_admin_form_cleanup_set($form);
-//    get_tripal_project_admin_form_reindex_set($form);
-
-  }
-  else {
-    $form['notice'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Project Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-      '#value' => t('Currently, project management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
-    );
-  }
+  $form['nothing'] = array(
+    '#markup' => t('There are currently no settings to configure.')
+  );
 
   return system_settings_form($form);
 }
-/**
- *
- *
- * @ingroup tripal_project
- */
-function get_tripal_project_admin_form_cleanup_set(&$form) {
-  $form['cleanup'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Clean Up')
-  );
-  $form['cleanup']['description'] = array(
-    '#type' => 'item',
-    '#value' => t("With Drupal and chado residing in different databases ".
-    "it is possible that nodes in Drupal and projects in Chado become ".
-    "\"orphaned\".  This can occur if an project node in Drupal is ".
-    "deleted but the corresponding chado project is not and/or vice ".
-    "versa. Click the button below to resolve these discrepancies."),
-    '#weight' => 1,
-  );
-  $form['cleanup']['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Clean up orphaned projects'),
-    '#weight' => 2,
-  );
-}
-/**
- *
- * @ingroup tripal_project
- */
-function get_tripal_project_admin_form_sync_set(&$form) {
-  // define the fieldsets
-  $form['sync'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sync Projects')
-  );
-
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync libraries
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_project')) {
-    $active_jobs = TRUE;
-  }
-
-  if (!$active_jobs) {
 
-    // get the list of projects
-    $sql = "SELECT * FROM {project} ORDER BY name";
-    $org_rset = chado_query($sql);
-
-    // if we've added any projects to the list that can be synced
-    // then we want to build the form components to allow the user
-    // to select one or all of them.  Otherwise, just present
-    // a message stating that all projects are currently synced.
-    $proj_boxes = array();
-    $added = 0;
-    while ($project = $org_rset->fetchObject()) {
-      // check to see if the project is already present as a node in drupal.
-      // if so, then skip it.
-      $sql = "SELECT * FROM {chado_project} WHERE project_id = :project_id";
-      if (!db_query($sql, array(':project_id' => $project->project_id))->fetchObject()) {
-        $proj_boxes[$project->project_id] = $project->name;
-        $added++;
-      }
-    }
-
-    // if we have projects we need to add to the checkbox then
-    // build that form element
-    if ($added > 0) {
-      $proj_boxes['all'] = "All Projects";
-
-      $form['sync']['projects'] = array(
-        '#title'       => t('Available Projects'),
-        '#type'        => t('checkboxes'),
-        '#description' => t("Check the projects you want to sync.  Drupal content will be created for each of the projects listed above.  Select 'All Projects' to sync all of them."),
-        '#required'    => FALSE,
-        '#prefix'      => '<div id="org_boxes">',
-        '#suffix'      => '</div>',
-        '#options'     => $proj_boxes,
-      );
-      $form['sync']['button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Submit Sync Job')
-      );
-    }
-    // we don't have any projects to select from
-    else {
-    $form['sync']['value'] = array(
-        '#value' => t('All projects in Chado are currently synced with Drupal.')
-    );
-    }
-  }
-  // we don't want to present a form since we have an active job running
-  else {
-    $form['sync']['value'] = array(
-        '#value' => t('Currently, jobs exist related to chado projects. Please check back later for projects that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
-    );
-  }
-}
 /**
  *
  * @ingroup tripal_project
  */
 function tripal_project_admin_validate($form, &$form_state) {
-  global $user;  // we need access to the user info
-  $job_args = array();
-
-  if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-    // check to see if the user wants to sync chado and drupal.  If
-    // so then we need to register a job to do so with tripal
-    $projects = $form_state['values']['projects'];
-    $do_all = FALSE;
-    $to_sync = array();
-
-    foreach ($projects as $project_id) {
-      if (preg_match("/^all$/i" , $project_id)) {
-        $do_all = TRUE;
-      }
-      if ($project_id and preg_match("/^\d+$/i" , $project_id)) {
-        // get the list of projects
-        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
-        $project = chado_query($sql, array(':project_id' => $project_id))->fetchObject();
-        $to_sync[$project_id] = "$project->genus $project->species";
-      }
-    }
-
-    // submit the job the tripal job manager
-    if ($do_all) {
-      tripal_add_job('Sync all projects' , 'tripal_project',
-      'tripal_project_sync_projects' , $job_args , $user->uid);
-    }
-    else{
-      foreach ($to_sync as $project_id => $name) {
-        $job_args[0] = $project_id;
-        tripal_add_job("Sync project: $name" , 'tripal_project',
-          'tripal_project_sync_projects' , $job_args , $user->uid);
-      }
-    }
-  }
-
-  // -------------------------------------
-  // Submit the Reindex Job if selected
-  if ($form_state['values']['op'] == t('Reindex Features')) {
-    $projects = $form_state['values']['re-projects'];
-    foreach ($projects as $project_id) {
-      if ($project_id and preg_match("/^\d+$/i" , $project_id)) {
-        // get the project info
-        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
-        $project = chado_query($sql , array(':project_id' => $project_id))->fetchObject();
-        $job_args[0] = $project_id;
-        tripal_add_job("Reindex features for project: $project->genus ".
-         "$project->species", 'tripal_project' ,
-         'tripal_project_reindex_features', $job_args, $user->uid);
-      }
-    }
-  }
-
-  // -------------------------------------
-  // Submit the taxonomy Job if selected
-  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
-    $projects = $form_state['values']['tx-projects'];
-    foreach ($projects as $project_id) {
-      if ($project_id and preg_match("/^\d+$/i", $project_id)) {
-        // get the project info
-        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
-        $project = chado_query($sql , array(':project_id' => $project_id))->fetchObject();
-        $job_args[0] = $project_id;
-        tripal_add_job("Set taxonomy for features in project: ".
-          "$project->genus $project->species" , 'tripal_project',
-          'tripal_project_taxonify_features', $job_args, $user->uid);
-      }
-    }
-  }
-
-  // -------------------------------------
-  // Submit the Cleanup Job if selected
-  if ($form_state['values']['op'] == t('Clean up orphaned projects')) {
-    tripal_add_job('Cleanup orphaned projects', 'tripal_project',
-      'tripal_project_cleanup', $job_args, $user->uid);
-  }
-}
-/**
- * Synchronize projects from chado to drupal
- *
- * @ingroup tripal_project
- */
-function tripal_project_sync_projects($project_id = NULL, $job_id = NULL) {
-  global $user;
-  $page_content = '';
-
-  if (!$project_id) {
-    $sql = "SELECT * FROM {project} P";
-    $results = chado_query($sql);
-  }
-  else {
-    $sql = "SELECT * FROM {project} P WHERE project_id = :project_id";
-    $results = chado_query($sql, array(':project_id' => $project_id));
-  }
-
-  // We'll use the following SQL statement for checking if the project
-  // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_project} WHERE project_id = :project_id";
-
-  while ($project = $results->fetchObject()) {
-
-    // check if this project already exists in the drupal database. if it
-    // does then skip this project and go to the next one.
-    if (!db_query($sql, array(':project_id' => $project->project_id))->fetchObject()) {
-
-      $new_node = new stdClass();
-      $new_node->type = 'chado_project';
-      $new_node->uid = $user->uid;
-      $new_node->title = "$project->name";
-      $new_node->project_id = $project->project_id;
-      $new_node->name = $project->name;
-      $new_node->description = $project->description;
-      node_validate($new_node);
-      if (!form_get_errors()) {
-        $node = node_submit($new_node);
-        node_save($node);
-        if ($node->nid) {
-          print "Added $project->name\n";
-        }
-      }
-      else {
-        print "Failed to insert project $project->name\n";
-      }
-    }
-    else {
-      print "Skipped $project->name\n";
-    }
-  }
-  return $page_content;
-}
-/*
- *
- */
-function tripal_project_sync_projects_form_submit($form, &$form_state) {
-  global $user;
-
-  //sync'ing is done by a tripal_job that is added here
-  $job_id = tripal_add_job('Sync Projects', 'tripal_project',
-  'tripal_project_sync_all_projects', array(), $user->uid);
-
-}
-
-/*
- *
- */
-function tripal_project_sync_all_projects() {
-
-  //retrieve all projects in drupal
-  $resource = db_query('SELECT project_id FROM {chado_project}');
-  $drupal_projects = array();
-  while ($r = $resource->fetchObject()) {
-    $drupal_projects[$r->project_id] = $r->project_id;
-  }
-
-  // retrieve all projects in chado
-  $chado_projects = array();
-  $resource = chado_query('SELECT project_id FROM {project}');
-  while ($r = $resource->fetchObject()) {
-    // if not already in drupal add to list to be sync'd
-    if (!isset($drupal_projects[$r->project_id])) {
-      $chado_projects[$r->project_id] = $r->project_id;
-    }
-  }
-
-  print 'Number of Projects to Sync: ' . sizeof($chado_projects) . "\n";
-
-  foreach ($chado_projects as $project_id) {
-    $project = tripal_core_chado_select('project', array('name', 'description'), array('project_id' => $project_id));
-
-    // create node
-    $new_node = new stdClass();
-    $new_node->type = 'chado_project';
-    $new_node->uid = $user->uid;
-    $new_node->title = $project[0]->name;
-    $new_node->project_id = $project_id;
-    $new_node->description = $project[0]->description;
-    node_validate($new_node);
-    $errors = form_get_errors();
-    if (!$errors) {
-      $node = node_submit($new_node);
-      node_save($node);
-      if ($node->nid) {
-        print "Added " . $project[0]->name . " (Node ID:" . $node->nid . ")\n";
-      }
-    }
-    else {
-      print "Failed to insert project: " . $project[0]->name . "\n";
-      print "Errors: " . print_r($errors, TRUE) . "\n";
-    }
-
-  }
-
-
-}
-
-/**
- * Remove orphaned drupal nodes
- *
- * @param $dummy
- *   Not Used -kept for backwards compatibility
- * @param $job_id
- *   The id of the tripal job executing this function
- *
- * @ingroup tripal_project
- */
-function tripal_project_cleanup($dummy = NULL, $job_id = NULL) {
 
-  return tripal_core_chado_node_cleanup_orphaned('project', $job_id);
 }

+ 395 - 0
tripal_project/includes/tripal_project.chado_node.inc

@@ -0,0 +1,395 @@
+<?php
+
+/**
+ * Implementation of hook_form().
+ *
+ *  This form takes the Project Title information and description from the user.
+ *
+ *  @parm $node
+ *    The initialized node
+ *
+ *  @parm $form_state
+ *    The state of the form, that has the user entered information that is neccessary for adding
+ *    information to the project
+ *
+ *  @return $form
+ *    An array as described by the Drupal Form API
+ *
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_form(&$node, $form_state) {
+  $form = array();
+  
+dpm("hi");
+  // Default values can come in the following ways:
+  //
+  // 1) as elements of the $node object.  This occurs when editing an existing project
+  // 2) in the $form_state['values'] array which occurs on a failed validation or
+  //    ajax callbacks from non submit form elements
+  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
+  //    form elements and the form is being rebuilt
+  //
+  // set form field defaults
+  $project_id = null;
+  $title = '';
+  $description = '';
+  
+  // if we are editing an existing node then the project is already part of the node
+  if (property_exists($node, 'project')) {
+    $project = $node->project;
+    // get the project default values.  When this module was first created
+    // the project description was incorrectly stored in the $node->body field.
+    // It is better to store it in the Chado tables.  However, the 'description'
+    // field of the project table is only 255 characters.  So, we are going
+    // to follow the same as the project module and store the description in
+    // the projectprop table and leave the project.description field blank.
+    // however, for backwards compatibitily, we check to see if the description
+    // is in the $node->body field. If it is we'll use that.  When the node is
+    // edited the text will be moved out of the body and into the projectprop
+    // table where it should belong.
+    if ($node->body) {
+      $description = $node->body;
+    }
+    else {
+      $description = $node->description;
+    }
+    if (!$description) {
+      $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
+      $description = $projectprop->value;
+    }
+    
+    // keep track of the project id if we have.  If we do have one then
+    // this is an update as opposed to an insert.
+    $form['project_id'] = array(
+      '#type' => 'value',
+      '#value' => $project->project_id,
+    );
+  }
+  
+  // if we are re constructing the form from a failed validation or ajax callback
+  // then use the $form_state['values'] values
+  if (array_key_exists('values', $form_state)) {
+    $title       = $form_state['values']['title'];
+    $description = $form_state['values']['description'];
+  }
+  // if we are re building the form from after submission (from ajax call) then
+  // the values are in the $form_state['input'] array
+  if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
+    $title       = $form_state['input']['title'];
+    $description = $form_state['input']['description'];
+  }
+
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Project Title'),
+    '#description'   => t('Please enter the title for this project. This appears at the top of the project page.'),
+    '#required'      => TRUE,
+    '#default_value' => $node->title,
+    '#weight'        => 1
+  );
+
+  $form['description']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Project Description'),
+    '#description'   => t('A brief description of the project'),
+    '#required'      => TRUE,
+    '#default_value' => $description,
+    '#weight'        => 5
+  );
+
+  // get the project properties
+  $properties = array();
+  $properties[] = 'Select a Property';
+  $sql = "
+    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+    FROM  {cvterm} CVT
+      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
+    WHERE
+      CV.name = 'project_property' AND
+      NOT CVT.is_obsolete = 1
+    ORDER BY CVT.name ASC
+  ";
+  $prop_types = chado_query($sql);
+  while ($prop = $prop_types->fetchObject()) {
+    // because we are using the project description property as
+    // a replacement for the project.description field and we want the 
+    // user to add a description in the field above, we remove the property
+    // from the list.
+    if (strcmp($prop->name, "Project Description")==0) {
+      continue;
+    }
+    $properties[$prop->cvterm_id] = $prop->name;
+  }
+  
+  // we want to exclude the project description from being loaded as a stored property 
+  // because we want to use the property to replace the project.description field as it is
+  // only 255 characters which isn't large enough. We don't want the user to set it 
+  // as a property even though it will be stored as a property. 
+  $exclude = array('Project Description');
+  $include = array();
+  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the project_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
+  tripal_core_properties_form($form, $form_state, 'projectprop', 'project_id', 'project_property',
+    $properties, $project_id, $exclude, $include, $instructions, 'Properties');
+  
+  return $form;
+
+}
+/**
+ *  validates submission of form when adding or updating a project node
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_validate($node, $form, &$form_state) {
+  
+  $node->title = trim($node->title);
+  $node->description = trim($node->description);
+  
+  // if this is a delete then don't validate
+  if($node->op == 'Delete') {
+    return;
+  }
+  
+  // we are syncing if we do not have a node ID but we do have a project_id. We don't
+  // need to validate during syncing so just skip it.
+  if (is_null($node->nid) and property_exists($node, 'project_id') and $node->project_id != 0) {
+    return;
+  }
+  
+  $project = 0;
+  // check to make sure the name on the project is unique
+  // before we try to insert into chado.
+  if ($node->project_id) {
+    $sql = "SELECT * FROM {project} WHERE name = :name AND NOT project_id = :project_id";
+    $project = chado_query($sql, array(':name' => $node->title, ':project_id' => $node->project_id))->fetchObject();
+  }
+  else {
+    $sql = "SELECT * FROM {project} WHERE name = :name";
+    $project = chado_query($sql, array(':name' => $node->title))->fetchObject();
+  }
+  if ($project) {
+    form_set_error('title', t('The unique project name already exists. Please choose another'));
+  }
+}
+/**
+ * Implementation of hook_insert().
+ *
+ *  @parm $node
+ *    Then node that has the information stored within, accessed given the nid
+ *
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_insert($node) {
+
+  $node->title = trim($node->title);
+  $node->description = trim($node->description);
+  
+  // if there is an project_id in the $node object then this must be a sync so
+  // we can skip adding the project as it is already there, although
+  // we do need to proceed with the rest of the insert
+  if (!property_exists($node, 'project_id')) {
+    $values = array(
+      'name' => $node->title,
+      'description' => '',
+    );
+    $project = tripal_core_chado_insert('project', $values);
+    if (!$project) {
+      drupal_set_message(t('Unable to add project.', 'warning'));
+      watchdog('tripal_project', 'Insert project: Unable to create project where values:%values',
+      array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
+      return;
+    }
+    $project_id = $project['project_id'];
+    
+    // now add in the properties
+    $properties = tripal_core_properties_form_retreive($node, 'project_property');
+    foreach ($properties as $property => $elements) {
+      foreach ($elements as $rank => $value) {
+    
+        $status = tripal_project_insert_property($project_id, $property, $value, FALSE, 'project_property');
+        if (!$status) {
+          drupal_set_message("Error cannot add property: $property", "error");
+          watchdog('t_project', "Error cannot add property: %prop",
+          array('%property' => $property), WATCHDOG_ERROR);
+        }
+      }
+    }
+    
+    // add in the description as a separate property
+    tripal_project_insert_property($project_id, 'Project Description', $node->description, FALSE);
+  }
+  else {
+    $project_id = $node->project_id;
+  }
+
+  // Make sure the entry for this project doesn't already exist in the
+  // chado_project table if it doesn't exist then we want to add it.
+  $check_org_id = chado_get_id_for_node('project', $node->nid);
+  if (!$check_org_id) {
+    $record = new stdClass();
+    $record->nid = $node->nid;
+    $record->vid = $node->vid;
+    $record->project_id = $project_id;
+    drupal_write_record('chado_project', $record);
+  }
+}
+
+/**
+ *
+ * Implementation of hook_delete().
+ *
+ * @param $node
+ * The node which is to be deleted, only chado project and chado_project need to be dealt with
+ * since the drupal node is deleted automagically
+ *
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_delete($node) {
+
+  $project_id = chado_get_id_for_node('project', $node->nid);
+
+  // if we don't have a project id for this node then this isn't a node of
+  // type chado_project or the entry in the chado_project table was lost.
+  if (!$project_id) {
+    return;
+  }
+
+  // Remove data from {chado_project}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_project} 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 = :vod";
+  db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
+
+  // Remove data from project and projectprop tables of chado database as well
+  chado_query("DELETE FROM {projectprop} WHERE project_id = :project_id", array(':project_id' => $project_id));
+  chado_query("DELETE FROM {project} WHERE project_id = :project_id", array(':project_id' => $project_id));
+}
+
+/**
+ * Implements hook_update().
+ *
+ * @param $node
+ *  The node which is to have its containing information updated when the user modifies information
+ *  pertaining to the specific project
+ *
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_update($node) {
+  
+  $node->title = trim($node->title);
+  $node->description = trim($node->description);
+
+  // update the project and the description
+  $project_id = chado_get_id_for_node('project', $node->nid) ;
+  $match = array('project_id' => $project_id);
+  $values = array(
+    'name' => $node->title,
+    'description' => '',
+  );
+  $status = tripal_core_chado_update('project', $match, $values);
+  if (!$status) {
+    drupal_set_message(t('Unable to update project.', 'warning'));
+    watchdog('tripal_project', 'Update project: Unable to update project where values: %values',
+    array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
+  }
+  
+  // now add in the properties by first removing any the project
+  // already has and adding the ones we have
+  tripal_core_chado_delete('projectprop', array('project_id' => $project_id));
+  $properties = tripal_core_properties_form_retreive($node, 'project_property');
+  foreach ($properties as $property => $elements) {
+    foreach ($elements as $rank => $value) {
+      $status = tripal_project_insert_property($project_id, $property, $value, FALSE, 'project_property');
+      if (!$status) {
+        drupal_set_message("Error cannot add property: '$property'", "error");
+        watchdog('t_project', "Error cannot add property: '%prop'",
+        array('%prop' => $property), WATCHDOG_ERROR);
+      }
+    }
+  }
+  
+  // add the project description as a property
+  tripal_project_update_property($project_id, 'Project Description', $node->description, 1);
+}
+
+/**
+ * Implementation of node_load().
+ *
+ * @param $node
+ *   The node that is to have its containing information loaded
+ *
+ * @return $node
+ *   The node, containing the loaded project with the current nid
+ *
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_load($nodes) {
+
+  foreach ($nodes as $nid => $node) {
+    // get the feature details from chado
+    $project_id = chado_get_id_for_node('project', $node->nid);
+  
+    $values = array('project_id' => $project_id);
+    $project = tripal_core_generate_chado_var('project', $values);
+  
+    $nodes[$nid]->project = $project;
+  }
+
+}
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ * @ingroup tripal_project
+ */
+function chado_project_node_access($node, $op, $account) {
+
+  if ($op == 'create') {
+    if (!user_access('create chado_projects content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_projects content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_projects content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_projects content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}

+ 0 - 142
tripal_project/theme/node--chado-project.tpl.php

@@ -1,142 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the project node (page)
-//   using the same templates used for the various project content blocks.
-//
-// To Customize the Libray 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 the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-
-$project  = $variables['node']->project;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and 
-   $template_settings['tripal_no_sidebar']['project']) {
-  $no_sidebar = 1;
-}
-
-if ($teaser) { 
-  print theme('tripal_project_teaser',$node); 
-} 
-else { ?>
-
-<script type="text/javascript">
-(function ($) {
-  Drupal.behaviors.projectBehavior = {
-    attach: function (context, settings){ <?php 
-      if ($no_sidebar) { ?>    
-        // hide the resource side bar and strech the details section    
-        $(".tripal_toc").hide();
-        $(".tripal_details").addClass("tripal_details_full");
-        $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
-      } ?>
- 
-      // iterate through all of the info boxes and add their titles
-      // to the table of contents
-      $(".tripal-info-box-title").each(function(){
-        var parent = $(this).parent();
-        var id = $(parent).attr('id');
-        var title = $(this).text();
-        $('#tripal_project_toc_list').append('<li><a href="#'+id+'" class="tripal_project_toc_item">'+title+'</a></li>');
-      });
-
-      // when a title in the table of contents is clicked, then
-      // show the corresponding item in the details box
-      $(".tripal_project_toc_item").click(function(){
-         $(".tripal-info-box").hide();
-         href = $(this).attr('href');
-         $(href).fadeIn('slow');
-         // we want to make sure our table of contents and the details
-         // box stay the same height
-         $("#tripal_project_toc").height($(href).parent().height());
-         return false;
-      }); 
-
-      // we want the base details to show up when the page is first shown 
-      // unless the user specified a specific block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
-      if(block == null){
-         block = window.location.href.match(/[\?|\&]block=(.+)/)
-      }
-      if(block != null){
-         $("#tripal_project-"+block[1]+"-box").show();
-      } else {
-         $("#tripal_project-base-box").show();
-      }
-
-      $("#tripal_project_toc").height($("#tripal_project-base-box").parent().height());
-    }     
-  };
-})(jQuery);
-</script>
-
-<div id="tripal_project_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_project_base',$node); ?>
-   
-   <!-- Properties Theme -->
-   <?php print theme('tripal_project_properties',$node); ?>
-   
-   <!-- Contact Theme -->
-   <?php print theme('tripal_project_contact',$node); ?>
-   
-   <!-- Relationships Theme -->
-   <?php print theme('tripal_project_relationships',$node); ?>
-   
-   <!-- Publications Theme -->
-   <?php print theme('tripal_project_publications',$node); ?>
-
-   <!-- Resource Blocks CCK elements --><?php
-   for($i = 0; $i < count($node->field_resource_titles); $i++){
-     if($node->field_resource_titles[$i]['value']){ ?>
-       <div id="tripal_project-resource_<?php print $i?>-box" class="tripal_project-info-box tripal-info-box">
-         <div class="tripal_project-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-         <?php print $node->field_resource_blocks[$i]['value']; ?>
-       </div><?php
-     }
-   }?>
-   
-   <!-- Let modules add more content -->
-
-   <?php print $content ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_project_toc" class="tripal_toc">
-   <div id="tripal_project_toc_title" class="tripal_toc_title">Resources</div>
-   <ul id="tripal_project_toc_list" class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }?>
-     
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-
-<?php } ?>

+ 0 - 0
tripal_project/theme/tripal_project_help.tpl.php → tripal_project/theme/tripal_project.help.tpl.php


+ 1 - 0
tripal_project/theme/tripal_project.theme.inc

@@ -0,0 +1 @@
+<?php

+ 84 - 0
tripal_project/theme/tripal_project/tripal_project.base.tpl.php

@@ -0,0 +1,84 @@
+<?php
+$project = $variables['node']->project;
+
+// get the project description.  The first iteration of the project
+// module incorrectly stored the project description in the Drupal 
+// node->body field.  Also, the project.descriptin field is only 255
+// characters which is not large neough. Therefore, we store the description
+// in the  chado.projectprop table.  For backwards compatibility, we 
+// will check if the node->body is empty and if not we'll use that instead.
+// If there is data in the project.description field then we will use that, but
+// if there is data in the projectprop table for a descrtion then that takes 
+// precedence 
+$description = '';
+if ($node->body) {
+  $description = $node->body;
+}
+if ($node->description) {
+  $description = $project->description;
+}
+else {
+  $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
+  $description = $projectprop->value;
+}
+
+?>
+<div id="tripal_project-base-box" class="tripal_project-info-box tripal-info-box">
+  <div class="tripal_project-info-box-title tripal-info-box-title">Project Details</div>
+  <div class="tripal_project-info-box-desc tripal-info-box-desc"></div><?php 
+
+  // the $headers array is an array of fields to use as the colum headers. 
+  // additional documentation can be found here 
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  // This table for the project has a vertical header (down the first column)
+  // so we do not provide headers here, but specify them in the $rows array below.
+  $headers = array();
+  
+  // the $rows array contains an array of rows where each row is an array
+  // of values for each column of the table in that row.  Additional documentation
+  // can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+  $rows = array();
+
+  // Project Name row
+  $rows[] = array(
+    array(
+      'data' => 'Project Name',
+      'header' => TRUE
+    ),
+    $project->name
+  );
+  // allow site admins to see the feature ID
+  if (user_access('access administration pages')) {
+    // Project ID
+    $rows[] = array(
+      array(
+        'data' => 'Project ID',
+        'header' => TRUE
+      ),
+      $project->project_id
+    );
+  }
+  // the $table array contains the headers and rows array as well as other
+  // options for controlling the display of the table.  Additional
+  // documentation can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_project-table-base',
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  
+  // once we have our table array structure defined, we call Drupal's theme_table()
+  // function to generate the table.
+  print theme_table($table);
+  if ($description) { ?>
+    <div style="text-align: justify"><?php print $description; ?></div> <?php  
+  } ?>
+</div>

+ 77 - 0
tripal_project/theme/tripal_project/tripal_project.contact.tpl.php

@@ -0,0 +1,77 @@
+<?php
+$project = $variables['node']->project;
+
+// expand the project object to include the contacts from the project_contact
+// table in chado.
+$project = tripal_core_expand_chado_vars($project,'table','project_contact', array('return_array' => 1));
+$project_contacts = $project->project_contact;
+
+if (count($project_contacts) > 0) { ?>
+  <div id="tripal_project-contacts-box" class="tripal_project-info-box tripal-info-box">
+    <div class="tripal_project-info-box-title tripal-info-box-title">People</div>
+    <div class="tripal_project-info-box-desc tripal-info-box-desc">The following people particpated in development or execution of this project</div><?php     
+    
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Property Name', 'Value');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($project_contacts as $project_contact) {
+      $contact = $project_contact->contact_id;
+      $contact_name = $contact->name;
+      if (property_exists($contact, 'nid')) {
+        $contact_name = l($contact_name, 'node/' . $contact->nid, array('attributes' => array('target' => '_blank')));
+      }
+      
+      // Get some additional details about this contact if they exists.
+      $details = '';
+      $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
+      $properties = $contact->contactprop;
+      $options = array('order_by' => array('rank' => 'ASC'));
+      $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options);
+      
+      if (is_array($properties)) {
+        foreach ($properties as $property) {
+          // skip the description and name properties
+          if ($property->type_id->name == "contact_description" or
+              $property->type_id->name == "Surname" or
+              $property->type_id->name == "Given Name" or
+              $property->type_id->name == "First Initials" or
+              $property->type_id->name == "Suffix") {
+            continue;
+          }
+          $details .= "<br>" . $property->type_id->name . " : " .  $property->value;
+        }
+      }
+      
+      $rows[] = array(
+        $contact_name . $details,
+      );
+    } 
+        // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_pub-table-contacts',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table);?>    
+  </div> <?php 
+}

+ 65 - 0
tripal_project/theme/tripal_project/tripal_project.properties.tpl.php

@@ -0,0 +1,65 @@
+<?php
+
+// expand the project to include the properties.
+$project = $variables['node']->project;
+$project = tripal_core_expand_chado_vars($project,'table', 'projectprop', array('return_array' => 1));
+$projectprops = $project->projectprop;
+
+// put the properties in an array so we can remove the project_description property
+$properties = array();
+if ($projectprops) {
+  foreach ($projectprops as $property) {
+    // we want to keep all properties but the project_description as that
+    // property is shown on the base template page.
+    if($property->type_id->name != 'Project Description') {
+      $property = tripal_core_expand_chado_vars($property,'field','projectprop.value');
+      $properties[] = $property;
+    }
+  }
+}
+
+
+if (count($properties) > 0) { ?>
+  <div id="tripal_project-properties-box" class="tripal_project-info-box tripal-info-box">
+    <div class="tripal_project-info-box-title tripal-info-box-title">More Details</div>
+    <div class="tripal_project-info-box-desc tripal-info-box-desc">Additional information about this project:</div><?php
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Property Name', 'Value');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    // add the properties as individual rows
+    foreach ($properties as $property) {
+      $rows[] = array(
+        ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
+        $property->value
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_project-table-properties',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php
+}

+ 78 - 0
tripal_project/theme/tripal_project/tripal_project.publications.tpl.php

@@ -0,0 +1,78 @@
+<?php
+$project = $variables['node']->project;
+
+// expand project to include pubs 
+$options = array('return_array' => 1);
+$project = tripal_core_expand_chado_vars($project, 'table', 'project_pub', $options);
+$project_pubs = $project->project_pub; 
+
+
+if (count($project_pubs) > 0) { ?>
+  <div id="tripal_project_pub-pub-box" class="tripal_project_pub-info-box tripal-info-box">
+    <div class="tripal_project_pub-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_project_pub-info-box-desc tripal-info-box-desc"></div> <?php 
+  
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Year', 'Publication');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($project_pubs as $project_pub) {
+      $pub = $project_pub->pub_id;
+      $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+      $citation = $pub->title;  // use the title as the default citation
+      
+      // get the citation for this pub if it exists
+      $values = array(
+        'pub_id' => $pub->pub_id, 
+        'type_id' => array(
+          'name' => 'Citation',
+        ),
+      );
+      $options = array('return_array' => 1);
+      $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+      if (count($citation_prop) == 1) {
+        $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+        $citation = $citation_prop[0]->value;
+      }
+      
+      // if the publication is synced then link to it
+      if ($pub->nid) {
+        // replace the title with a link
+        $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
+        $citation = preg_replace('/' . $pub->title . '/', $link, $citation);
+      }
+      
+      $rows[] = array(
+        $pub->pyear,
+        $citation,
+      );
+    }
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_project-table-publications',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php 
+}

+ 129 - 0
tripal_project/theme/tripal_project/tripal_project.relationships.tpl.php

@@ -0,0 +1,129 @@
+<?php
+/* Typically in a Tripal template, the data needed is retrieved using a call to
+ * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * of the project relationships for this node, the following function call would be made:
+ * 
+ *   $project = tripal_core_expand_chado_vars($project,'table','project_relationship');
+ * 
+ * However, this function call can be extremely slow when there are numerous relationships.
+ * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * all data following the foreign key relationships tree.  Therefore, to speed retrieval
+ * of data, a special variable is provided to this template:
+ * 
+ *   $project->all_relationships;
+ *   
+ * This variable is an array with two sub arrays with the keys 'object' and 'subject'.  The array with
+ * key 'object' contains relationships where the project is the object, and the array with
+ * the key 'subject' contains relationships where the project is the subject
+ */
+$project = $variables['node']->project;
+
+$all_relationships = $project->all_relationships;
+$object_rels = $all_relationships['object'];
+$subject_rels = $all_relationships['subject'];
+
+if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
+  <div id="tripal_project-relationships-box" class="tripal_project-info-box tripal-info-box">
+    <div class="tripal_project-info-box-title tripal-info-box-title">Relationships</div>
+    <div class="tripal_project-info-box-desc tripal-info-box-desc"></div> <?php
+    // first add in the subject relationships.  
+    foreach ($subject_rels as $rel_type => $rels){
+      foreach ($rels as $obj_type => $objects){ ?>
+        <p>This <?php print $project->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> project(s): <?php
+         
+        // the $headers array is an array of fields to use as the colum headers.
+        // additional documentation can be found here
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $headers = array('Name');
+        
+        // the $rows array contains an array of rows where each row is an array
+        // of values for each column of the table in that row.  Additional documentation
+        // can be found here:
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $rows = array();
+        
+        foreach ($objects as $object){
+          // link the project to it's node
+          $project_name = $object->record->object_id->name;
+          if (property_exists($object->record, 'nid')) {
+            $project_name = "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
+          }
+
+          $rows[] = array(
+            $project_name, 
+          ); 
+         } 
+         // the $table array contains the headers and rows array as well as other
+         // options for controlling the display of the table.  Additional
+         // documentation can be found here:
+         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+         $table = array(
+           'header' => $headers,
+           'rows' => $rows,
+           'attributes' => array(
+             'id' => 'tripal_project-table-relationship-object',
+           ),
+           'sticky' => FALSE,
+           'caption' => '',
+           'colgroups' => array(),
+           'empty' => '',
+         );
+         
+         // once we have our table array structure defined, we call Drupal's theme_table()
+         // function to generate the table.
+         print theme_table($table); ?>
+         </p>
+         <br><?php
+       }
+    }
+    
+    // second add in the object relationships.  
+    foreach ($object_rels as $rel_type => $rels){
+      foreach ($rels as $subject_type => $subjects){?>
+        <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> project(s) are <?php print $rel_type ?> this <?php print $project->type_id->name;?>: <?php 
+        // the $headers array is an array of fields to use as the colum headers.
+        // additional documentation can be found here
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $headers = array('Name');
+        
+        // the $rows array contains an array of rows where each row is an array
+        // of values for each column of the table in that row.  Additional documentation
+        // can be found here:
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $rows = array();
+        
+        foreach ($subjects as $subject){
+          // link the project to it's node
+          $project_name = $subject->record->subject_id->name;
+          if (property_exists($subject->record, 'nid')) {
+            $project_name = "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
+          }
+          $rows[] = array(
+            $project_name, 
+          ); 
+         } 
+         // the $table array contains the headers and rows array as well as other
+         // options for controlling the display of the table.  Additional
+         // documentation can be found here:
+         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+         $table = array(
+           'header' => $headers,
+           'rows' => $rows,
+           'attributes' => array(
+             'id' => 'tripal_project-table-relationship-subject',
+           ),
+           'sticky' => FALSE,
+           'caption' => '',
+           'colgroups' => array(),
+           'empty' => '',
+         );
+         
+         // once we have our table array structure defined, we call Drupal's theme_table()
+         // function to generate the table.
+         print theme_table($table); ?>
+         </p>
+         <br><?php
+       }
+    }?>
+  </div> <?php
+}

+ 36 - 0
tripal_project/theme/tripal_project/tripal_project.teaser.tpl.php

@@ -0,0 +1,36 @@
+<?php
+$node    = $variables['node'];
+$project = $variables['node']->project;
+
+// get the project description.  The first iteration of the project
+// module incorrectly stored the project description in the Drupal 
+// node->body field.  Also, the project.descriptin field is only 255
+// characters which is not large neough. Therefore, we store the description
+// in the  chado.projectprop table.  For backwards compatibility, we 
+// will check if the node->body is empty and if not we'll use that instead.
+// If there is data in the project.description field then we will use that, but
+// if there is data in the projectprop table for a descrtion then that takes 
+// precedence 
+$description = '';
+if ($node->body) {
+  $description = $node->body;
+}
+if ($node->description) {
+  $description = $project->description;
+}
+else {
+  $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
+  $description = $projectprop->value;
+} ?>
+
+<div class="tripal_project-teaser tripal-teaser"> 
+  <div class="tripal-project-teaser-title tripal-teaser-title"><?php 
+    print l($node->title, "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-project-teaser-text tripal-teaser-text"><?php 
+    print substr($description, 0, 650);
+    if (strlen($description) > 650) {
+      print "... " . l("[more]", "node/$node->nid");
+    } ?>
+  </div>
+</div>

+ 0 - 53
tripal_project/theme/tripal_project/tripal_project_base.tpl.php

@@ -1,53 +0,0 @@
-<?php
-$node = $variables['node'];
-$project = $variables['node']->project;
-
-// get the project description.  The first iteration of the project
-// module incorrectly stored the project description in the Drupal 
-// node->body field.  It should have been in the chado.projectprop 
-// table.  Therefore, for backwards compatibility, we will check if the
-// node->body is empty and if not we'll use that instead. Otherwise,
-// we'll pull from the projectprop table.
-$project_description = '';
-if ($node->body) {
-  $project_description = $node->body;
-}
-else {
-  // expand the project to include the properties.
-  $project = tripal_core_expand_chado_vars($project,'table','projectprop', array('return_array' => 1));  
-  $projectprops = $project->projectprop;
-  foreach ($projectprops as $property) {
-    if($property->type_id->name == 'project_description') {
-      $property = tripal_core_expand_chado_vars($property,'field','projectprop.value');
-      $project_description = $property->value;      
-    }
-  }
-  // if there is no project_description property then see if
-  // there is anything in the project.description field.  This field is only 255
-  // characters and isn't large enough for some project description, which is why
-  // the description is stored as a property.  But if we have no property then
-  // use the field
-  if (!$project_description) {
-    // we expect the project.description field will one day get changed to
-    // a text field so, we'll expand it now so that the template won't break if the field ever does change.
-    tripal_core_expand_chado_vars($project,'field','project.description');
-    $project_description = $project->description;
-  }
-}
-
-?>
-<div id="tripal_project-base-box" class="tripal_project-info-box tripal-info-box">
-  <div class="tripal_project-info-box-title tripal-info-box-title">Project Details</div>
-  <div class="tripal_project-info-box-desc tripal-info-box-desc"></div>   
-
-  <table id="tripal_project-table-base" class="tripal_project-table tripal-table tripal-table-vert">
-    <tr class="tripal_project-table-even-row tripal-table-even-row">
-      <th>Project Name</th>
-      <td><?php print $project->name; ?></td>
-    </tr>
-    <tr class="tripal_project-table-odd-row tripal-table-odd-row">
-      <th>Description</th>
-      <td><?php print $project_description?></td>
-    </tr>
-  </table> 
-</div>

+ 0 - 50
tripal_project/theme/tripal_project/tripal_project_contact.tpl.php

@@ -1,50 +0,0 @@
-<?php
-$project = $variables['node']->project;
-
-// expand the project object to include the contacts from the project_contact
-// table in chado.
-$project = tripal_core_expand_chado_vars($project,'table','project_contact', array('return_array' => 1));
-$contacts = $project->project_contact;
-
-if (count($contacts) > 0) { ?>
-  <div id="tripal_project-contacts-box" class="tripal_project-info-box tripal-info-box">
-    <div class="tripal_project-info-box-title tripal-info-box-title">People</div>
-    <div class="tripal_project-info-box-desc tripal-info-box-desc">The following people particpated in development or execution of this project</div><?php     
-    $i = 0; 
-    foreach ($contacts as $contact) { ?>
-      <b><?php print $contact->contact_id->name ?></b>, <?php print $contact->contact_id->description ?>
-      <table id="tripal_project-contacts-table" class="tripal_project-table tripal-table tripal-table-horz"> <?php
-      
-        // expand the contact to include the properties.  This table doesn't
-        // actually exist in Chado v1.11 or Chado v1.2. But, for some sites it has been
-        // added manually, and it is expected that this table will be added to fiture
-        // versions of Chado, so the code is included below to handle contact properties.
-        $contact = tripal_core_expand_chado_vars($contact,'table','contactprop');       
-        if ($contact->contactprop) {
-          foreach ($contact->contactprop as $prop) {
-             $class = 'tripal-table-odd-row';
-             if ($i % 2 == 0 ) {
-               $class = 'tripal-table-even-row';
-             }
-             # make the type a bit more reader friendly
-             $type = $prop->type_id->name;
-             $type = preg_replace("/_/", " ", $type);
-             $type = ucwords($type);
-             ?>
-             <tr class="<?php print $class ?>">
-               <td> <?php print $type ?></td>
-               <td> <?php print $prop->value ?></td>
-             </tr> <?php
-             $i++;  
-          } 
-        }
-        /* else { ?>
-          <tr class="tripal-table-odd-row">
-            <td>No contact information available for <?php print $contact->contact_id->name ?></td>
-          </tr> <?php
-        } */
-        ?>
-      </table> <?php 
-    } ?>    
-  </div> <?php 
-}

+ 0 - 41
tripal_project/theme/tripal_project/tripal_project_properties.tpl.php

@@ -1,41 +0,0 @@
-<?php
-$project = $node->project;
-
-// expand the project to include the properties.
-$project = tripal_core_expand_chado_vars($project,'table', 'projectprop', array('return_array' => 1));
-$projectprops = $project->projectprop;
-$properties = array();
-foreach ($projectprops as $property) {
-  // we want to keep all properties but the project_description as that
-  // property is shown on the base template page.
-  if($property->type_id->name != 'project_description') {
-    $property = tripal_core_expand_chado_vars($property,'field','projectprop.value');
-    $properties[] = $property;
-  }
-}
-
-if (count($properties) > 0) { ?>
-  <div id="tripal_project-properties-box" class="tripal_project-info-box tripal-info-box">
-    <div class="tripal_project-info-box-title tripal-info-box-title">Properties</div>
-    <div class="tripal_project-info-box-desc tripal-info-box-desc">Properties for this project include:</div>
-    <table class="tripal_project-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Property Name</th>
-        <th>Value</th>
-      </tr> <?php
-      $i = 0;
-      foreach ($properties as $property) {
-        $class = 'tripal_project-table-odd-row tripal-table-odd-row';
-        if ($i % 2 == 0 ) {
-           $class = 'tripal_project-table-odd-row tripal-table-even-row';
-        }
-        $i++; 
-        ?>
-        <tr class="<?php print $class ?>">
-          <td><?php print ucfirst(preg_replace('/_/', ' ', $property->type_id->name)) ?></td>
-          <td><?php print $property->value ?></td>
-        </tr><?php 
-      } ?>
-    </table>
-  </div> <?php
-}

+ 0 - 58
tripal_project/theme/tripal_project/tripal_project_publications.tpl.php

@@ -1,58 +0,0 @@
-<?php
-$project  = $variables['node']->project;
-
-// expand project to include pubs 
-$project = tripal_core_expand_chado_vars($project, 'table', 'project_pub', array('return_array' => 1));
-$project_pubs = $project->project_pub;
-
-if (count($project_pubs) > 0) { ?>
-  <div id="tripal_project-pub-box" class="tripal_project-info-box tripal-info-box">
-    <div class="tripal_project-info-box-title tripal-info-box-title">Publications</div>
-    <div class="tripal_project-info-box-desc tripal-info-box-desc"></div>
-  
-    <table id="tripal_project-pub-table" class="tripal_project-table tripal-table tripal-table-vert" style="border-bottom:solid 2px #999999">
-      <tr>
-        <th>Year</th>
-        <th>Publication</th>
-      </tr> <?php
-      $i = 0;
-      foreach ($project_pubs AS $project_pubs) {
-        $pub = $project_pubs->pub_id;
-        $class = 'tripal_project-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_project-table-odd-row tripal-table-even-row';
-        }
-        $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title'); 
-        $citation = $pub->title;  // use the title as the default citation
-        
-        // get the citation for this pub if it exists
-        $values = array(
-          'pub_id' => $pub->pub_id, 
-          'type_id' => array(
-            'name' => 'Citation',
-          ),
-        );
-
-        $options = array('return_array' => 1);
-        $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
-        if (count($citation_prop) == 1) {
-          $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
-          $citation = $citation_prop[0]->value;
-        }
-        
-        // if the publication is synced then link to it
-        if ($pub->nid) {
-          // replace the title with a link
-          $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
-          $citation = preg_replace('/' . $pub->title . '/', $link, $citation);
-        }
-        ?>
-        <tr class="<?php print $class ?>">
-          <td><?php print $pub->pyear ?></td>
-          <td><?php print $citation ?></td>
-        </tr><?php 
-        $i++;
-      }  ?>
-    </table>
-  </div><?php 
-}

+ 0 - 81
tripal_project/theme/tripal_project/tripal_project_relationships.tpl.php

@@ -1,81 +0,0 @@
-<?php
-// this template does not follow the typical Tripal API. Normally
-// variables are expanded using the tripal_core_expand_chado_vars API
-// function call, but expanding the relationships table does not yeild
-// a meaningful order to the data.  Therefore, relationships are preprocessed
-// into an array named 'all_relationships', which is used in the template below.
-
-$project = $variables['node']->project;
-
-$all_relationships = $project->all_relationships;
-$object_rels = $all_relationships['object'];
-$subject_rels = $all_relationships['subject'];
-
-// make the project type a bit more human readable
-$project_type =  preg_replace("/_/", ' ', $project->type_id->name);
-
-if (count($object_rels) > 0 or count($subject_rels) > 0) {
-?>
-  <div id="tripal_project-relationships-box" class="tripal_project-info-box tripal-info-box">
-    <div class="tripal_project-info-box-title tripal-info-box-title">Relationships</div>
-    <!--  <div class="tripal_project-info-box-desc tripal-info-box-desc"></div> --><?php
-    
-      // first add in the subject relationships.  
-      foreach ($subject_rels as $rel_type => $rels){
-         // make the type a bit more human readable
-         $rel_type = preg_replace("/_/", ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through each parent   
-         foreach ($rels as $obj_type => $objects){?>
-           <p>This project is a <b><?php print $rel_type ?></b> of the following project(s):
-           <table id="tripal_project-relationships_as_object-table" class="tripal_project-table tripal-table tripal-table-horz">
-             <tr>
-               <th>Project Name</th>
-             </tr> <?php
-             foreach ($objects as $object){ ?>
-               <tr>
-                 <td><?php 
-                    if ($object->nid) {
-                      print "<a href=\"" . url("node/" . $object->nid) . "\" target=\"_blank\">" . $object->name . "</a>";
-                    }
-                    else {
-                      print $object->name;
-                    } ?>
-                 </td>
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      }
-      
-      // second add in the object relationships.  
-      foreach ($object_rels as $rel_type => $rels){
-         // make the type more human readable
-         $rel_type = preg_replace('/_/', ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through the children         
-         foreach ($rels as $subject_type => $subjects){?>
-           <p>The following projects are a <b><?php print $rel_type ?></b> of this project:
-           <table id="tripal_project-relationships_as_object-table" class="tripal_project-table tripal-table tripal-table-horz">
-             <tr>
-               <th>Project Name</th>
-             </tr> <?php
-             foreach ($subjects as $subject){ ?>
-               <tr>
-                 <td><?php 
-                    if ($subject->nid) {
-                      print "<a href=\"" . url("node/" . $subject->nid) . "\" target=\"_blank\">" . $subject->name . "</a>";
-                    }
-                    else {
-                      print $subject->name;
-                    } ?>
-                 </td>
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      } ?>
-  </div> <?php
-}

+ 0 - 20
tripal_project/theme/tripal_project/tripal_project_teaser.tpl.php

@@ -1,20 +0,0 @@
-<?php
-$node = $variables['node'];
-$project = $variables['node']->project;
-
-?>
-<div id="tripal_project-base-box" class="tripal_project-info-box tripal-info-box">
-  <div class="tripal_project-info-box-title tripal-info-box-title">Project Details</div>
-  <div class="tripal_project-info-box-desc tripal-info-box-desc"></div>   
-
-  <table id="tripal_project-table-base" class="tripal_project-table tripal-table tripal-table-vert">
-    <tr class="tripal_project-table-even-row tripal-table-even-row">
-      <th>Project Name</th>
-      <td><?php print $project->name; ?></td>
-    </tr>
-    <tr class="tripal_project-table-odd-row tripal-table-odd-row">
-      <th>Description</th>
-      <td><i><?php print $project->description; ?></i></td>
-    </tr>
-  </table> 
-</div>

+ 41 - 6
tripal_project/tripal_project.install

@@ -86,14 +86,49 @@ function tripal_project_schema() {
   return $schema;
 }
 
-/*
+/**
+ * 
+ */
+function tripal_project_add_cvs() {
+  tripal_cv_add_cv('project_property', 'Contains properties for projects');
+}
+/**
  *
  */
 function tripal_project_add_cvterms() {
 
-  // Insert cvterm 'library_description' into cvterm table of chado
-  // database. This CV term is used to keep track of the library
-  // description in the libraryprop table.
-  tripal_cv_add_cvterm(array('name' => 'project_description', 'def' => 'Description of a project'),
-    'tripal', 0, 1, 'tripal');
+  // Insert cvterm 'project_description' into cvterm table of chado
+  // database. This CV term is used to keep track of the project
+  // description in the projectprop table.
+  tripal_cv_add_cvterm(
+    array(
+      'name' => 'Project Description', 
+      'def'  => 'Description of a project'
+    ),
+    'project_property', 0, 1, 'tripal'
+  );
+}
+
+/**
+ * This is the required update for tripal_project when upgrading from Drupal core API 6.x.
+ */
+function tripal_project_update_7000() {
+
+  // For Tripal in Drupal 6 the project_description cvterm was stored in the
+  // 'tripal' CV.  It should be stored in the new project_property CV that
+  // is added by this module for Tripal 2.0 and Drupal 7.  So, we need to
+  // reset the CV ID for that term and rename the term to 'Project Description'
+  tripal_project_add_cvs();
+  $cv = tripal_cv_get_cv_by_name('project_property');
+  $cvterm = tripal_cv_get_cvterm_by_name('project_description', $cv->cv_id);
+  $match = array(
+    'cvterm_id' => $cvterm->cvterm_id,
+  );
+  $values = array(
+    'name'  => 'Project Description',
+  );
+  tripal_core_chado_update('cvterm', $match, $values);
+  if (!$success) {
+    throw new DrupalUpdateException('Failed to move project properties to new project_property CV.');
+  }
 }

+ 95 - 303
tripal_project/tripal_project.module

@@ -30,12 +30,24 @@ function tripal_project_node_info() {
     'chado_project' => array(
       'name' => t('Project'),
       'base' => 'chado_project',
-      'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of projects'),
+      'description' => t('A project from the Chado database'),
       'has_title' => TRUE,
       'title_label' => t('Project Name'),
       'had_body' => TRUE,
       'body_label' => t('Full Description'),
-    )
+      'chado_node_api' => array(
+        'base_table' => 'project',
+        'hook_prefix' => 'chado_project',
+        'record_type_title' => array(
+          'singular' => t('Project'),
+          'plural' => t('Projects')
+        ),
+        'sync_filters' => array(
+          'type_id' => FALSE,
+          'organism_id' => FALSE
+        ),
+      ),
+    ),
   );
 }
 
@@ -63,23 +75,23 @@ function tripal_project_views_api() {
 function tripal_project_menu() {
   $items[ 'admin/tripal/chado/tripal_project' ]= array(
     'title' => 'Projects',
-    'description' => ('A grouping of a variety of data (ie: group natural diversity experiment).'),
+    'description' => ('A project. Can be used for grouping data such as with the natural diversity module data.'),
     'page callback' => 'tripal_project_admin_project_view',
     'access arguments' => array('adminster tripal projects'),
     'type' => MENU_NORMAL_ITEM
   );
 
-  $items[ 'admin/tripal/chado/tripal_project/help' ]= array(
+  $items['admin/tripal/chado/tripal_project/help']= array(
     'title' => 'Help',
-    'description' => ("A description of the Tripal Project module including a short description of it's usage."),
+    'description' => ("Basic Description of Tripal Project Module Functionality."),
     'page callback' => 'theme',
-    'page arguments' => array('tripal_project_help'),
+    'page arguments' => array('tripal_project.help'),
     'access arguments' => array('adminster tripal projects'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 6
   );
 
-  $items[ 'admin/tripal/chado/tripal_project/configuration' ]= array(
+  $items['admin/tripal/chado/tripal_project/configuration']= array(
     'title' => 'Settings',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_project_admin'),
@@ -88,11 +100,21 @@ function tripal_project_menu() {
     'weight' => 4
   );
 
+  $items['admin/tripal/chado/tripal_project/sync'] = array(
+    'title' => ' Sync',
+    'description' => 'Create pages on this site for projects stored in Chado',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_project', 'chado_project'),
+    'access arguments' => array('administer tripal projects'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 0
+  );
+  
   $items['admin/tripal/chado/tripal_project/views/projects/enable'] = array(
     'title' => 'Enable Project Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_project_admin_projects', 'admin/tripal/chado/tripal_project'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('administer tripal projects'),
     'type' => MENU_CALLBACK,
   );
 
@@ -143,55 +165,7 @@ function tripal_project_permission() {
   );
 }
 
-/**
- * Implement hook_access().
- *
- * This hook allows node modules to limit access to the node types they define.
- *
- *  @param $node
- *  The node on which the operation is to be performed, or, if it does not yet exist, the
- *  type of node to be created
- *
- *  @param $op
- *  The operation to be performed
- *
- *
- *  @param $account
- *  A user object representing the user for whom the operation is to be performed
- *
- *  @return
- *  If the permission for the specified operation is not set then return FALSE. If the
- *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always
- *  return TRUE if the permission is set.
- *
- * @ingroup tripal_project
- */
-function chado_project_node_access($node, $op, $account) {
 
-  if ($op == 'create') {
-    if (!user_access('create chado_projects content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
-  }
-  if ($op == 'update') {
-    if (!user_access('edit chado_projects content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_projects content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_projects content', $account)) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
 
 /**
  *  We need to let drupal know about our theme functions and their arguments.
@@ -200,270 +174,88 @@ function chado_project_node_access($node, $op, $account) {
  *
  * @ingroup tripal_project
  */
-function tripal_project_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_project') . '/theme';
+function tripal_project_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
 
   $items = array(
-    'tripal_project_base' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_project_base',
-      'path' => "$theme_path/tripal_project",
+    'node__chado_project' => array(
+      'template' => 'node--chado-generic',
+      'render element' => 'node',
+      'base hook' => 'node',
+      'path' => "$core_path/theme",
+    ),
+    'tripal_project.base' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.base',
+      'path' => "$path/theme/tripal_project",
+    ),
+    'tripal_project.contact' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.contact',
+      'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project_contact' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_project_contact',
-      'path' => "$theme_path/tripal_project",
+    'tripal_project.properties' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.properties',
+      'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project_publications' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_project_publications',
-      'path' => "$theme_path/tripal_project",
+    'tripal_project.publications' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.publications',
+      'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project_relationships' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_project_relationships',
-      'path' => "$theme_path/tripal_project",
+    'tripal_project.relationships' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.relationships',
+      'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project_properties' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_project_properties',
-      'path' => "$theme_path/tripal_project",
+    'tripal_project.teaser' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_project.teaser',
+      'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project_help' => array(
-      'template' => 'tripal_project_help',
-      'arguments' =>  array(NULL),
-      'path' => $theme_path,
+    'tripal_project.help' => array(
+      'variables' => 'tripal_project.help',
+      'variables' =>  array(NULL),
+      'path' => "$path/theme",
     ),
   );
   return $items;
 }
-/**
- * Implementation of hook_form().
- *
- *  This form takes the Project Title information and description from the user.
- *
- *  @parm $node
- *    The initialized node
- *
- *  @parm $form_state
- *    The state of the form, that has the user entered information that is neccessary for adding
- *    information to the project
- *
- *  @return $form
- *    An array as described by the Drupal Form API
- *
- *
- * @ingroup tripal_project
- */
-function chado_project_form(&$node, $form_state) {
-  $form = array();
-
-  $project = $node->project;
-
-  // get the project default values.  When this module was first created
-  // the project description was incorrectly stored in the $node->body field.
-  // It is better to store it in the Chado tables.  However, the 'description'
-  // field of the project table is only 255 characters.  So, we are going
-  // to follow the same as the project module and store the description in
-  // the projectprop table and leave the project.description field blank.
-  // however, for backwards compatibitily, we check to see if the description
-  // is in the $node->body field. If it is we'll use that.  When the node is
-  // edited the text will be moved out of the body and into the projectprop
-  // table where it should belong.
-  if ($node->body) {
-    $project_description = $node->body;
-  }
-  else {
-    $project_description = $node->project_description;
-  }
-  if (!$project_description) {
-    $projectprop = tripal_project_get_property($project->project_id, 'project_description');
-    $project_description = $projectprop->value;
-  }
-
-  // keep track of the project id if we have.  If we do have one then
-  // this is an update as opposed to an insert.
-  $form['project_id'] = array(
-    '#type' => 'value',
-    '#value' => $project->project_id,
-  );
-
-  $form['title']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Project Title'),
-    '#description'   => t('Please enter the title for this project. This appears at the top of the project page.'),
-    '#required'      => TRUE,
-    '#default_value' => $node->title,
-    '#weight'        => 1
-  );
-
-  $form['project_description']= array(
-    '#type'          => 'textarea',
-    '#title'         => t('Project Description'),
-    '#description'   => t('A brief description of the project'),
-    '#required'      => TRUE,
-    '#default_value' => $project_description,
-    '#weight'        => 5
-  );
-
-  return $form;
-
-}
-/**
- *  validates submission of form when adding or updating a project node
- *
- * @ingroup tripal_project
- */
-function chado_project_validate($node, $form, &$form_state) {
-  $project = 0;
-  // check to make sure the name on the project is unique
-  // before we try to insert into chado.
-  if ($node->project_id) {
-    $sql = "SELECT * FROM {project} WHERE name = :name AND NOT project_id = :project_id";
-    $project = chado_query($sql, array(':name' => $node->title, ':project_id' => $node->project_id))->fetchObject();
-  }
-  else {
-    $sql = "SELECT * FROM {project} WHERE name = :name";
-    $project = chado_query($sql, array(':name' => $node->title))->fetchObject();
-  }
-  if ($project) {
-    form_set_error('title', t('The unique project name already exists. Please choose another'));
-  }
-}
-/**
- * Implementation of hook_insert().
- *
- *  @parm $node
- *    Then node that has the information stored within, accessed given the nid
- *
- *
- * @ingroup tripal_project
- */
-function chado_project_insert($node) {
-
-  if ($node->project_id) {
-    $project['project_id'] = $node->project_id;
-  }
-  else {
-    $values = array(
-      'name' => $node->title,
-      'description' => '',
-    );
-    $project = tripal_core_chado_insert('project', $values);
-  }
-
-  if ($project) {
-     // add the description property
-    tripal_project_insert_property($project['project_id'], 'project_description',
-      $node->project_description);
-
-    // make sure the entry for this feature doesn't already exist in the chado_project table
-    // if it doesn't exist then we want to add it.
-    $project_id = chado_get_id_for_node('project', $node->nid) ;
-    if (!$project_id) {
-       // next add the item to the drupal table
-      $sql = "
-        INSERT INTO {chado_project} (nid, vid, project_id)
-        VALUES (:nid, :vid, :project_id)
-      ";
-      db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':project_id' => $project['project_id']));
-    }
-  }
-  else {
-    drupal_set_message(t('Unable to add project.', 'warning'));
-    watchdog('tripal_project', 'Insert feature: Unable to create project where values: %values',
-      array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
-  }
-}
-
-/**
- *
- * Implementation of hook_delete().
- *
- * @param $node
- * The node which is to be deleted, only chado project and chado_project need to be dealt with
- * since the drupal node is deleted automagically
- *
- *
- * @ingroup tripal_project
- */
-function chado_project_delete($node) {
-
-  $project_id = chado_get_id_for_node('project', $node->nid);
-
-  // if we don't have a project id for this node then this isn't a node of
-  // type chado_project or the entry in the chado_project table was lost.
-  if (!$project_id) {
-    return;
-  }
-
-  // Remove data from {chado_project}, {node} and {node_revisions} tables of
-  // drupal database
-  $sql_del = "DELETE FROM {chado_project} 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 = :vod";
-  db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
-  db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
-
-  // Remove data from project and projectprop tables of chado database as well
-  chado_query("DELETE FROM {projectprop} WHERE project_id = :project_id", array(':project_id' => $project_id));
-  chado_query("DELETE FROM {project} WHERE project_id = :project_id", array(':project_id' => $project_id));
-}
 
 /**
- * Implements hook_update().
- *
- * @param $node
- *  The node which is to have its containing information updated when the user modifies information
- *  pertaining to the specific project
  *
- *
- * @ingroup tripal_project
+ * @ingroup tripal_feature
  */
-function chado_project_update($node) {
- if ($node->revision) {
-    // there is no way to handle revisions in Chado but leave
-    // this here just to make note we've addressed it.
+function tripal_project_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'chado_project':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_project.base'] = array(
+          '#value' => theme('tripal_project.base', array('node' => $node)),
+        );
+        $node->content['tripal_project.contact'] = array(
+          '#value' => theme('tripal_project.contact', array('node' => $node)),
+        );
+        $node->content['tripal_project.properties'] = array(
+          '#value' => theme('tripal_project.properties', array('node' => $node)),
+        );
+        $node->content['tripal_project.publications'] = array(
+          '#value' => theme('tripal_project.publications', array('node' => $node)),
+        );
+        $node->content['tripal_project.relationships'] = array(
+          '#value' => theme('tripal_project.relationships', array('node' => $node)),
+        );
+      }
+      if ($view_mode == 'teaser') {
+        $node->content['tripal_project_teaser'] = array(
+          '#value' => theme('tripal_project_teaser', array('node' => $node)),
+        );
+      }
+      break;
   }
-
-  // update the project and the description
-  $project_id = chado_get_id_for_node('project', $node->nid) ;
-  $match = array('project_id' => $project_id);
-  $values = array(
-    'name' => $node->title,
-    'description' => '',
-  );
-  $status = tripal_core_chado_update('project', $match, $values);
-  tripal_project_update_property($project_id, 'project_description', $node->project_description, 1);
 }
-
-/**
- * Implementation of node_load().
- *
- * @param $node
- *   The node that is to have its containing information loaded
- *
- * @return $node
- *   The node, containing the loaded project with the current nid
- *
- *
- * @ingroup tripal_project
- */
-function chado_project_load($node) {
-
-  // get the feature details from chado
-  $project_id = chado_get_id_for_node('project', $node->nid);
-
-  $values = array('project_id' => $project_id);
-  $project = tripal_core_generate_chado_var('project', $values);
-
-  $additions = new stdClass();
-  $additions->project = $project;
-  return $additions;
-
-}
-
 /**
  *
  * @ingroup tripal_project

+ 1 - 1
tripal_views/tripal_views.module

@@ -119,7 +119,7 @@ function tripal_views_menu() {
     'title' => 'Enable Integrations Administrative View',
     'page callback' => 'tripal_views_admin_enable_view',
     'page arguments' => array('tripal_views_admin_integrations', 'admin/tripal/views-integrations'),
-    'access arguments' => array('administer tripal_bulk_loader'),
+    'access arguments' => array('manage tripal_views_integration'),
     'type' => MENU_CALLBACK,
   );