tripal_pub.chado_node.inc 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. <?php
  2. /**
  3. * @file
  4. * Implements the pub node content type
  5. */
  6. /**
  7. * Implements hook_node_info().
  8. *
  9. * @ingroup tripal_pub
  10. */
  11. function tripal_pub_node_info() {
  12. return array(
  13. 'chado_pub' => array(
  14. 'name' => t('Publication'),
  15. 'base' => 'chado_pub',
  16. 'description' => t('A publication from the Chado database'),
  17. 'has_title' => TRUE,
  18. 'locked' => TRUE,
  19. 'chado_node_api' => array(
  20. 'base_table' => 'pub',
  21. 'hook_prefix' => 'chado_pub',
  22. 'record_type_title' => array(
  23. 'singular' => t('Publication'),
  24. 'plural' => t('Publications')
  25. ),
  26. 'sync_filters' => array(
  27. 'type_id' => FALSE,
  28. 'organism_id' => FALSE
  29. ),
  30. ),
  31. ),
  32. );
  33. }
  34. /**
  35. * Implements hook_form().
  36. *
  37. * @ingroup tripal_pub
  38. */
  39. function chado_pub_form($node, $form_state) {
  40. $form = array();
  41. // Default values can come in the following ways:
  42. //
  43. // 1) as elements of the $node object. This occurs when editing an existing pub
  44. // 2) in the $form_state['values'] array which occurs on a failed validation or
  45. // ajax callbacks from non submit form elements
  46. // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit
  47. // form elements and the form is being rebuilt
  48. //
  49. // set form field defaults
  50. $pub_id = null;
  51. $title = '';
  52. $pyear = '';
  53. $uniquename = '';
  54. $type_id = '';
  55. $is_obsolete = '';
  56. // some of the fields in the pub table should show up in the properties
  57. // form elements to make the form more seemless. We will add them
  58. // to this array.
  59. $more_props = array();
  60. // if we are editing an existing node then the pub is already part of the node
  61. if (property_exists($node, 'pub')) {
  62. $pub = $node->pub;
  63. $pub = chado_expand_var($pub, 'field', 'pub.title');
  64. $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
  65. $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
  66. $pub_id = $pub->pub_id;
  67. $title = $pub->title;
  68. $pyear = $pub->pyear;
  69. $uniquename = $pub->uniquename;
  70. $type_id = $pub->type_id->cvterm_id;
  71. $is_obsolete = $pub->is_obsolete;
  72. // if the obsolete value is set by the database then it is in the form of
  73. // 't' or 'f', we need to convert to 1 or 0
  74. $is_obsolete = $is_obsolete == 't' ? 1 : $is_obsolete;
  75. $is_obsolete = $is_obsolete == 'f' ? 0 : $is_obsolete;
  76. // set the organism_id in the form
  77. $form['pub_id'] = array(
  78. '#type' => 'value',
  79. '#value' => $pub->pub_id,
  80. );
  81. // get fields from the pub table and convert them to properties. We will add these to the $more_props
  82. // array which gets passed in to the tripal_core_properties_form() API call further down
  83. if ($pub->volumetitle) {
  84. $cvterm = tripal_cv_get_cvterm_by_name('Volume Title', NULL, 'tripal_pub');
  85. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volumetitle);
  86. }
  87. if ($pub->volume) {
  88. $cvterm = tripal_cv_get_cvterm_by_name('Volume', NULL, 'tripal_pub');
  89. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volume);
  90. }
  91. if ($pub->series_name) {
  92. switch ($pub->type_id->name) {
  93. case 'Journal Article':
  94. $cvterm = tripal_cv_get_cvterm_by_name('Journal Name', NULL, 'tripal_pub');
  95. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
  96. break;
  97. case 'Conference Proceedings':
  98. $cvterm = tripal_cv_get_cvterm_by_name('Conference Name', NULL, 'tripal_pub');
  99. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
  100. break;
  101. default:
  102. $cvterm = tripal_cv_get_cvterm_by_name('Series Name', NULL, 'tripal_pub');
  103. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
  104. }
  105. }
  106. if ($pub->issue) {
  107. $cvterm = tripal_cv_get_cvterm_by_name('Issue', NULL, 'tripal_pub');
  108. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->issue);
  109. }
  110. if ($pub->pages) {
  111. $cvterm = tripal_cv_get_cvterm_by_name('Pages', NULL, 'tripal_pub');
  112. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
  113. }
  114. if ($pub->miniref) {
  115. // not sure what to do with this one
  116. }
  117. if ($pub->publisher) {
  118. $cvterm = tripal_cv_get_cvterm_by_name('Publisher', NULL, 'tripal_pub');
  119. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->publisher);
  120. }
  121. if ($pub->pubplace) {
  122. $cvterm = tripal_cv_get_cvterm_by_name('Published Location', NULL, 'tripal_pub');
  123. $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
  124. }
  125. }
  126. // if we are re constructing the form from a failed validation or ajax callback
  127. // then use the $form_state['values'] values
  128. if (array_key_exists('values', $form_state) and isset($form_state['values']['pubtitle'])) {
  129. $title = $form_state['values']['pubtitle'];
  130. $pyear = $form_state['values']['pyear'];
  131. $uniquename = $form_state['values']['uniquename'];
  132. $type_id = $form_state['values']['type_id'];
  133. $is_obsolete = $form_state['values']['is_obsolete'];
  134. }
  135. // if we are re building the form from after submission (from ajax call) then
  136. // the values are in the $form_state['input'] array
  137. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  138. $title = $form_state['input']['pubtitle'];
  139. $uniquename = $form_state['input']['uniquename'];
  140. $type_id = $form_state['input']['type_id'];
  141. $is_obsolete = $form_state['input']['is_obsolete'];
  142. }
  143. // a drupal title can only be 255 characters, but the Chado title can be much longer.
  144. // we use the publication title as the drupal title, but we'll need to truncate it.
  145. $form['title'] = array(
  146. '#type' => 'hidden',
  147. '#value' => substr($title, 0, 255),
  148. );
  149. $form['pubtitle'] = array(
  150. '#type' => 'textarea',
  151. '#title' => t('Publication Title'),
  152. '#default_value' => $title,
  153. '#required' => TRUE,
  154. );
  155. // get the list of publication types. In the Tripal publication
  156. // ontologies these are all grouped under the term 'Publication Type'
  157. // we want the default to be 'Journal Article'
  158. $sql = "
  159. SELECT
  160. CVTS.cvterm_id, CVTS.name
  161. FROM {cvtermpath} CVTP
  162. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  163. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  164. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  165. WHERE
  166. CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  167. NOT CVTS.is_obsolete = 1
  168. ORDER BY CVTS.name ASC
  169. ";
  170. $results = chado_query($sql);
  171. $pub_types = array();
  172. while ($pub_type = $results->fetchObject()) {
  173. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  174. // if we don't have a default type then set the default to be 'Journal Article'
  175. if (strcmp($pub_type->name,"Journal Article") == 0 and !$type_id) {
  176. $type_id = $pub_type->cvterm_id;
  177. }
  178. }
  179. $form['type_id'] = array(
  180. '#type' => 'select',
  181. '#title' => t('Publication Type'),
  182. '#options' => $pub_types,
  183. '#required' => TRUE,
  184. '#default_value' => $type_id,
  185. );
  186. $form['pyear'] = array(
  187. '#type' => 'textfield',
  188. '#title' => t('Publication Year'),
  189. '#default_value' => $pyear,
  190. '#required' => TRUE,
  191. '#size' => 5,
  192. '#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.'),
  193. );
  194. $form['uniquename'] = array(
  195. '#type' => 'textarea',
  196. '#title' => t('Citation'),
  197. '#default_value' => $uniquename,
  198. '#description' => t('All publications must have a unique citation.
  199. <b>Please enter the full citation for this publication or leave blank and one will be generated
  200. automatically if possible</b>. For PubMed style citations list
  201. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  202. 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.
  203. 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
  204. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
  205. );
  206. $form['is_obsolete'] = array(
  207. '#type' => 'checkbox',
  208. '#title' => t('Is Obsolete? (Check for Yes)'),
  209. '#default_value' => $is_obsolete,
  210. );
  211. // Properties Form
  212. // ----------------------------------
  213. // Need to pass in our own select_options since we use cvtermpath to filter ours
  214. $select_options = array();
  215. $select_options[] = 'Select a Property';
  216. $sql = "
  217. SELECT
  218. DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  219. FROM {cvtermpath} CVTP
  220. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  221. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  222. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  223. WHERE CV.name = 'tripal_pub' and
  224. (CVTO.name = 'Publication Details' OR CVTS.name = 'Publication Type') AND
  225. NOT CVTS.is_obsolete = 1
  226. ORDER BY CVTS.name ASC
  227. ";
  228. $prop_types = chado_query($sql);
  229. while ($prop = $prop_types->fetchObject()) {
  230. // add all properties except the Citation. That property is set via the uniquename field
  231. if ($prop->name == 'Citation') {
  232. continue;
  233. }
  234. // Publication Dbxref's are handled by the dbxref form addition below
  235. if ($prop->name == 'Publication Dbxref') {
  236. continue;
  237. }
  238. $select_options[$prop->cvterm_id] = $prop->name;
  239. }
  240. $details = array(
  241. 'property_table' => 'pubprop',
  242. 'chado_id' => $pub_id,
  243. 'cv_name' => 'tripal_pub',
  244. 'select_options' => $select_options,
  245. );
  246. chado_add_node_form_properties($form, $form_state, $details);
  247. // RELATIONSHIPS FORM
  248. //---------------------------------------------
  249. // We want to use the contact_relationship_types cv if there are any terms available
  250. // and if not, then default to the relationship ontology
  251. $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'pub_relationship_types'));
  252. if (count($cv_result) > 0) {
  253. $cv_id = $cv_result[0]->cv_id;
  254. $cv_name = 'pub_relationship_types';
  255. $select_options = tripal_cv_get_cvterm_options($cv_id);
  256. }
  257. // D7 @TODO: tell tripal admin's about this
  258. $details = array(
  259. 'relationship_table' => 'pub_relationship', // the name of the _relationship table
  260. 'base_table' => 'pub', // the name of your chado base table
  261. 'base_foreign_key' => 'pub_id', // the name of the key in your base chado table
  262. 'base_key_value' => $pub_id, // the value of example_id for this record
  263. 'nodetype' => 'pub', // the human-readable name of your node type
  264. 'cv_name' => $cv_name, // the cv.name of the cv containing the properties
  265. 'base_name_field' => 'uniquename', // the base table field you want to be used as the name
  266. 'select_options' => $select_options
  267. );
  268. // Adds the form elements to your current form
  269. chado_add_node_form_relationships($form, $form_state, $details);
  270. // ADDITIONAL DBXREFS FORM
  271. //---------------------------------------------
  272. $details = array(
  273. 'linking_table' => 'pub_dbxref', // the name of the _dbxref table
  274. 'base_foreign_key' => 'pub_id', // the name of the key in your base chado table
  275. 'base_key_value' => $pub_id // the value of pub_id for this record
  276. );
  277. // Adds the form elements to your current form
  278. chado_add_node_form_dbxrefs($form, $form_state, $details);
  279. return $form;
  280. }
  281. /**
  282. * Implements hook_validate().
  283. *
  284. * @ingroup tripal_pub
  285. */
  286. function chado_pub_validate($node, $form, &$form_state) {
  287. // get the submitted values
  288. $title = trim($node->pubtitle);
  289. $pyear = trim($node->pyear);
  290. $uniquename = trim($node->uniquename);
  291. $is_obsolete = $node->is_obsolete;
  292. $type_id = $node->type_id;
  293. // if this is a delete then don't validate
  294. if($node->op == 'Delete') {
  295. return;
  296. }
  297. // we are syncing if we do not have a node ID but we do have a pub_id. We don't
  298. // need to validate during syncing so just skip it.
  299. if (is_null($node->nid) and property_exists($node, 'pub_id') and $node->pub_id != 0) {
  300. return;
  301. }
  302. $pub = array();
  303. // make sure the year is four digits
  304. if(!preg_match('/^\d{4}$/', $pyear)){
  305. form_set_error('pyear', t('The publication year should be a 4 digit year.'));
  306. return;
  307. }
  308. // get the type of publication
  309. $values = array('cvterm_id' => $type_id);
  310. $options = array('statement_name' => 'sel_pub_ty');
  311. $cvterm = chado_select_record('cvterm', array('name'), $values, $options);
  312. if (count($cvterm) == 0) {
  313. $message = t('Invalid publication type.');
  314. form_set_error('type_id', $message);
  315. return;
  316. }
  317. // get the media name looking at the properties
  318. $series_name = '';
  319. foreach ($node as $element => $value) {
  320. // if this is an existing property (either previously in the database or
  321. // added via AHAH/AJAX callback)
  322. if (preg_match('/^prop_value-(\d+)-(\d+)$/', $element, $matches)) {
  323. $prop_type_id = $matches[1];
  324. $prop_type = tripal_cv_get_cvterm_by_id($prop_type_id);
  325. if($prop_type->name == 'Conference Name' or $prop_type->name == 'Journal Name') {
  326. $series_name = $value;
  327. }
  328. if($prop_type->name == 'Citation') {
  329. $uniquename = $value;
  330. }
  331. $pub[$prop_type->name] = $value;
  332. }
  333. // if this is a new property (added by this submit of the form)
  334. elseif ($element == 'new_id') {
  335. $prop_type = tripal_cv_get_cvterm_by_id($value);
  336. if($prop_type->name == 'Conference Name' or $prop_type->name == 'Journal Name') {
  337. $series_name = $node->new_value;
  338. }
  339. if($prop_type->name == 'Citation') {
  340. $uniquename = $node->new_value;
  341. }
  342. $pub[$prop_type->name] = $node->new_value;
  343. }
  344. }
  345. // if the citation is missing then try to generate one
  346. if (!$uniquename) {
  347. $pub['Title'] = $title;
  348. $pub['Publication Type'][0] = $cvterm[0]->name;
  349. $pub['Year'] = $pyear;
  350. $uniquename = tripal_pub_create_citation($pub);
  351. if (!$uniquename) {
  352. form_set_error('uniquename', "Cannot automatically generate a citation for this publication type. Please add one manually.");
  353. }
  354. }
  355. $skip_duplicate_check = 0;
  356. // if this publication is a Patent then skip the validation below. Patents can have the title
  357. // name and year but be different
  358. if (strcmp($cvterm[0]->name,'Patent') == 0) {
  359. $skip_duplicate_check = 1;
  360. }
  361. // Validating for an update
  362. if (!is_null($node->nid)) {
  363. $pub_id = $node->pub_id;
  364. // first get the original title, type and year before it was changed
  365. $values = array('pub_id' => $pub_id);
  366. $columns = array('title', 'pyear', 'type_id', 'series_name');
  367. $options = array('statement_name' => 'sel_pub_id');
  368. $pub = chado_select_record('pub', $columns, $values, $options);
  369. // if the title, type, year or series_name have changed then check the pub
  370. // to see if it is a duplicate of another
  371. if((strcmp(strtolower($pub[0]->title), strtolower($title)) == 0) and
  372. (strcmp(strtolower($pub[0]->series_name), strtolower($series_name)) == 0) and
  373. ($pub[0]->type_id == $type_id) and
  374. ($pub[0]->pyear == $pyear)) {
  375. $skip_duplicate_check = 1;
  376. }
  377. // check to see if a duplicate publication already exists
  378. if (!$skip_duplicate_check) {
  379. chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id);
  380. }
  381. chado_pub_validate_check_uniquename($uniquename, $pub_id);
  382. }
  383. // Validating for an insert
  384. else {
  385. chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm);
  386. chado_pub_validate_check_uniquename($uniquename);
  387. }
  388. }
  389. /**
  390. * Validate the publication uniquename. To be called from hook_validate().
  391. *
  392. * @param $uniquename
  393. * The uniquename of the publication
  394. *
  395. * @ingroup tripal_pub
  396. */
  397. function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
  398. $results = tripal_pub_get_pub_by_uniquename($uniquename);
  399. // make sure we don't capture our pub_id in the list (remove it)
  400. foreach ($results as $index => $found_pub_id) {
  401. if($found_pub_id == $pub_id){
  402. unset($results[$index]);
  403. }
  404. }
  405. if (count($results) > 0) {
  406. $message = t('A publication with this unique citation already exists.');
  407. form_set_error('uniquename', $message);
  408. }
  409. }
  410. /**
  411. * Check for duplicate publications. To be called from hook_validate().
  412. *
  413. * @param $title
  414. * The title of the publication
  415. * @param $pyear
  416. * The year the publication was published
  417. * @param $series_name
  418. * The series name of the publication
  419. * @param $cvterm
  420. * The type of publication
  421. * @param $pub_id
  422. * the unique id of the publication
  423. *
  424. * @ingroup tripal_pub
  425. */
  426. function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
  427. // make sure the publication is unique using the prefereed import duplication check
  428. $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
  429. switch ($import_dups_check) {
  430. case 'title_year':
  431. $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, NULL, $pyear, NULL);
  432. // make sure we don't capture our pub_id in the list (remove it)
  433. foreach ($results as $index => $found_pub_id) {
  434. if($found_pub_id == $pub_id){
  435. unset($results[$index]);
  436. }
  437. }
  438. if (count($results) > 0) {
  439. $message = t('A publication with this title and publication year, already exists.');
  440. form_set_error('pyear', $message);
  441. }
  442. break;
  443. case 'title_year_type':
  444. $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, $cvterm[0]->name, $pyear, NULL);
  445. // make sure we don't capture our pub_id in the list (remove it)
  446. foreach ($results as $index => $found_pub_id) {
  447. if($found_pub_id == $pub_id){
  448. unset($results[$index]);
  449. }
  450. }
  451. if (count($results) > 0) {
  452. $message = t('A publication with this title, type and publication year, already exists.');
  453. form_set_error('pyear', $message);
  454. }
  455. break;
  456. case 'title_year_media':
  457. $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, NULL, $pyear, $series_name);
  458. // make sure we don't capture our pub_id in the list (remove it)
  459. foreach ($results as $index => $found_pub_id) {
  460. if($found_pub_id == $pub_id){
  461. unset($results[$index]);
  462. }
  463. }
  464. if (count($results) > 0) {
  465. $message = t('A publication with this title, media name (e.g. Journal Name) and publication year, already exists.');
  466. form_set_error('pyear', $message);
  467. }
  468. break;
  469. }
  470. }
  471. /**
  472. * Implement hook_node_access().
  473. *
  474. * This hook allows node modules to limit access to the node types they define.
  475. *
  476. * @param $node
  477. * The node on which the operation is to be performed, or, if it does not yet exist, the
  478. * type of node to be created
  479. *
  480. * @param $op
  481. * The operation to be performed
  482. *
  483. * @param $account
  484. * A user object representing the user for whom the operation is to be performed
  485. *
  486. * @return
  487. * If the permission for the specified operation is not set then return FALSE. If the
  488. * permission is set then return NULL as this allows other modules to disable
  489. * access. The only exception is when the $op == 'create'. We will always
  490. * return TRUE if the permission is set.
  491. *
  492. * @ingroup tripal_pub
  493. */
  494. function chado_pub_node_access($node, $op, $account) {
  495. $node_type = $node;
  496. if (is_object($node)) {
  497. $node_type = $node->type;
  498. }
  499. if($node_type == 'chado_pub') {
  500. if ($op == 'create') {
  501. if (!user_access('create chado_pub', $account)) {
  502. return NODE_ACCESS_DENY;
  503. }
  504. return NODE_ACCESS_ALLOW;
  505. }
  506. if ($op == 'update') {
  507. if (!user_access('edit chado_pub', $account)) {
  508. return NODE_ACCESS_DENY;
  509. }
  510. }
  511. if ($op == 'delete') {
  512. if (!user_access('delete chado_pub', $account)) {
  513. return NODE_ACCESS_DENY;
  514. }
  515. }
  516. if ($op == 'view') {
  517. if (!user_access('access chado_pub', $account)) {
  518. return NODE_ACCESS_DENY;
  519. }
  520. }
  521. return NODE_ACCESS_IGNORE;
  522. }
  523. }
  524. /**
  525. * Implements hook_insert().
  526. *
  527. * @ingroup tripal_pub
  528. */
  529. function chado_pub_insert($node) {
  530. $title = trim($node->pubtitle);
  531. $pyear = trim($node->pyear);
  532. $uniquename = trim($node->uniquename);
  533. $is_obsolete = $node->is_obsolete;
  534. $type_id = $node->type_id;
  535. // we need an array suitable for the tripal_pub_create_citation() function
  536. // to automatically generate a citation if a uniquename doesn't already exist
  537. $pub_arr = array();
  538. // if there is an pub_id in the $node object then this must be a sync so
  539. // we can skip adding the pub as it is already there, although
  540. // we do need to proceed with the rest of the insert
  541. if (!property_exists($node, 'pub_id')) {
  542. $properties = array(); // stores all of the properties we need to add
  543. $cross_refs = array(); // stores any cross references for this publication
  544. // get the properties from the form
  545. $properties = chado_retrieve_node_form_properties($node);
  546. // get the list of properties for easy lookup (without doing lots of database queries
  547. $properties_list = array();
  548. $sql = "
  549. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  550. FROM {cvtermpath} CVTP
  551. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  552. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  553. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  554. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  555. NOT CVTS.is_obsolete = 1
  556. ORDER BY CVTS.name ASC
  557. ";
  558. $prop_types = chado_query($sql);
  559. while ($prop = $prop_types->fetchObject()) {
  560. $properties_list[$prop->cvterm_id] = $prop->name;
  561. // The 'Citation' term is special because it serves
  562. // both as a property and as the uniquename for the
  563. // pub and we want it stored in both the pub table and the pubprop table
  564. if ($prop->name == 'Citation') {
  565. $citation_id = $prop->cvterm_id;
  566. if (!empty($node->uniquename)) {
  567. $properties[$citation_id] = $node->uniquename;
  568. }
  569. }
  570. }
  571. // iterate through all of the properties and remove those that really are
  572. // part of the pub table fields
  573. $volume = '';
  574. $volumetitle = '';
  575. $issue = '';
  576. $pages = '';
  577. $publisher = '';
  578. $series_name = '';
  579. $pubplace = '';
  580. $miniref = '';
  581. $cross_refs = array();
  582. foreach ($properties as $type_id => $element) {
  583. $value = trim($element[0]);
  584. $name = $properties_list[$type_id];
  585. // populate our $pub_array for building a citation
  586. $pub_arr[$name] = $value;
  587. // remove properties that are stored in the pub table
  588. if ($name == "Volume") {
  589. $volume = $value;
  590. unset($properties[$type_id]);
  591. }
  592. elseif ($name == "Volume Title") {
  593. $volumetitle = $value;
  594. unset($properties[$type_id]);
  595. }
  596. elseif ($name == "Issue") {
  597. $issue = $value;
  598. unset($properties[$type_id]);
  599. }
  600. elseif ($name == "Pages") {
  601. $pages = $value;
  602. unset($properties[$type_id]);
  603. }
  604. elseif ($name == "Publisher") {
  605. $publisher = $value;
  606. unset($properties[$type_id]);
  607. }
  608. elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
  609. $series_name = $value;
  610. unset($properties[$type_id]);
  611. }
  612. elseif ($name == "Journal Country" or $name == "Published Location") {
  613. $pubplace = $value;
  614. // allow this property to go into the pubprop table so we don't loose info
  615. // so don't unset it. But it will also go into the pub.pubplace field
  616. }
  617. elseif ($name == "Publication Dbxref") {
  618. // we will add the cross-references to the pub_dbxref table
  619. // but we also want to keep the property in the pubprop table so don't unset it
  620. $cross_refs[] = $value;
  621. }
  622. }
  623. // generate a citation for this pub if one doesn't already exist
  624. if (!$node->uniquename and !array_key_exists($citation_id, $properties)) {
  625. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  626. $pub_arr['Title'] = $node->pubtitle;
  627. $pub_arr['Publication Type'][0] = $pub_type->name;
  628. $pub_arr['Year'] = $node->pyear;
  629. $node->uniquename = tripal_pub_create_citation($pub_arr);
  630. $properties[$citation_id][0] = $node->uniquename;
  631. }
  632. // insert the pub record
  633. $values = array(
  634. 'title' => $node->pubtitle,
  635. 'series_name' => substr($series_name, 0, 255),
  636. 'type_id' => $node->type_id,
  637. 'pyear' => $node->pyear,
  638. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  639. 'uniquename' => $node->uniquename,
  640. 'volumetitle' => $volumetitle,
  641. 'volume' => $volume,
  642. 'issue' => $issue,
  643. 'pages' => $pages,
  644. 'miniref' => substr($miniref, 0, 255),
  645. 'publisher' => substr($publisher, 0, 255),
  646. 'pubplace' => substr($pubplace, 0, 255),
  647. );
  648. $pub = chado_insert_record('pub', $values);
  649. if (!$pub) {
  650. drupal_set_message("Error inserting publication", "error");
  651. watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
  652. return;
  653. }
  654. $pub_id = $pub['pub_id'];
  655. // now add in the properties
  656. // Only adds in those not used in the pub record
  657. $details = array(
  658. 'property_table' => 'pubprop',
  659. 'base_table' => 'pub',
  660. 'foreignkey_name' => 'pub_id',
  661. 'foreignkey_value' => $pub_id
  662. );
  663. chado_update_node_form_properties($node, $details, $properties);
  664. // * Relationships Form *
  665. $details = array(
  666. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  667. 'foreignkey_value' => $pub_id // value of the pub_id key
  668. );
  669. chado_update_node_form_relationships($node, $details);
  670. // add in any database cross-references
  671. foreach ($cross_refs as $index => $ref) {
  672. $dbxref = array();
  673. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  674. $dbxref['db_name'] = $matches[1];
  675. $dbxref['accession'] = $matches[2];
  676. }
  677. $success = chado_associate_dbxref('pub', $pub['pub_id'], $dbxref);
  678. if (!$success) {
  679. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  680. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  681. array('%ref' => $ref), WATCHDOG_ERROR);
  682. }
  683. }
  684. // * Additional DBxrefs Form *
  685. $details = array(
  686. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  687. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  688. 'foreignkey_value' => $pub_id // the value of the pub_id key
  689. );
  690. chado_update_node_form_dbxrefs($node, $details);
  691. }
  692. else {
  693. $pub_id = $node->pub_id;
  694. }
  695. // Make sure the entry for this pub doesn't already exist in the
  696. // chado_pub table if it doesn't exist then we want to add it.
  697. $check_org_id = chado_get_id_from_nid('pub', $node->nid);
  698. if (!$check_org_id) {
  699. $record = new stdClass();
  700. $record->nid = $node->nid;
  701. $record->vid = $node->vid;
  702. $record->pub_id = $pub_id;
  703. drupal_write_record('chado_pub', $record);
  704. }
  705. }
  706. /**
  707. * Implements hook_update().
  708. *
  709. * The purpose of the function is to allow the module to take action when an edited node is being
  710. * updated. It updates any name changes to the database tables that werec reated upon registering a Publication.
  711. * As well, the database will be changed, so the user changed information will be saved to the database.
  712. *
  713. * @param $node
  714. * The node being updated
  715. *
  716. * @ingroup tripal_pub
  717. */
  718. function chado_pub_update($node) {
  719. $title = trim($node->pubtitle);
  720. $pyear = trim($node->pyear);
  721. $uniquename = trim($node->uniquename);
  722. $is_obsolete = $node->is_obsolete;
  723. $type_id = $node->type_id;
  724. // we need an array suitable for the tripal_pub_create_citation() function
  725. // to automatically generate a citation if a uniquename doesn't already exist
  726. $pub_arr = array();
  727. // get the publication ID for this publication
  728. $pub_id = chado_get_id_from_nid('pub', $node->nid) ;
  729. $properties = array(); // stores all of the properties we need to add
  730. $cross_refs = array(); // stores any cross references for this publication
  731. // get the properties from the form
  732. $properties = chado_retrieve_node_form_properties($node);
  733. // get the list of properties for easy lookup (without doing lots of database queries
  734. $properties_list = array();
  735. $sql = "
  736. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  737. FROM {cvtermpath} CVTP
  738. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  739. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  740. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  741. WHERE CV.name = 'tripal_pub' and
  742. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  743. NOT CVTS.is_obsolete = 1
  744. ORDER BY CVTS.name ASC
  745. ";
  746. $prop_types = chado_query($sql);
  747. while ($prop = $prop_types->fetchObject()) {
  748. $properties_list[$prop->cvterm_id] = $prop->name;
  749. // The 'Citation' term is special because it serves
  750. // both as a property and as the uniquename for the
  751. // pub and we want it stored in both the pub table and the pubprop table
  752. if ($prop->name == 'Citation') {
  753. $citation_id = $prop->cvterm_id;
  754. if (!empty($node->uniquename)) {
  755. $properties[$citation_id][0] = $node->uniquename;
  756. }
  757. }
  758. }
  759. // iterate through all of the properties and remove those that really are
  760. // part of the pub table fields
  761. $volume = '';
  762. $volumetitle = '';
  763. $issue = '';
  764. $pages = '';
  765. $publisher = '';
  766. $series_name = '';
  767. $pubplace = '';
  768. $miniref = '';
  769. $cross_refs = array();
  770. foreach ($properties as $type_id => $element) {
  771. foreach ($element as $index => $value) {
  772. $name = $properties_list[$type_id];
  773. // populate our $pub_array for building a citation
  774. $pub_arr[$name] = $value;
  775. // remove properties that are stored in the pub table
  776. if ($name == "Volume") {
  777. $volume = $value;
  778. unset($properties[$type_id]);
  779. }
  780. elseif ($name == "Volume Title") {
  781. $volumetitle = $value;
  782. unset($properties[$type_id]);
  783. }
  784. elseif ($name == "Issue") {
  785. $issue = $value;
  786. unset($properties[$type_id]);
  787. }
  788. elseif ($name == "Pages") {
  789. $pages = $value;
  790. unset($properties[$type_id]);
  791. }
  792. elseif ($name == "Publisher") {
  793. $publisher = $value;
  794. unset($properties[$type_id]);
  795. }
  796. elseif ($name == "Journal Name" or $name == "Conference Name") {
  797. $series_name = $value;
  798. unset($properties[$type_id]);
  799. }
  800. elseif ($name == "Journal Country" or $name == "Published Location") {
  801. $pubplace = $value;
  802. // allow this property to go into the pubprop table so we don't loose info
  803. // so don't unset it. But it will also go into the pub.pubplace field
  804. }
  805. elseif ($name == "Publication Dbxref") {
  806. // we will add the cross-references to the pub_dbxref table
  807. // but we also want to keep the property in the pubprop table so don't unset it
  808. $cross_refs[] = $value;
  809. }
  810. }
  811. }
  812. // generate a citation for this pub if one doesn't already exist
  813. if (!$node->uniquename) {
  814. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  815. $pub_arr['Title'] = $node->pubtitle;
  816. $pub_arr['Publication Type'][0] = $pub_type->name;
  817. $pub_arr['Year'] = $node->pyear;
  818. $node->uniquename = tripal_pub_create_citation($pub_arr);
  819. $properties[$citation_id][0] = $node->uniquename;
  820. }
  821. // update the pub record
  822. $match = array(
  823. 'pub_id' => $pub_id,
  824. );
  825. $values = array(
  826. 'title' => $node->pubtitle,
  827. 'type_id' => $node->type_id,
  828. 'pyear' => $node->pyear,
  829. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  830. 'uniquename' => $node->uniquename,
  831. 'series_name' => substr($series_name, 0, 255),
  832. 'volumetitle' => $volumetitle,
  833. 'volume' => $volume,
  834. 'issue' => $issue,
  835. 'pages' => $pages,
  836. 'miniref' => substr($miniref, 0, 255),
  837. 'publisher' => substr($publisher, 0, 255),
  838. 'pubplace' => substr($pubplace, 0, 255),
  839. );
  840. $status = chado_update_record('pub', $match, $values);
  841. if (!$status) {
  842. drupal_set_message("Error updating publication", "error");
  843. watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
  844. return;
  845. }
  846. // now add in the properties by first removing any the publication
  847. // already has and adding the ones we have
  848. $details = array(
  849. 'property_table' => 'pubprop',
  850. 'base_table' => 'pub',
  851. 'foreignkey_name' => 'pub_id',
  852. 'foreignkey_value'=> $pub_id
  853. );
  854. chado_update_node_form_properties($node, $details, $properties);
  855. // * Relationships Form *
  856. $details = array(
  857. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  858. 'foreignkey_value' => $pub_id // value of the pub_id key
  859. );
  860. chado_update_node_form_relationships($node, $details);
  861. // add in any database cross-references after first removing
  862. chado_delete_record('pub_dbxref', array('pub_id' => $pub_id));
  863. foreach ($cross_refs as $index => $ref) {
  864. $dbxref = array();
  865. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  866. $dbxref['db_name'] = $matches[1];
  867. $dbxref['accession'] = $matches[2];
  868. }
  869. $success = chado_associate_dbxref('pub', $pub_id, $dbxref);
  870. if (!$success) {
  871. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  872. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  873. array('%ref' => $ref), WATCHDOG_ERROR);
  874. }
  875. }
  876. // * Additional DBxrefs Form *
  877. $details = array(
  878. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  879. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  880. 'foreignkey_value' => $pub_id // the value of the pub_id key
  881. );
  882. chado_update_node_form_dbxrefs($node, $details);
  883. }
  884. /**
  885. * Implements hook_load().
  886. *
  887. * @param $node
  888. * The node that is to be loaded
  889. *
  890. * @return $node
  891. * The node with the information to be loaded into the database
  892. *
  893. * @ingroup tripal_pub
  894. */
  895. function chado_pub_load($nodes) {
  896. foreach ($nodes as $nid => $node) {
  897. // find the pub and add in the details
  898. $pub_id = chado_get_id_from_nid('pub', $nid);
  899. // get the pub
  900. $values = array('pub_id' => $pub_id);
  901. $pub = chado_generate_var('pub', $values);
  902. // expand the 'text' fields as those aren't included by default
  903. // and they really shouldn't be so large to cause problems
  904. $pub = chado_expand_var($pub, 'field', 'pub.title');
  905. $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
  906. $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
  907. // set the URL path
  908. $nodes[$nid]->path = "pub/$pub_id";
  909. $nodes[$nid]->pub = $pub;
  910. }
  911. }
  912. /**
  913. * Implements hook_delete().
  914. *
  915. * This function takes a node and if the delete button has been chosen by the user, the publication
  916. * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
  917. * the 'chado_pub' table.
  918. *
  919. * @parm $node
  920. * Then node to be deleted
  921. *
  922. * @ingroup tripal_pub
  923. */
  924. function chado_pub_delete(&$node) {
  925. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  926. // if we don't have a pub id for this node then this isn't a node of
  927. // type chado_pub or the entry in the chado_pub table was lost.
  928. if (!$pub_id) {
  929. return;
  930. }
  931. // Remove data from {chado_pub}, {node} and {node_revision} tables of
  932. // drupal database
  933. $sql_del = "DELETE FROM {chado_pub} WHERE nid = :nid AND vid = :vid";
  934. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  935. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  936. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  937. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  938. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  939. // Remove data from pub and pubprop tables of chado database as well
  940. chado_query("DELETE FROM {pubprop} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  941. chado_query("DELETE FROM {pub} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  942. }
  943. /**
  944. * Implements hook_node_view(). Acts on all content types.
  945. *
  946. * @ingroup tripal_pub
  947. */
  948. function tripal_pub_node_view($node, $view_mode, $langcode) {
  949. switch ($node->type) {
  950. case 'chado_pub':
  951. // Show feature browser and counts
  952. if ($view_mode == 'full') {
  953. $node->content['tripal_pub_authors'] = array(
  954. '#markup' => theme('tripal_pub_authors', array('node' => $node)),
  955. '#tripal_toc_id' => 'authors',
  956. '#tripal_toc_title' => 'Author Details',
  957. );
  958. $node->content['tripal_pub_base'] = array(
  959. '#markup' => theme('tripal_pub_base', array('node' => $node)),
  960. '#tripal_toc_id' => 'base',
  961. '#tripal_toc_title' => 'Overview',
  962. '#weight' => -100,
  963. );
  964. $node->content['tripal_pub_featuremaps'] = array(
  965. '#markup' => theme('tripal_pub_featuremaps', array('node' => $node)),
  966. '#tripal_toc_id' => 'featuremaps',
  967. '#tripal_toc_title' => 'Maps',
  968. );
  969. $node->content['tripal_pub_features'] = array(
  970. '#markup' => theme('tripal_pub_features', array('node' => $node)),
  971. '#tripal_toc_id' => 'features',
  972. '#tripal_toc_title' => 'Features',
  973. );
  974. $node->content['tripal_pub_libraries'] = array(
  975. '#markup' => theme('tripal_pub_libraries', array('node' => $node)),
  976. '#tripal_toc_id' => 'libraries',
  977. '#tripal_toc_title' => 'Libraries',
  978. );
  979. $node->content['tripal_pub_projects'] = array(
  980. '#markup' => theme('tripal_pub_projects', array('node' => $node)),
  981. '#tripal_toc_id' => 'projects',
  982. '#tripal_toc_title' => 'Projects',
  983. );
  984. $node->content['tripal_pub_properties'] = array(
  985. '#markup' => theme('tripal_pub_properties', array('node' => $node)),
  986. '#tripal_toc_id' => 'properties',
  987. '#tripal_toc_title' => 'Properties',
  988. );
  989. $node->content['tripal_pub_references'] = array(
  990. '#markup' => theme('tripal_pub_references', array('node' => $node)),
  991. '#tripal_toc_id' => 'references',
  992. '#tripal_toc_title' => 'Cross References',
  993. );
  994. $node->content['tripal_pub_relationships'] = array(
  995. '#markup' => theme('tripal_pub_relationships', array('node' => $node)),
  996. '#tripal_toc_id' => 'relationships',
  997. '#tripal_toc_title' => 'Relationships',
  998. );
  999. $node->content['tripal_pub_stocks'] = array(
  1000. '#markup' => theme('tripal_pub_stocks', array('node' => $node)),
  1001. '#tripal_toc_id' => 'stocks',
  1002. '#tripal_toc_title' => 'Stocks',
  1003. );
  1004. }
  1005. if ($view_mode == 'teaser') {
  1006. $node->content['tripal_pub_teaser'] = array(
  1007. '#markup' => theme('tripal_pub_teaser', array('node' => $node)),
  1008. );
  1009. }
  1010. break;
  1011. }
  1012. }
  1013. /**
  1014. * Implements hook_node_insert(). Acts on all content types.
  1015. *
  1016. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1017. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1018. * into the publication without needing to know the node. Of course if you know the
  1019. * node that will still work too (e.g. http://[base url]/node/[node id]
  1020. * so the nodeapi function ensures that the URL path is set after insert or update
  1021. * of the node and when the node is loaded if it hasn't yet been set.
  1022. *
  1023. * @ingroup tripal_pub
  1024. */
  1025. function tripal_pub_node_insert($node) {
  1026. if ($node->type == 'chado_pub') {
  1027. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1028. tripal_pub_set_pub_url($node, $pub_id);
  1029. }
  1030. }
  1031. /**
  1032. * Implements hook_node_load(). Acts on all content types.
  1033. *
  1034. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1035. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1036. * into the publication without needing to know the node. Of course if you know the
  1037. * node that will still work too (e.g. http://[base url]/node/[node id]
  1038. * so the nodeapi function ensures that the URL path is set after insert or update
  1039. * of the node and when the node is loaded if it hasn't yet been set.
  1040. *
  1041. * @ingroup tripal_pub
  1042. */
  1043. function tripal_pub_node_load($nodes, $types) {
  1044. if (count(array_intersect(array('chado_pub'), $types))) {
  1045. foreach ($nodes as $nid => $node) {
  1046. if ($node->type == 'chado_pub' and !property_exists($node, 'path')) {
  1047. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1048. $path = tripal_pub_set_pub_url($node, $pub_id);
  1049. }
  1050. }
  1051. }
  1052. }
  1053. /**
  1054. * Implements hook_node_update(). Acts on all content types.
  1055. *
  1056. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1057. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1058. * into the publication without needing to know the node. Of course if you know the
  1059. * node that will still work too (e.g. http://[base url]/node/[node id]
  1060. * so the nodeapi function ensures that the URL path is set after insert or update
  1061. * of the node and when the node is loaded if it hasn't yet been set.
  1062. *
  1063. * @ingroup tripal_pub
  1064. */
  1065. function tripal_pub_node_update($node) {
  1066. if ($node->type == 'chado_pub') {
  1067. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1068. tripal_pub_set_pub_url($node, $pub_id);
  1069. }
  1070. }