12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- <?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 = 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');
- $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)) {
- $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,
- );
-
-
- $properties_select = array();
- $properties_select[] = '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') {
- $properties[$prop->cvterm_id] = $prop->name;
- }
- }
-
-
-
-
- $exclude = array("Citation");
- $instructions = '';
- tripal_core_properties_form($form, $form_state, 'pubprop', 'pub_id', 'tripal_pub',
- $properties, $pub_id, $exclude, $more_props, $instructions, 'Properties');
- 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 = tripal_core_chado_select('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 = tripal_core_chado_select('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 = tripal_core_properties_form_retreive($node, 'tripal_pub');
-
- $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') {
- $properties[$prop->name][0] = $node->uniquename;
- }
- }
-
-
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $name => $element) {
- $value = trim($element[0]);
-
- $pub_arr[$name] = $value;
-
- 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;
-
-
- }
- elseif ($name == "Publication Dbxref") {
-
-
- $cross_refs[] = $value;
- }
- }
-
- 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;
- }
-
- $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'];
-
- 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);
- }
- }
- }
-
- 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;
- }
-
-
- $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);
- }
- }
- 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_for_node('pub', $node->nid) ;
- $properties = array();
- $cross_refs = array();
-
- $properties = tripal_core_properties_form_retreive($node, 'tripal_pub');
-
- $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') {
- $properties[$prop->name][0] = $node->uniquename;
- }
- }
-
-
- $volume = '';
- $volumetitle = '';
- $issue = '';
- $pages = '';
- $publisher = '';
- $series_name = '';
- $pubplace = '';
- $miniref = '';
- $cross_refs = array();
- foreach ($properties as $name => $element) {
- foreach ($element as $index => $value) {
-
- $pub_arr[$name] = $value;
-
- 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;
-
-
- }
- 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'][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 = 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;
- }
-
-
- 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);
- }
- }
- }
-
- 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);
- }
- }
- }
- function chado_pub_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $pub_id = chado_get_id_for_node('pub', $nid);
-
- $values = array('pub_id' => $pub_id);
- $pub = tripal_core_generate_chado_var('pub', $values);
-
-
- $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');
-
- $nodes[$nid]->path = "pub/$pub_id";
- $nodes[$nid]->pub = $pub;
- }
- }
- function chado_pub_delete(&$node) {
- $pub_id = chado_get_id_for_node('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(
- '#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;
- }
- }
- function tripal_pub_node_insert($node) {
-
-
-
-
-
-
- if ($node->type == 'chado_pub') {
- $pub_id = chado_get_id_for_node('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_for_node('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_for_node('pub', $node->nid);
- tripal_pub_set_pub_url($node, $pub_id);
- }
- }
|