|
@@ -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
|