1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120 |
- <?php
- 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,
- 'chado_node_api' => array(
- 'base_table' => 'pub',
- 'hook_prefix' => 'chado_pub',
- 'record_type_title' => array(
- 'singular' => t('Publication'),
- 'plural' => t('Publications')
- ),
- 'sync_filters' => array(
- 'type_id' => FALSE,
- 'organism_id' => FALSE
- ),
- ),
- ),
- );
- }
- function chado_pub_form($node, $form_state) {
- $form = array();
-
-
-
-
-
-
-
-
-
- $pub_id = null;
- $title = '';
- $pyear = '';
- $uniquename = '';
- $type_id = '';
- $is_obsolete = '';
-
-
-
- $more_props = array();
-
- if (property_exists($node, 'pub')) {
- $pub = $node->pub;
- $pub = chado_expand_var($pub, 'field', 'pub.title');
- $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
- $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
- $pub_id = $pub->pub_id;
- $title = $pub->title;
- $pyear = $pub->pyear;
- $uniquename = $pub->uniquename;
- $type_id = $pub->type_id->cvterm_id;
- $is_obsolete = $pub->is_obsolete;
-
-
- $is_obsolete = $is_obsolete == 't' ? 1 : $is_obsolete;
- $is_obsolete = $is_obsolete == 'f' ? 0 : $is_obsolete;
-
- $form['pub_id'] = array(
- '#type' => 'value',
- '#value' => $pub->pub_id,
- );
-
-
- if ($pub->volumetitle) {
- $cvterm = tripal_cv_get_cvterm_by_name('Volume Title', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volumetitle);
- }
- if ($pub->volume) {
- $cvterm = tripal_cv_get_cvterm_by_name('Volume', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volume);
- }
- if ($pub->series_name) {
- switch ($pub->type_id->name) {
- case 'Journal Article':
- $cvterm = tripal_cv_get_cvterm_by_name('Journal Name', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
- break;
- case 'Conference Proceedings':
- $cvterm = tripal_cv_get_cvterm_by_name('Conference Name', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
- break;
- default:
- $cvterm = tripal_cv_get_cvterm_by_name('Series Name', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
- }
- }
- if ($pub->issue) {
- $cvterm = tripal_cv_get_cvterm_by_name('Issue', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->issue);
- }
- if ($pub->pages) {
- $cvterm = tripal_cv_get_cvterm_by_name('Pages', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
- }
- if ($pub->miniref) {
-
- }
- if ($pub->publisher) {
- $cvterm = tripal_cv_get_cvterm_by_name('Publisher', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->publisher);
- }
- if ($pub->pubplace) {
- $cvterm = tripal_cv_get_cvterm_by_name('Published Location', NULL, 'tripal_pub');
- $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
- }
- }
-
-
- if (array_key_exists('values', $form_state) and isset($form_state['values']['pubtitle'])) {
- $title = $form_state['values']['pubtitle'];
- $pyear = $form_state['values']['pyear'];
- $uniquename = $form_state['values']['uniquename'];
- $type_id = $form_state['values']['type_id'];
- $is_obsolete = $form_state['values']['is_obsolete'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $title = $form_state['input']['pubtitle'];
- $uniquename = $form_state['input']['uniquename'];
- $type_id = $form_state['input']['type_id'];
- $is_obsolete = $form_state['input']['is_obsolete'];
- }
-
-
- $form['title'] = array(
- '#type' => 'hidden',
- '#value' => substr($title, 0, 255),
- );
- $form['pubtitle'] = array(
- '#type' => 'textarea',
- '#title' => t('Publication Title'),
- '#default_value' => $title,
- '#required' => TRUE,
- );
-
-
-
- $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' AND
- NOT CVTS.is_obsolete = 1
- ORDER BY CVTS.name ASC
- ";
- $results = chado_query($sql);
- $pub_types = array();
- while ($pub_type = $results->fetchObject()) {
- $pub_types[$pub_type->cvterm_id] = $pub_type->name;
-
- if (strcmp($pub_type->name,"Journal Article") == 0 and !$type_id) {
- $type_id = $pub_type->cvterm_id;
- }
- }
- $form['type_id'] = array(
- '#type' => 'select',
- '#title' => t('Publication Type'),
- '#options' => $pub_types,
- '#required' => TRUE,
- '#default_value' => $type_id,
- );
- $form['pyear'] = array(
- '#type' => 'textfield',
- '#title' => t('Publication Year'),
- '#default_value' => $pyear,
- '#required' => TRUE,
- '#size' => 5,
- '#description' => t('Enter the year of publication. Also, if available, please add a <b>Publication Date</b> property to specify the full date of publication.'),
- );
- $form['uniquename'] = array(
- '#type' => 'textarea',
- '#title' => t('Citation'),
- '#default_value' => $uniquename,
- '#description' => t('All publications must have a unique citation.
- <b>Please enter the full citation for this publication or leave blank and one will be generated
- automatically if possible</b>. For PubMed style citations list
- the last name of the author followed by initials. Each author should be separated by a comma. Next comes
- the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
- Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
- suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
- );
- $form['is_obsolete'] = array(
- '#type' => 'checkbox',
- '#title' => t('Is Obsolete? (Check for Yes)'),
- '#default_value' => $is_obsolete,
- );
-
-
-
- $select_options = array();
- $select_options[] = 'Select a Property';
- $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()) {
-
- if ($prop->name != 'Citation') {
- $select_options[$prop->cvterm_id] = $prop->name;
- }
- }
- $details = array(
- 'property_table' => 'pubprop',
- 'base_foreign_key' => 'pub_id',
- 'base_key_value' => $pub_id,
- 'cv_name' => 'tripal_pub',
- 'select_options' => $select_options,
- );
- chado_add_node_form_properties($form, $form_state, $details);
-
-
-
-
- $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'pub_relationship_types'));
- $cv_id = $cv_result[0]->cv_id;
- $select_options = tripal_cv_get_cvterm_options($cv_id);
- if (empty($select_options)) {
- $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'relationship'));
- $cv_id = $cv_result[0]->cv_id;
- $select_options = tripal_cv_get_cvterm_options($cv_id);
- }
-
- $details = array(
- 'relationship_table' => 'pub_relationship',
- 'base_table' => 'pub',
- 'base_foreign_key' => 'pub_id',
- 'base_key_value' => $pub_id,
- 'nodetype' => 'pub',
- 'cv_name' => 'pub_relationship_types',
- 'base_name_field' => 'uniquename',
- 'select_options' => $select_options
- );
-
- chado_add_node_form_relationships($form, $form_state, $details);
-
-
- $details = array(
- 'linking_table' => 'pub_dbxref',
- 'base_foreign_key' => 'pub_id',
- 'base_key_value' => $pub_id
- );
-
- chado_add_node_form_dbxrefs($form, $form_state, $details);
- return $form;
- }
- function chado_pub_validate($node, $form, &$form_state) {
-
- $title = trim($node->pubtitle);
- $pyear = trim($node->pyear);
- $uniquename = trim($node->uniquename);
- $is_obsolete = $node->is_obsolete;
- $type_id = $node->type_id;
-
- if($node->op == 'Delete') {
- return;
- }
-
-
- if (is_null($node->nid) and property_exists($node, 'pub_id') and $node->pub_id != 0) {
- return;
- }
- $pub = array();
-
- if(!preg_match('/^\d{4}$/', $pyear)){
- form_set_error('pyear', t('The publication year should be a 4 digit year.'));
- return;
- }
-
- $values = array('cvterm_id' => $type_id);
- $options = array('statement_name' => 'sel_pub_ty');
- $cvterm = chado_select_record('cvterm', array('name'), $values, $options);
- if (count($cvterm) == 0) {
- $message = t('Invalid publication type.');
- form_set_error('type_id', $message);
- return;
- }
-
- $series_name = '';
- foreach ($node as $element => $value) {
-
-
- if (preg_match('/^prop_value-(\d+)-(\d+)$/', $element, $matches)) {
- $prop_type_id = $matches[1];
- $prop_type = tripal_cv_get_cvterm_by_id($prop_type_id);
- if($prop_type->name == 'Conference Name' or $prop_type->name == 'Journal Name') {
- $series_name = $value;
- }
- if($prop_type->name == 'Citation') {
- $uniquename = $value;
- }
- $pub[$prop_type->name] = $value;
- }
-
- elseif ($element == 'new_id') {
- $prop_type = tripal_cv_get_cvterm_by_id($value);
- if($prop_type->name == 'Conference Name' or $prop_type->name == 'Journal Name') {
- $series_name = $node->new_value;
- }
- if($prop_type->name == 'Citation') {
- $uniquename = $node->new_value;
- }
- $pub[$prop_type->name] = $node->new_value;
- }
- }
-
- if (!$uniquename) {
- $pub['Title'] = $title;
- $pub['Publication Type'][0] = $cvterm[0]->name;
- $pub['Year'] = $pyear;
- $uniquename = tripal_pub_create_citation($pub);
- if (!$uniquename) {
- form_set_error('uniquename', "Cannot automatically generate a citation for this publication type. Please add one manually.");
- }
- }
- $skip_duplicate_check = 0;
-
-
- if (strcmp($cvterm[0]->name,'Patent') == 0) {
- $skip_duplicate_check = 1;
- }
-
- if (!is_null($node->nid)) {
- $pub_id = $node->pub_id;
-
- $values = array('pub_id' => $pub_id);
- $columns = array('title', 'pyear', 'type_id', 'series_name');
- $options = array('statement_name' => 'sel_pub_id');
- $pub = chado_select_record('pub', $columns, $values, $options);
-
-
- if((strcmp(strtolower($pub[0]->title), strtolower($title)) == 0) and
- (strcmp(strtolower($pub[0]->series_name), strtolower($series_name)) == 0) and
- ($pub[0]->type_id == $type_id) and
- ($pub[0]->pyear == $pyear)) {
- $skip_duplicate_check = 1;
- }
-
- if (!$skip_duplicate_check) {
- chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id);
- }
- chado_pub_validate_check_uniquename($uniquename, $pub_id);
- }
-
- else {
- chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm);
- chado_pub_validate_check_uniquename($uniquename);
- }
- }
- function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
- $results = tripal_pub_get_pub_by_uniquename($uniquename);
-
- foreach ($results as $index => $found_pub_id) {
- if($found_pub_id == $pub_id){
- unset($results[$index]);
- }
- }
- if (count($results) > 0) {
- $message = t('A publication with this unique citation already exists.');
- form_set_error('uniquename', $message);
- }
- }
- function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
-
- $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
- switch ($import_dups_check) {
- case 'title_year':
- $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, NULL, $pyear, NULL);
-
- foreach ($results as $index => $found_pub_id) {
- if($found_pub_id == $pub_id){
- unset($results[$index]);
- }
- }
- if (count($results) > 0) {
- $message = t('A publication with this title and publication year, already exists.');
- form_set_error('pyear', $message);
- }
- break;
- case 'title_year_type':
- $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, $cvterm[0]->name, $pyear, NULL);
-
- foreach ($results as $index => $found_pub_id) {
- if($found_pub_id == $pub_id){
- unset($results[$index]);
- }
- }
- if (count($results) > 0) {
- $message = t('A publication with this title, type and publication year, already exists.');
- form_set_error('pyear', $message);
- }
- break;
- case 'title_year_media':
- $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, NULL, $pyear, $series_name);
-
- foreach ($results as $index => $found_pub_id) {
- if($found_pub_id == $pub_id){
- unset($results[$index]);
- }
- }
- if (count($results) > 0) {
- $message = t('A publication with this title, media name (e.g. Journal Name) and publication year, already exists.');
- form_set_error('pyear', $message);
- }
- break;
- }
- }
- 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;
- }
- 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;
-
-
- $pub_arr = array();
-
-
-
- if (!property_exists($node, 'pub_id')) {
- $properties = array();
- $cross_refs = array();
-
- $properties = chado_retrieve_node_form_properties($node);
-
- $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;
-
-
-
- if ($prop->name == 'Citation') {
- $citation_id = $prop->cvterm_id;
- if (!empty($node->uniquename)) {
- $properties[$citation_id] = $node->uniquename;
- }
- }
- }
-
-
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $type_id => $element) {
- $value = trim($element[0]);
- $name = $properties_list[$type_id];
-
- $pub_arr[$name] = $value;
-
- if ($name == "Volume") {
- $volume = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Volume Title") {
- $volumetitle = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Issue") {
- $issue = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Pages") {
- $pages = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Publisher") {
- $publisher = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
- $series_name = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Journal Country" or $name == "Published Location") {
- $pubplace = $value;
-
-
- }
- elseif ($name == "Publication Dbxref") {
-
-
- $cross_refs[] = $value;
- }
- }
-
- if (!$node->uniquename and !array_key_exists($citation_id, $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_id][0] = $node->uniquename;
- }
-
- $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 = chado_insert_record('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'];
-
-
- $details = array(
- 'property_table' => 'pubprop',
- 'base_table' => 'pub',
- 'foreignkey_name' => 'pub_id',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = array(
- 'relationship_table' => 'pub_relationship',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_relationships($node, $details);
-
- 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);
- }
- }
-
- $details = array(
- 'linking_table' => 'pub_dbxref',
- 'foreignkey_name' => 'pub_id',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_dbxrefs($node, $details);
- }
- else {
- $pub_id = $node->pub_id;
- }
-
-
- $check_org_id = chado_get_id_from_nid('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);
- }
- }
- 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;
-
-
- $pub_arr = array();
-
- $pub_id = chado_get_id_from_nid('pub', $node->nid) ;
- $properties = array();
- $cross_refs = array();
-
- $properties = chado_retrieve_node_form_properties($node);
-
- $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;
-
-
-
- if ($prop->name == 'Citation') {
- $citation_id = $prop->cvterm_id;
- if (!empty($node->uniquename)) {
- $properties[$citation_id][0] = $node->uniquename;
- }
- }
- }
-
-
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $type_id => $element) {
- foreach ($element as $index => $value) {
- $name = $properties_list[$type_id];
-
- $pub_arr[$name] = $value;
-
- if ($name == "Volume") {
- $volume = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Volume Title") {
- $volumetitle = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Issue") {
- $issue = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Pages") {
- $pages = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Publisher") {
- $publisher = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Journal Name" or $name == "Conference Name") {
- $series_name = $value;
- unset($properties[$type_id]);
- }
- elseif ($name == "Journal Country" or $name == "Published Location") {
- $pubplace = $value;
-
-
- }
- elseif ($name == "Publication Dbxref") {
-
-
- $cross_refs[] = $value;
- }
- }
- }
-
- 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_id][0] = $node->uniquename;
- }
-
- $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 = chado_update_record('pub', $match, $values);
- if (!$status) {
- drupal_set_message("Error updating publication", "error");
- watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
- return;
- }
-
-
- $details = array(
- 'property_table' => 'pubprop',
- 'base_table' => 'pub',
- 'foreignkey_name' => 'pub_id',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = array(
- 'relationship_table' => 'pub_relationship',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_relationships($node, $details);
-
- chado_delete_record('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);
- }
- }
-
- $details = array(
- 'linking_table' => 'pub_dbxref',
- 'foreignkey_name' => 'pub_id',
- 'foreignkey_value' => $pub_id
- );
- chado_update_node_form_dbxrefs($node, $details);
- }
- function chado_pub_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $pub_id = chado_get_id_from_nid('pub', $nid);
-
- $values = array('pub_id' => $pub_id);
- $pub = chado_generate_var('pub', $values);
-
-
- $pub = chado_expand_var($pub, 'field', 'pub.title');
- $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
- $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
-
- $nodes[$nid]->path = "pub/$pub_id";
- $nodes[$nid]->pub = $pub;
- }
- }
- function chado_pub_delete(&$node) {
- $pub_id = chado_get_id_from_nid('pub', $node->nid);
-
-
- if (!$pub_id) {
- return;
- }
-
-
- $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));
-
- 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));
- }
- function tripal_pub_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_pub':
-
- if ($view_mode == 'full') {
- $node->content['tripal_pub_authors'] = array(
- '#markup' => theme('tripal_pub_authors', array('node' => $node)),
- '#tripal_toc_id' => 'authors',
- '#tripal_toc_title' => 'Author Details',
- );
- $node->content['tripal_pub_base'] = array(
- '#markup' => theme('tripal_pub_base', array('node' => $node)),
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- );
- $node->content['tripal_pub_featuremaps'] = array(
- '#markup' => theme('tripal_pub_featuremaps', array('node' => $node)),
- '#tripal_toc_id' => 'featuremaps',
- '#tripal_toc_title' => 'Maps',
- );
- $node->content['tripal_pub_features'] = array(
- '#markup' => theme('tripal_pub_features', array('node' => $node)),
- '#tripal_toc_id' => 'features',
- '#tripal_toc_title' => 'Features',
- );
- $node->content['tripal_pub_libraries'] = array(
- '#markup' => theme('tripal_pub_libraries', array('node' => $node)),
- '#tripal_toc_id' => 'libraries',
- '#tripal_toc_title' => 'Libraries',
- );
- $node->content['tripal_pub_projects'] = array(
- '#markup' => theme('tripal_pub_projects', array('node' => $node)),
- '#tripal_toc_id' => 'projects',
- '#tripal_toc_title' => 'Projects',
- );
- $node->content['tripal_pub_properties'] = array(
- '#markup' => theme('tripal_pub_properties', array('node' => $node)),
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- );
- $node->content['tripal_pub_references'] = array(
- '#markup' => theme('tripal_pub_references', array('node' => $node)),
- '#tripal_toc_id' => 'references',
- '#tripal_toc_title' => 'Cross References',
- );
- $node->content['tripal_pub_relationships'] = array(
- '#markup' => theme('tripal_pub_relationships', array('node' => $node)),
- '#tripal_toc_id' => 'relationships',
- '#tripal_toc_title' => 'Relationships',
- );
- $node->content['tripal_pub_stocks'] = array(
- '#markup' => theme('tripal_pub_stocks', array('node' => $node)),
- '#tripal_toc_id' => 'stocks',
- '#tripal_toc_title' => 'Stocks',
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_pub_teaser'] = array(
- '#markup' => theme('tripal_pub_teaser', array('node' => $node)),
- );
- }
- break;
- }
- }
- function tripal_pub_node_insert($node) {
-
-
-
-
-
-
- if ($node->type == 'chado_pub') {
- $pub_id = chado_get_id_from_nid('pub', $node->nid);
- tripal_pub_set_pub_url($node, $pub_id);
- }
- }
- function tripal_pub_node_load($nodes, $types) {
-
-
-
-
-
-
- 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_from_nid('pub', $node->nid);
- $path = tripal_pub_set_pub_url($node, $pub_id);
- }
- }
- }
- }
- function tripal_pub_node_update($node) {
-
-
-
-
-
-
- if ($node->type == 'chado_pub') {
- $pub_id = chado_get_id_from_nid('pub', $node->nid);
- tripal_pub_set_pub_url($node, $pub_id);
- }
- }
|