array( 'name' => t('Publication'), 'module' => 'chado_pub', 'description' => t('A publication from the Chado database'), 'title_label' => t('Article Title'), 'body_label' => t('Abstract'), 'has_title' => TRUE, 'has_body' => FALSE, ), ); } /** * Tripal-Publication-Menu * * Implemets hook_menu(): Adds menu items for the tripal_pub module menu. This section * gives the outline for the main menu of the Tripal-Publication module * * @return * An array of menu items that is visible within the Drupal Menu, returned as soon * as the program is ran */ function tripal_pub_menu() { $items = array(); $items[ 'admin/tripal/tripal_pub' ]= array( 'title' => 'Publications', 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'), 'page callback' => 'theme', 'page arguments' => array('tripal_pub_admin'), 'access arguments' => array('administer tripal pubs'), 'type' => MENU_NORMAL_ITEM ); $items['admin/tripal/tripal_pub/sync'] = array( 'title' => ' Sync Publications', 'description' => 'Sync publications in Chado with Drupal', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_pub_sync_form'), 'access arguments' => array('administer tripal pubs'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_pub/import_list'] = array( 'title' => t('Importers List'), 'description' => t('List all publication importers'), 'page callback' => 'tripal_pub_importers_list', 'access arguments' => array('administer tripal pubs'), 'type ' => MENU_CALLBACK, ); $items['admin/tripal/tripal_pub/import/new'] = array( 'title' => t('Add an Importer'), 'description' => t('Add a new publication importer.'), 'page callback' => 'tripal_pub_importer_setup', 'page arguments' => array(4, NULL), 'access arguments' => array('administer tripal pubs'), 'type ' => MENU_CALLBACK, ); $items['admin/tripal/tripal_pub/import/edit/%'] = array( 'page callback' => 'tripal_pub_importer_setup', 'page arguments' => array(4, 5), 'access arguments' => array('administer tripal pubs'), 'type ' => MENU_CALLBACK, ); $items['admin/tripal/tripal_pub/import/delete/%'] = array( 'page callback' => 'tripal_pub_importer_delete', 'page arguments' => array(5), 'access arguments' => array('administer tripal pubs'), 'type ' => MENU_CALLBACK, ); $items['admin/tripal/tripal_pub/import/criteria/%/%'] = array( 'page callback' => 'tripal_pub_importer_setup_page_update_criteria', 'page arguments' => array(5, 6), 'access arguments' => array('administer tripal pubs'), 'type ' => MENU_CALLBACK, ); // Automatically generate checkboxes. $items['node/add/tripal_pub/ahah_authors'] = array( 'title' => 'Add Additional Authors', 'page callback' => 'drupal_get_form', 'page arguments' => array('author_addition_fields_ahah_callback'), 'access callback' => TRUE, 'type' => MENU_CALLBACK, 'weight' => 2, ); $items['tripal_pub/js/%'] = array( 'page callback' => 'tripal_pub_js', 'page arguments' => array(2), 'access arguments' => array('access content'), 'type ' => MENU_CALLBACK, ); return $items; } /** * Implements hook_theme(): Register themeing functions for this module * * * @return * An array of themeing functions to register * */ function tripal_pub_theme() { return array( 'tripal_pub_base' => array( 'arguments' => array('node' => NULL), ), 'tripal_pub_properties' => array( 'arguments' => array('node' => NULL) ), 'tripal_pub_authors' => array( 'arguments' => array('node' => NULL) ), 'tripal_pub_references' => array( 'arguments' => array('node' => NULL) ), 'tripal_pub_relationships' => array( 'arguments' => array('node' => NULL) ), 'tripal_pub_importer_setup_form' => array( 'arguments' => array('form'), ), 'tripal_pub_admin' => array( 'template' => 'tripal_pub_admin', 'arguments' => array(NULL), 'path' => drupal_get_path('module', 'tripal_pub') . '/theme' ), ); } /** * Implement hook_perm(). */ function tripal_pub_perm() { return array( 'access chado_pub content', 'create chado_pub content', 'delete chado_pub content', 'edit chado_pub content', 'administer tripal pubs', ); } /** * Implement hook_access(). * * This hook allows node modules to limit access to the node types they define. * * @param $op * The operation to be performed * * @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 $account * A user object representing the user for whom the operation is to be performed * * @return * TRUE * */ function chado_pub_access($op, $node, $account ) { if ($op == 'create') { if (!user_access('create chado_pub content', $account)) { return FALSE; } } if ($op == 'update') { if (!user_access('edit chado_pub content', $account)) { return FALSE; } } if ($op == 'delete') { if (!user_access('delete chado_pub content', $account)) { return FALSE; } } if ($op == 'view') { if (!user_access('access chado_pub content', $account)) { return FALSE; } } return NULL; } /** * Implementation of tripal_pub_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 publication * * @return $form * The information that was enterd allong with * */ function chado_pub_form(&$node, $form_state) { $type = node_get_types('type', $node); $form['pub_id'] = array( '#type' => 'hidden', '#value' => (isset($node->pub_id)) ? $node->pub_id->pub_id : NULL , ); $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} ON CVTO.cv_id = CV.cv_id WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' ORDER BY CVTS.name ASC "; $results = chado_query($sql); $pub_types = array(); $default_type = ''; while ($pub_type = db_fetch_object($results)) { $pub_types[$pub_type->cvterm_id] = $pub_type->name; if (strcmp($pub_type->name,"Journal Article") == 0) { $default_type = $pub_type->cvterm_id; } } $form['type_id'] = array( '#type' => 'select', '#title' => t('Publication Type'), '#options' => $pub_types, '#required' => TRUE, '#default_value' => isset($node->pub_id->type_id) ? $node->pub_id->type_id : $default_type, ); // Article Title. $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => $node->title, '#required' => TRUE, ); $form['volume'] = array( '#type' => 'textfield', '#title' => t('Volume'), '#default_value' => isset($node->pub_id->volume) ? $node->pub_id->volume : '' ); $form['volumetitle'] = array( '#type' => 'textfield', '#title' => t('Volume Title'), '#description' => t('Title of part if one of a series.'), '#default_value' => isset($node->pub_id->volumetitle) ? $node->pub_id->volumetitle : '' ); $form['series_name'] = array( '#type' => 'textfield', '#title' => t('Series Name'), '#description' => t('Full name of (journal) series.'), '#default_value' => isset($node->pub_id->series_name) ? $node->pub_id->series_name : '' ); $form['issue'] = array( '#type' => 'textfield', '#title' => t('Issue'), '#default_value' => isset($node->pub_id->issue) ? $node->pub_id->issue : '' ); $form['pyear'] = array( '#type' => 'textfield', '#title' => t('Publication Year'), '#default_value' => isset($node->pub_id->pyear) ? $node->pub_id->pyear : '' ); $form['pages'] = array( '#type' => 'textfield', '#title' => t('Pages'), '#description' => t('Page number range[s], e.g. 457--459, viii + 664pp, lv--lvii.'), '#default_value' => isset($node->pub_id->pages) ? $node->pub_id->pages : '' ); $form['miniref'] = array( '#type' => 'textfield', '#title' => t('Mini-Ref'), '#required' => FALSE, '#default_value' => isset($node->pub_id->miniref) ? $node->pub_id->miniref : '' ); $form['publisher'] = array( '#type' => 'textfield', '#title' => t('Publisher Name'), '#required' => FALSE, '#default_value' => isset($node->pub_id->publisher) ? $node->pub_id->publisher : '' ); $form['pubplace'] = array( '#type' => 'textfield', '#title' => t('Place of Publication'), '#required' => FALSE, '#default_value' => isset($node->pub_id->pubplace) ? $node->pub_id->pubplace : '' ); $form['is_obsolete'] = array( '#type' => 'checkbox', '#title' => t('Is Obsolete? (Check for Yes)'), '#required' => TRUE, '#default_value' => isset($node->pub_id->is_obsolete) ? $node->pub_id->is_obsolete : FALSE ); return $form; } /** * Implementation of tripal_pub_insert(). * * This function inserts user entered information pertaining to the Publication instance into the * 'pubauthor', 'pubprop', 'chado_pub', 'pub' talble of the database. * * @parm $node * Then node which contains the information stored within the node-ID * * */ function chado_pub_insert($node) { // if a pub_id already exists for this node then it already exists in Chado and // we get here because we are syncing the node. Therefore, we can skip the insert if ($node->pub_id) { $pub['pub_id'] = $node->pub_id; } else { $values = array( 'title' => $node->title, 'volumetitle' => $node->volumetitle, 'volume' => $node->volume, 'series_name' => $node->series_name, 'issue' => $node->issue, 'pyear' => $node->pyear, 'pages' => $node->pages, 'miniref' => $node->miniref, 'type_id' => $node->type_id, 'is_obsolete' => $node->is_obsolete, 'publisher' => $node->publisher, 'pubplace' => $node->pubplace, 'uniquename' => $node->uniquename, 'type_id' => $node->type_id ); $pub = tripal_core_chado_insert('pub', $values); } if ($pub) { // make sure the entry for this feature doesn't already exist in the chado_pub table // if it doesn't exist then we want to add it. $pub_id = chado_get_id_for_node('pub', $node) ; if (!$pub_id) { // next add the item to the drupal table $sql = "INSERT INTO {chado_pub} (nid, vid, pub_id) ". "VALUES (%d, %d, %d)"; db_query($sql, $node->nid, $node->vid, $pub['pub_id']); } } else { drupal_set_message(t('Unable to add publication.', 'warning')); watchdog('tripal_pub', 'Insert publication: Unable to create pub where values: %values', array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING); } } /* * * 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 Publication. * 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_pub */ function chado_pub_update($node) { if ($node->revision) { // there is no way to handle revisions in Chado but leave // this here just to make not we've addressed it. } $pub_id = chado_get_id_for_node('pub', $node) ; // update the pub record $match = array( 'pub_id' => $pub_id, ); $values = array( 'title' => $node->title, 'volumetitle' => $node->volumetitle, 'volume' => $node->volume, 'series_name' => $node->series_name, 'issue' => $node->issue, 'pyear' => $node->pyear, 'pages' => $node->pages, 'miniref' => $node->miniref, 'uniquename' => $node->uniquename, 'type_id' => $node->type_id, 'is_obsolete' => $node->is_obsolete, 'publisher' => $node->publisher, 'pubplace' => $node->pubplace, 'type_id' => $node->type_id ); $status = tripal_core_chado_update('pub', $match, $values); } /** * Implementation of tripal_pub_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_pub_load($node) { // get the feature details from chado $pub_id = chado_get_id_for_node('pub', $node); $values = array('pub_id' => $pub_id); $pub = tripal_core_generate_chado_var('pub', $values); $additions = new stdClass(); $additions->pub = $pub; return $additions; } /** * Implementation of tripal_pub_delete(). * * This function takes a node and if the delete button has been chosen by the user, the publication * and it's details will be removed.Following,given the node-ID, the instance will be deleted from * the 'chado_pub' table. * * @parm $node * Then node which contains the information stored within the node-ID * */ function chado_pub_delete(&$node) { $pub_id = chado_get_id_for_node('pub', $node); // if we don't have a pub id for this node then this isn't a node of // type chado_pub or the entry in the chado_pub table was lost. if (!$pub_id) { return; } // Remove data from {chado_pub}, {node} and {node_revisions} tables of // drupal database $sql_del = "DELETE FROM {chado_pub} ". "WHERE nid = %d ". "AND vid = %d"; db_query($sql_del, $node->nid, $node->vid); $sql_del = "DELETE FROM {node_revisions} ". "WHERE nid = %d ". "AND vid = %d"; db_query($sql_del, $node->nid, $node->vid); $sql_del = "DELETE FROM {node} ". "WHERE nid = %d ". "AND vid = %d"; db_query($sql_del, $node->nid, $node->vid); // Remove data from pub and pubprop tables of chado database as well chado_query("DELETE FROM {pubprop} WHERE pub_id = %d", $pub_id); chado_query("DELETE FROM {pub} WHERE pub_id = %d", $pub_id); } /* * */ function tripal_pub_form_alter(&$form, &$form_state, $form_id) { if ($form_id == "tripal_pub_importer_setup_form") { // updating the form through the ahah callback sets the action of // the form to the ahah callback URL. We need to set it back // to the normal form URL if ($form_state['values']['action'] == 'edit') { $form['#action'] = url("admin/tripal/tripal_pub/import/edit/" . $form['pub_import_id']); } if ($form_state['values']['action'] == 'add') { $form['#action'] = url("admin/tripal/tripal_pub/import/add"); } } } /** * * * @ingroup tripal_pub */ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) { // we want to provide a new variable that contains the matched pubs. $pub = $variables['node']->pub; // normally we would use tripal_core_expand_chado_vars to expand our // organism object and add in the relationships, however whan a large // number of relationships are present this significantly slows the // query, therefore we will manually perform the query $sql = " SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type FROM pub_relationship PR INNER JOIN {pub} P ON PR.object_id = P.pub_id INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id WHERE PR.subject_id = %d "; $as_subject = chado_query($sql, $pub->pub_id); $sql = " SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type FROM pub_relationship PR INNER JOIN {pub} P ON PR.subject_id = P.pub_id INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id WHERE PR.object_id = %d "; $as_object = chado_query($sql, $pub->pub_id); // combine both object and subject relationshisp into a single array $relationships = array(); $relationships['object'] = array(); $relationships['subject'] = array(); // iterate through the object relationships while ($relationship = db_fetch_object($as_object)) { // get the relationship and child types $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type)); $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type)); if (!array_key_exists($rel_type, $relationships['object'])) { $relationships['object'][$rel_type] = array(); } if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) { $relationships['object'][$rel_type][$sub_type] = array(); } $relationships['object'][$rel_type][$sub_type][] = $relationship; } // now add in the subject relationships while ($relationship = db_fetch_object($as_subject)) { // get the relationship and child types $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type)); $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type)); if (!array_key_exists($rel_type, $relationships['subject'])) { $relationships['subject'][$rel_type] = array(); } if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) { $relationships['subject'][$rel_type][$obj_type] = array(); } $relationships['subject'][$rel_type][$obj_type][] = $relationship; } $pub->all_relationships = $relationships; }