12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088 |
- <?php
- require_once "api/tripal_pub.api.inc";
- require_once "includes/tripal_pub.admin.inc";
- require_once "includes/pub_sync.inc";
- require_once "includes/pub_form.inc";
- require_once "includes/pub_importers.inc";
- require_once "includes/pub_search.inc";
- require_once "includes/pub_citation.inc";
- require_once "includes/importers/PMID.inc";
- require_once "includes/importers/AGL.inc";
- /**
- * @file
- *
- * The Tripal Publication module allows you to search the PubMed databse for academic articles,
- * that relate to user specified tpoic\s. As well, it allows management of publications so that
- * a user can enter specified details regarding a desired publication. This allows all of the important
- * information that is unique to a Academic Publication to be stored for access.
- */
- /**
- *
- * @ingroup tripal_pub
- */
- function tripal_pub_init() {
- drupal_add_css(drupal_get_path('module', 'tripal_pub') . '/theme/css/tripal_pub.css');
- drupal_add_js(drupal_get_path('module', 'tripal_pub') . '/theme/js/tripal_pub.js');
- }
- /**
- * Implementation of hook_tripal_pub_node_info().
- *
- * This node_info, is a simple node that describes the functionallity of the module.
- *
- */
- function tripal_pub_node_info() {
- return array(
- 'chado_pub' => array(
- 'name' => t('Publication'),
- 'base' => '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
- *
- * Implements 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['find/publications' ]= array(
- 'title' => 'Publication Search',
- 'description' => ('Search for publications'),
- 'page callback' => 'tripal_pub_search_page',
- 'access arguments' => array('access chado_pub content'),
- 'type' => MENU_CALLBACK
- );
- $items['find/publications/criteria/%/%'] = array(
- 'page callback' => 'tripal_pub_search_page_update_criteria',
- 'page arguments' => array(5, 6),
- 'access arguments' => array('access chado_pub content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['admin/tripal/chado/tripal_pub']= array(
- 'title' => 'Publications',
- 'description' => ('A documented provenance artefact - publications, documents, personal communication.'),
- 'page callback' => 'tripal_pub_admin_pub_view',
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/chado/tripal_pub/help']= array(
- 'title' => 'Help',
- 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_pub_help'),
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10
- );
- $items['admin/tripal/chado/tripal_pub/configuration'] = array(
- 'title' => 'Settings',
- 'description' => 'Configure the Tripal publication module.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_pub_admin'),
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 5
- );
- $items['admin/tripal/chado/tripal_pub/sync'] = array(
- 'title' => ' Sync',
- '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_LOCAL_TASK,
- 'weight' => 2
- );
- $items['admin/tripal/chado/tripal_pub/citation'] = array(
- 'title' => 'Citations',
- 'description' => 'Update publication citations',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_pub_citation_form'),
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 1
- );
-
- $items['admin/tripal/chado/tripal_pub/import_list'] = array(
- 'title' => t('Importers'),
- 'description' => t('List all publication importers'),
- 'page callback' => 'tripal_pub_importers_list',
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 0
- );
-
- // add a second link for the importer on the data loaders page
- $items['admin/tripal/loaders/pub_import'] = array(
- 'title' => 'Publications Importers',
- 'description' => 'Create importers that can periodically import publications from remote online publication databases.',
- 'page callback' => 'tripal_pub_importers_list',
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['admin/tripal/chado/tripal_pub/import/new'] = array(
- 'title' => t('Add an Importer'),
- 'description' => t('Add a new publication importer.'),
- 'page callback' => 'tripal_pub_importer_setup_page',
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
- $items['admin/tripal/chado/tripal_pub/import/raw/%'] = array(
- 'page callback' => 'tripal_pub_get_raw_data',
- 'page arguments' => array(6),
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
- $items['admin/tripal/chado/tripal_pub/import/edit/%'] = array(
- 'page callback' => 'tripal_pub_importer_setup_page',
- 'page arguments' => array(5, 6),
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
-
- $items['admin/tripal/chado/tripal_pub/import/submit/%'] = array(
- 'page callback' => 'tripal_pub_importer_submit_job',
- 'page arguments' => array(6),
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
- $items['admin/tripal/chado/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/chado/tripal_pub/import/changedb'] = array(
- 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
- 'page arguments' => array(),
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
- $items['admin/tripal/chado/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,
- );
- $items['tripal_pub/chado/properties/add'] = array(
- 'page callback' => 'tripal_pub_property_add',
- 'access arguments' => array('edit chado_pub content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_pub/chado/properties/description'] = array(
- 'page callback' => 'tripal_pub_property_get_description',
- 'access arguments' => array('edit chado_pub content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_pub/chado/properties/minus/%/%'] = array(
- 'page callback' => 'tripal_pub_property_delete',
- 'page arguments' => array(3, 4),
- 'access arguments' => array('edit chado_pub 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($existing, $type, $theme, $path) {
- $core_path = drupal_get_path('module', 'tripal_core');
-
- $items = array(
- 'node__chado_pub' => array(
- 'template' => 'node--chado-generic',
- 'render element' => 'node',
- 'base hook' => 'node',
- 'path' => "$core_path/theme",
- ),
- // node templates
- 'tripal_pub_authors' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_authors',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_base' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_base',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_featuremaps' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_featuremaps',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_features' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_features',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_libraries' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_libraries',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_projects' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_projects',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_properties' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_properties',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_references' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_references',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_relationships' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_relationships',
- 'path' => "$path/theme/tripal_pub",
- ),
- 'tripal_pub_stocks' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_pub_stocks',
- 'path' => "$path/theme/tripal_pub",
- ),
- // instructions page for the pub module
- 'tripal_pub_help' => array(
- 'template' => 'tripal_pub_help',
- 'arguments' => array(NULL),
- 'path' => "$path/theme",
- ),
- // themed forms
- 'tripal_pub_importer_setup_form_elements' => array(
- 'render element' => 'form',
- ),
- 'tripal_pub_search_setup_form_elements' => array(
- 'render element' => 'form',
- ),
-
- // teaser
- 'tripal_pub_teaser' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_pub_teaser',
- 'path' => "$path/theme/tripal_pub",
- ),
- );
- return $items;
- }
- /**
- * Implements hook_help()
- * Purpose: Adds a help page to the module list
- */
- function tripal_pub_help ($path, $arg) {
- if ($path == 'admin/help#tripal_pub') {
- return theme('tripal_pub_help', array());
- }
- }
- /**
- * Implements hook_views_api()
- * Purpose: Essentially this hook tells drupal that there is views support for
- * for this module which then includes tripal_db.views.inc where all the
- * views integration code is
- *
- * @ingroup tripal_pub
- */
- function tripal_pub_views_api() {
- return array(
- 'api' => 3.0,
- );
- }
- /**
- * Implement hook_permissions().
- */
- function tripal_pub_permissions() {
- return array(
- 'access chado_pub content' => array(
- 'title' => t('View Publications'),
- 'description' => t('Allow users to view publication pages.'),
- ),
- 'create chado_pub content' => array(
- 'title' => t('Create Publication'),
- 'description' => t('Allow users to create new publication pages.'),
- ),
- 'delete chado_pub content' => array(
- 'title' => t('Delete Publication'),
- 'description' => t('Allow users to delete publication pages.'),
- ),
- 'edit chado_pub content' => array(
- 'title' => t('Edit Publications'),
- 'description' => t('Allow users to edit publication pages.'),
- ),
- 'adminster tripal pub' => array(
- 'title' => t('Administer Publications'),
- 'description' => t('Allow users to administer all publications.'),
- ),
- );
- }
- /**
- * 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_pub_node_access($node, $op, $account ) {
- if ($op == 'create') {
- if (!user_access('create chado_pub content', $account)) {
- return FALSE;
- }
- return TRUE;
- }
- 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_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) {
- $title = trim($node->pubtitle);
- $pyear = trim($node->pyear);
- $uniquename = trim($node->uniquename);
- $is_obsolete = $node->is_obsolete;
- $type_id = $node->type_id;
-
- // we need an array suitable for the tripal_pub_create_citation() function
- // to automatically generate a citation if a uniquename doesn't already exist
- $pub_arr = array();
-
- // if there is an pub_id in the $node object then this must be a sync so
- // we can skip adding the pub as it is already there, although
- // we do need to proceed with the rest of the insert
- if (!property_exists($node, 'pub_id')) {
-
- $properties = array(); // stores all of the properties we need to add
- $cross_refs = array(); // stores any cross references for this publication
- // get the properties from the form
- $properties = tripal_core_properties_form_retreive($node, 'tripal_pub');
-
- // get the list of properties for easy lookup (without doing lots of database queries
- $properties_list = array();
- $sql = "
- SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
- 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 Details' and
- NOT CVTS.is_obsolete = 1
- ORDER BY CVTS.name ASC
- ";
- $prop_types = chado_query($sql);
- while ($prop = $prop_types->fetchObject()) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- // The 'Citation' term is special because it serves
- // both as a property and as the uniquename for the
- // pub and we want it stored in both the pub table and the pubprop table
- if ($prop->name == 'Citation') {
- $properties[$prop->name][0] = $node->uniquename;
- }
- }
- // iterate through all of the properties and remove those that really are
- // part of the pub table fields
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $name => $element) {
- $value = trim($element[0]);
- // populate our $pub_array for building a citation
- $pub_arr[$name] = $value;
- // remove properties that are stored in the pub table
- if ($name == "Volume") {
- $volume = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Volume Title") {
- $volumetitle = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Issue") {
- $issue = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Pages") {
- $pages = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Publisher") {
- $publisher = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
- $series_name = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Journal Country" or $name == "Published Location") {
- $pubplace = $value;
- // allow this property to go into the pubprop table so we don't loose info
- // so don't unset it. But it will also go into the pub.pubplace field
- }
- elseif ($name == "Publication Dbxref") {
- // we will add the cross-references to the pub_dbxref table
- // but we also want to keep the property in the pubprop table so don't unset it
- $cross_refs[] = $value;
- }
- }
- // generate a citation for this pub if one doesn't already exist
- if (!$node->uniquename and array_key_exists('Citation', $properties)) {
- $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
- $pub_arr['Title'] = $node->pubtitle;
- $pub_arr['Publication Type'][0] = $pub_type->name;
- $pub_arr['Year'] = $node->pyear;
- $node->uniquename = tripal_pub_create_citation($pub_arr);
- $properties['Citation'][0] = $node->uniquename;
- }
- // insert the pub record
- $values = array(
- 'title' => $node->pubtitle,
- 'series_name' => substr($series_name, 0, 255),
- 'type_id' => $node->type_id,
- 'pyear' => $node->pyear,
- 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
- 'uniquename' => $node->uniquename,
- 'volumetitle' => $volumetitle,
- 'volume' => $volume,
- 'issue' => $issue,
- 'pages' => $pages,
- 'miniref' => substr($miniref, 0, 255),
- 'publisher' => substr($publisher, 0, 255),
- 'pubplace' => substr($pubplace, 0, 255),
- );
- $pub = tripal_core_chado_insert('pub', $values);
- if (!$pub) {
- drupal_set_message("Error inserting publication", "error");
- watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
- return;
- }
- $pub_id = $pub['pub_id'];
- // now add in the properties
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
- $status = tripal_pub_insert_property($pub['pub_id'], $property, $value, FALSE);
- if (!$status) {
- drupal_set_message("Error cannot add property: $property", "error");
- watchdog('tripal_pub', "Error cannot add property: %prop",
- array('%property' => $property), WATCHDOG_ERROR);
- }
- }
- }
- // add in any database cross-references
- foreach ($cross_refs as $index => $ref) {
- $pub_dbxref = tripal_pub_add_pub_dbxref($pub['pub_id'], trim($ref));
- if (!$pub_dbxref) {
- drupal_set_message("Error cannot add publication cross reference: $ref", "error");
- watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
- array('%ref' => $ref), WATCHDOG_ERROR);
- }
- }
- }
- else {
- $pub_id = $node->pub_id;
- }
- // Make sure the entry for this pub doesn't already exist in the
- // chado_pub table if it doesn't exist then we want to add it.
- $check_org_id = chado_get_id_for_node('pub', $node->nid);
- if (!$check_org_id) {
- $record = new stdClass();
- $record->nid = $node->nid;
- $record->vid = $node->vid;
- $record->pub_id = $pub_id;
- drupal_write_record('chado_pub', $record);
- }
-
- }
- /*
- *
- * 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) {
- $title = trim($node->pubtitle);
- $pyear = trim($node->pyear);
- $uniquename = trim($node->uniquename);
- $is_obsolete = $node->is_obsolete;
- $type_id = $node->type_id;
- // we need an array suitable for the tripal_pub_create_citation() function
- // to automatically generate a citation if a uniquename doesn't already exist
- $pub_arr = array();
- // get the publication ID for this publication
- $pub_id = chado_get_id_for_node('pub', $node->nid) ;
- $properties = array(); // stores all of the properties we need to add
- $cross_refs = array(); // stores any cross references for this publication
- // get the properties from the form
- $properties = tripal_core_properties_form_retreive($node, 'tripal_pub');
-
- // get the list of properties for easy lookup (without doing lots of database queries
- $properties_list = array();
- $sql = "
- SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
- 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 Details' or CVTS.name = 'Publication Type') and
- NOT CVTS.is_obsolete = 1
- ORDER BY CVTS.name ASC
- ";
- $prop_types = chado_query($sql);
- while ($prop = $prop_types->fetchObject()) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- // The 'Citation' term is special because it serves
- // both as a property and as the uniquename for the
- // pub and we want it stored in both the pub table and the pubprop table
- if ($prop->name == 'Citation') {
- $properties[$prop->name][0] = $node->uniquename;
- }
- }
- // iterate through all of the properties and remove those that really are
- // part of the pub table fields
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $name => $element) {
- foreach ($element as $index => $value) {
- // populate our $pub_array for building a citation
- $pub_arr[$name] = $value;
- // remove properties that are stored in the pub table
- if ($name == "Volume") {
- $volume = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Volume Title") {
- $volumetitle = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Issue") {
- $issue = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Pages") {
- $pages = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Publisher") {
- $publisher = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Journal Name" or $name == "Conference Name") {
- $series_name = $value;
- unset($properties[$name]);
- }
- elseif ($name == "Journal Country" or $name == "Published Location") {
- $pubplace = $value;
- // allow this property to go into the pubprop table so we don't loose info
- // so don't unset it. But it will also go into the pub.pubplace field
- }
- elseif ($name == "Publication Dbxref") {
- // we will add the cross-references to the pub_dbxref table
- // but we also want to keep the property in the pubprop table so don't unset it
- $cross_refs[] = $value;
- }
- }
- }
- // generate a citation for this pub if one doesn't already exist
- if (!$node->uniquename) {
- $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
- $pub_arr['Title'] = $node->pubtitle;
- $pub_arr['Publication Type'][0] = $pub_type->name;
- $pub_arr['Year'] = $node->pyear;
- $node->uniquename = tripal_pub_create_citation($pub_arr);
- $properties['Citation'][0] = $node->uniquename;
- }
- // update the pub record
- $match = array(
- 'pub_id' => $pub_id,
- );
- $values = array(
- 'title' => $node->pubtitle,
- 'type_id' => $node->type_id,
- 'pyear' => $node->pyear,
- 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
- 'uniquename' => $node->uniquename,
- 'series_name' => substr($series_name, 0, 255),
- 'volumetitle' => $volumetitle,
- 'volume' => $volume,
- 'issue' => $issue,
- 'pages' => $pages,
- 'miniref' => substr($miniref, 0, 255),
- 'publisher' => substr($publisher, 0, 255),
- 'pubplace' => substr($pubplace, 0, 255),
- );
- $status = tripal_core_chado_update('pub', $match, $values);
- if (!$status) {
- drupal_set_message("Error updating publication", "error");
- watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
- return;
- }
- // now add in the properties by first removing any the publication
- // already has and adding the ones we have
- tripal_core_chado_delete('pubprop', array('pub_id' => $pub_id));
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
- $status = tripal_pub_insert_property($pub_id, $property, $value, FALSE);
- if (!$status) {
- drupal_set_message("Error cannot add property: '$property'", "error");
- watchdog('tripal_pub', "Error cannot add property: '%prop'",
- array('%prop' => $property), WATCHDOG_ERROR);
- }
- }
- }
- // add in any database cross-references after first removing
- tripal_core_chado_delete('pub_dbxref', array('pub_id' => $pub_id));
- foreach ($cross_refs as $index => $ref) {
- $pub_dbxref = tripal_pub_add_pub_dbxref($pub_id, trim($ref));
- if (!$pub_dbxref) {
- drupal_set_message("Error cannot add publication cross reference: $ref", "error");
- watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
- array('%ref' => $ref), WATCHDOG_ERROR);
- }
- }
- }
- /**
- * 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($nodes) {
-
- foreach ($nodes as $nid => $node) {
- // find the pub and add in the details
- $pub_id = chado_get_id_for_node('pub', $nid);
-
- // get the pub
- $values = array('pub_id' => $pub_id);
- $pub = tripal_core_generate_chado_var('pub', $values);
-
- // expand the 'text' fields as those aren't included by default
- // and they really shouldn't be so large to cause problems
- $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
- $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
- $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');
-
- // set the URL path
- $nodes[$nid]->path = "pub/$pub_id";
- $nodes[$nid]->pub = $pub;
- }
- }
- /**
- * 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->nid);
- // 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_revision} tables of
- // drupal database
- $sql_del = "DELETE FROM {chado_pub} 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 pub and pubprop tables of chado database as well
- chado_query("DELETE FROM {pubprop} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
- chado_query("DELETE FROM {pub} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
- }
- /**
- *
- *
- * @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 = :subject_id
- ";
- $as_subject = chado_query($sql, array(':subject_id' => $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 = :object_id
- ";
- $as_object = chado_query($sql, array(':object_id' => $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 = $as_object->fetchObject()) {
- // 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 = $as_subject->fetchObject()) {
- // 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;
- }
- /**
- *
- */
- function tripal_pub_mail($key, &$message, $params) {
- $language = $message['language'];
- $variables = user_mail_tokens($params['account'], $language);
- switch($key) {
- case 'import_report':
- $headers = array(
- 'MIME-Version' => '1.0',
- 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer' => 'Drupal'
- );
- foreach ($headers as $key => $value) {
- $message['headers'][$key] = $value;
- }
- $message['subject'] = t('Publication import from !site', $variables, $language->language);
- $message['body'][] = $params['message'];
- break;
- }
- }
- /**
- *
- * @ingroup tripal_feature
- */
- function tripal_pub_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_pub':
- // Show feature browser and counts
- if ($view_mode == 'full') {
- $node->content['tripal_pub_authors'] = array(
- '#value' => theme('tripal_pub_authors', array('node' => $node)),
- );
- $node->content['tripal_pub_base'] = array(
- '#value' => theme('tripal_pub_base', array('node' => $node)),
- );
- $node->content['tripal_pub_featuremaps'] = array(
- '#value' => theme('tripal_pub_featuremaps', array('node' => $node)),
- );
- $node->content['tripal_pub_features'] = array(
- '#value' => theme('tripal_pub_features', array('node' => $node)),
- );
- $node->content['tripal_pub_libraries'] = array(
- '#value' => theme('tripal_pub_libraries', array('node' => $node)),
- );
- $node->content['tripal_pub_projects'] = array(
- '#value' => theme('tripal_pub_projects', array('node' => $node)),
- );
- $node->content['tripal_pub_properties'] = array(
- '#value' => theme('tripal_pub_properties', array('node' => $node)),
- );
- $node->content['tripal_pub_references'] = array(
- '#value' => theme('tripal_pub_references', array('node' => $node)),
- );
- $node->content['tripal_pub_relationships'] = array(
- '#value' => theme('tripal_pub_relationships', array('node' => $node)),
- );
- $node->content['tripal_pub_stocks'] = array(
- '#value' => theme('tripal_pub_stocks', array('node' => $node)),
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_pub_teaser'] = array(
- '#value' => theme('tripal_pub_teaser', array('node' => $node)),
- );
- }
- break;
- }
- }
- /**
- *
- * @param $node
- */
- function tripal_pub_node_insert($node) {
- // we want the publications to always have a URL of http://[base url]/pub/[pub id]
- // where [pub id] is the Chado publication ID. This will allow for easy linking
- // into the publication without needing to know the node. Of course if you know the
- // node that will still work too (e.g. http://[base url]/node/[node id]
- // so the nodeapi function ensures that the URL path is set after insert or update
- // of the node and when the node is loaded if it hasn't yet been set.
- if ($node->type == 'chado_pub') {
- $pub_id = chado_get_id_for_node('pub', $node->nid);
- tripal_pub_set_pub_url($node, $pub_id);
- }
- }
- /**
- *
- * @param $node
- * @param $types
- */
- function tripal_pub_node_load($nodes, $types) {
- // we want the publications to always have a URL of http://[base url]/pub/[pub id]
- // where [pub id] is the Chado publication ID. This will allow for easy linking
- // into the publication without needing to know the node. Of course if you know the
- // node that will still work too (e.g. http://[base url]/node/[node id]
- // so the nodeapi function ensures that the URL path is set after insert or update
- // of the node and when the node is loaded if it hasn't yet been set.
- if (count(array_intersect(array('chado_pub'), $types))) {
- foreach ($nodes as $nid => $node) {
- if ($node->type == 'chado_pub' and !property_exists($node, 'path')) {
- $pub_id = chado_get_id_for_node('pub', $node->nid);
- $path = tripal_pub_set_pub_url($node, $pub_id);
- }
- }
- }
- }
- /**
- *
- * @param $node
- */
- function tripal_pub_node_update($node) {
- // we want the publications to always have a URL of http://[base url]/pub/[pub id]
- // where [pub id] is the Chado publication ID. This will allow for easy linking
- // into the publication without needing to know the node. Of course if you know the
- // node that will still work too (e.g. http://[base url]/node/[node id]
- // so the nodeapi function ensures that the URL path is set after insert or update
- // of the node and when the node is loaded if it hasn't yet been set.
- if ($node->type == 'chado_pub') {
- $pub_id = chado_get_id_for_node('pub', $node->nid);
- tripal_pub_set_pub_url($node, $pub_id);
- }
- }
- /**
- * Implementation of hook_form_alter()
- *
- * @param $form
- * @param $form_state
- * @param $form_id
- */
- function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
- // turn of preview button for insert/updates
- if ($form_id == "chado_pub_node_form") {
- $form['actions']['preview']['#access'] = FALSE;
- }
- 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 (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
- $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
- }
- if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
- $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
- }
- */
- }
- if ($form_id == "tripal_pub_search_form") {
- $form['#action'] = url("find/publications");
- }
- if ($form_id == "chado_pub_node_form") {
- }
- }
- /**
- *
- * @param $callback
- * @param $args
- */
- function tripal_pub_job_describe_args($callback, $args) {
- $new_args = array();
- if ($callback == 'tripal_pub_import_publications_by_import_id') {
- // get all of the loaders
- $qargs = array(':import_id' => $args[0]);
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
- $import = db_query($sql, $qargs)->fetchObject();
-
- $new_args['Importer'] = $import->name;
- }
- return $new_args;
- }
|