tripal_pub.chado_node.inc 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. * @param $pub_id
  395. * If an update, provide the pub_id so we don't check for a matching
  396. * uniquename of the pub we are editing
  397. *
  398. * @ingroup tripal_pub
  399. */
  400. function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
  401. // check to see if a pub exists with this uniquename
  402. $pub = chado_get_publication(array('uniquename' => $uniquename));
  403. if ($pub) {
  404. // if a $pub_id is provided to the function then this is an update
  405. // if the pub_id's don't match then a different pub with the same
  406. // uniquename already exists.
  407. if ($pub->pub_id != $pub_id) {
  408. $message = t('A publication with this unique citation already exists.');
  409. form_set_error('uniquename', $message);
  410. }
  411. }
  412. }
  413. /**
  414. * Check for duplicate publications. To be called from hook_validate().
  415. *
  416. * @param $title
  417. * The title of the publication
  418. * @param $pyear
  419. * The year the publication was published
  420. * @param $series_name
  421. * The series name of the publication
  422. * @param $cvterm
  423. * The type of publication
  424. * @param $pub_id
  425. * the unique id of the publication
  426. *
  427. * @ingroup tripal_pub
  428. */
  429. function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
  430. $pub_details = array(
  431. 'Title' => $title,
  432. 'Year' => $pyear,
  433. 'Series Name' => $series_name,
  434. 'Publication Type' => $cvterm->name,
  435. );
  436. $pub_ids = chado_does_pub_exist($pub_details);
  437. // if we found only one publication and it is our publication then
  438. // return, we're good.
  439. if(count($pub_ids) == 1 and !in_array($pub_id, $pub_ids)) {
  440. return;
  441. }
  442. // return an appropriate message based on the unique constraint settings
  443. $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
  444. switch ($import_dups_check) {
  445. case 'title_year':
  446. $message = t('A publication with this title and publication year already exists.');
  447. form_set_error('pyear', $message);
  448. break;
  449. case 'title_year_type':
  450. $message = t('A publication with this title, type and publication year already exists.');
  451. form_set_error('pyear', $message);
  452. break;
  453. case 'title_year_media':
  454. $message = t('A publication with this title, media name (e.g. Journal Name) and publication year already exists.');
  455. form_set_error('pyear', $message);
  456. break;
  457. }
  458. }
  459. /**
  460. * Implement hook_node_access().
  461. *
  462. * This hook allows node modules to limit access to the node types they define.
  463. *
  464. * @param $node
  465. * The node on which the operation is to be performed, or, if it does not yet exist, the
  466. * type of node to be created
  467. *
  468. * @param $op
  469. * The operation to be performed
  470. *
  471. * @param $account
  472. * A user object representing the user for whom the operation is to be performed
  473. *
  474. * @return
  475. * If the permission for the specified operation is not set then return FALSE. If the
  476. * permission is set then return NULL as this allows other modules to disable
  477. * access. The only exception is when the $op == 'create'. We will always
  478. * return TRUE if the permission is set.
  479. *
  480. * @ingroup tripal_pub
  481. */
  482. function chado_pub_node_access($node, $op, $account) {
  483. $node_type = $node;
  484. if (is_object($node)) {
  485. $node_type = $node->type;
  486. }
  487. if($node_type == 'chado_pub') {
  488. if ($op == 'create') {
  489. if (!user_access('create chado_pub', $account)) {
  490. return NODE_ACCESS_DENY;
  491. }
  492. return NODE_ACCESS_ALLOW;
  493. }
  494. if ($op == 'update') {
  495. if (!user_access('edit chado_pub', $account)) {
  496. return NODE_ACCESS_DENY;
  497. }
  498. }
  499. if ($op == 'delete') {
  500. if (!user_access('delete chado_pub', $account)) {
  501. return NODE_ACCESS_DENY;
  502. }
  503. }
  504. if ($op == 'view') {
  505. if (!user_access('access chado_pub', $account)) {
  506. return NODE_ACCESS_DENY;
  507. }
  508. }
  509. return NODE_ACCESS_IGNORE;
  510. }
  511. }
  512. /**
  513. * Implements hook_insert().
  514. *
  515. * @ingroup tripal_pub
  516. */
  517. function chado_pub_insert($node) {
  518. $title = trim($node->pubtitle);
  519. $pyear = trim($node->pyear);
  520. $uniquename = trim($node->uniquename);
  521. $is_obsolete = $node->is_obsolete;
  522. $type_id = $node->type_id;
  523. // we need an array suitable for the tripal_pub_create_citation() function
  524. // to automatically generate a citation if a uniquename doesn't already exist
  525. $pub_arr = array();
  526. // if there is an pub_id in the $node object then this must be a sync so
  527. // we can skip adding the pub as it is already there, although
  528. // we do need to proceed with the rest of the insert
  529. if (!property_exists($node, 'pub_id')) {
  530. $properties = array(); // stores all of the properties we need to add
  531. $cross_refs = array(); // stores any cross references for this publication
  532. // get the properties from the form
  533. $properties = chado_retrieve_node_form_properties($node);
  534. // get the list of properties for easy lookup (without doing lots of database queries
  535. $properties_list = array();
  536. $sql = "
  537. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  538. FROM {cvtermpath} CVTP
  539. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  540. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  541. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  542. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  543. NOT CVTS.is_obsolete = 1
  544. ORDER BY CVTS.name ASC
  545. ";
  546. $prop_types = chado_query($sql);
  547. while ($prop = $prop_types->fetchObject()) {
  548. $properties_list[$prop->cvterm_id] = $prop->name;
  549. // The 'Citation' term is special because it serves
  550. // both as a property and as the uniquename for the
  551. // pub and we want it stored in both the pub table and the pubprop table
  552. if ($prop->name == 'Citation') {
  553. $citation_id = $prop->cvterm_id;
  554. if (!empty($node->uniquename)) {
  555. $properties[$citation_id] = $node->uniquename;
  556. }
  557. }
  558. }
  559. // iterate through all of the properties and remove those that really are
  560. // part of the pub table fields
  561. $volume = '';
  562. $volumetitle = '';
  563. $issue = '';
  564. $pages = '';
  565. $publisher = '';
  566. $series_name = '';
  567. $pubplace = '';
  568. $miniref = '';
  569. $cross_refs = array();
  570. foreach ($properties as $type_id => $element) {
  571. $value = trim($element[0]);
  572. $name = $properties_list[$type_id];
  573. // populate our $pub_array for building a citation
  574. $pub_arr[$name] = $value;
  575. // remove properties that are stored in the pub table
  576. if ($name == "Volume") {
  577. $volume = $value;
  578. unset($properties[$type_id]);
  579. }
  580. elseif ($name == "Volume Title") {
  581. $volumetitle = $value;
  582. unset($properties[$type_id]);
  583. }
  584. elseif ($name == "Issue") {
  585. $issue = $value;
  586. unset($properties[$type_id]);
  587. }
  588. elseif ($name == "Pages") {
  589. $pages = $value;
  590. unset($properties[$type_id]);
  591. }
  592. elseif ($name == "Publisher") {
  593. $publisher = $value;
  594. unset($properties[$type_id]);
  595. }
  596. elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
  597. $series_name = $value;
  598. unset($properties[$type_id]);
  599. }
  600. elseif ($name == "Journal Country" or $name == "Published Location") {
  601. $pubplace = $value;
  602. // allow this property to go into the pubprop table so we don't loose info
  603. // so don't unset it. But it will also go into the pub.pubplace field
  604. }
  605. elseif ($name == "Publication Dbxref") {
  606. // we will add the cross-references to the pub_dbxref table
  607. // but we also want to keep the property in the pubprop table so don't unset it
  608. $cross_refs[] = $value;
  609. }
  610. }
  611. // generate a citation for this pub if one doesn't already exist
  612. if (!$node->uniquename and !array_key_exists($citation_id, $properties)) {
  613. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  614. $pub_arr['Title'] = $node->pubtitle;
  615. $pub_arr['Publication Type'][0] = $pub_type->name;
  616. $pub_arr['Year'] = $node->pyear;
  617. $node->uniquename = tripal_pub_create_citation($pub_arr);
  618. $properties[$citation_id][0] = $node->uniquename;
  619. }
  620. // insert the pub record
  621. $values = array(
  622. 'title' => $node->pubtitle,
  623. 'series_name' => substr($series_name, 0, 255),
  624. 'type_id' => $node->type_id,
  625. 'pyear' => $node->pyear,
  626. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  627. 'uniquename' => $node->uniquename,
  628. 'volumetitle' => $volumetitle,
  629. 'volume' => $volume,
  630. 'issue' => $issue,
  631. 'pages' => $pages,
  632. 'miniref' => substr($miniref, 0, 255),
  633. 'publisher' => substr($publisher, 0, 255),
  634. 'pubplace' => substr($pubplace, 0, 255),
  635. );
  636. $pub = chado_insert_record('pub', $values);
  637. if (!$pub) {
  638. drupal_set_message("Error inserting publication", "error");
  639. watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
  640. return;
  641. }
  642. $pub_id = $pub['pub_id'];
  643. // now add in the properties
  644. // Only adds in those not used in the pub record
  645. $details = array(
  646. 'property_table' => 'pubprop',
  647. 'base_table' => 'pub',
  648. 'foreignkey_name' => 'pub_id',
  649. 'foreignkey_value' => $pub_id
  650. );
  651. chado_update_node_form_properties($node, $details, $properties);
  652. // * Relationships Form *
  653. $details = array(
  654. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  655. 'foreignkey_value' => $pub_id // value of the pub_id key
  656. );
  657. chado_update_node_form_relationships($node, $details);
  658. // add in any database cross-references
  659. foreach ($cross_refs as $index => $ref) {
  660. $dbxref = array();
  661. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  662. $dbxref['db_name'] = $matches[1];
  663. $dbxref['accession'] = $matches[2];
  664. }
  665. $success = chado_associate_dbxref('pub', $pub['pub_id'], $dbxref);
  666. if (!$success) {
  667. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  668. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  669. array('%ref' => $ref), WATCHDOG_ERROR);
  670. }
  671. }
  672. // * Additional DBxrefs Form *
  673. $details = array(
  674. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  675. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  676. 'foreignkey_value' => $pub_id // the value of the pub_id key
  677. );
  678. chado_update_node_form_dbxrefs($node, $details);
  679. }
  680. else {
  681. $pub_id = $node->pub_id;
  682. }
  683. // Make sure the entry for this pub doesn't already exist in the
  684. // chado_pub table if it doesn't exist then we want to add it.
  685. $check_org_id = chado_get_id_from_nid('pub', $node->nid);
  686. if (!$check_org_id) {
  687. $record = new stdClass();
  688. $record->nid = $node->nid;
  689. $record->vid = $node->vid;
  690. $record->pub_id = $pub_id;
  691. drupal_write_record('chado_pub', $record);
  692. }
  693. }
  694. /**
  695. * Implements hook_update().
  696. *
  697. * The purpose of the function is to allow the module to take action when an edited node is being
  698. * updated. It updates any name changes to the database tables that werec reated upon registering a Publication.
  699. * As well, the database will be changed, so the user changed information will be saved to the database.
  700. *
  701. * @param $node
  702. * The node being updated
  703. *
  704. * @ingroup tripal_pub
  705. */
  706. function chado_pub_update($node) {
  707. $title = trim($node->pubtitle);
  708. $pyear = trim($node->pyear);
  709. $uniquename = trim($node->uniquename);
  710. $is_obsolete = $node->is_obsolete;
  711. $type_id = $node->type_id;
  712. // we need an array suitable for the tripal_pub_create_citation() function
  713. // to automatically generate a citation if a uniquename doesn't already exist
  714. $pub_arr = array();
  715. // get the publication ID for this publication
  716. $pub_id = chado_get_id_from_nid('pub', $node->nid) ;
  717. $properties = array(); // stores all of the properties we need to add
  718. $cross_refs = array(); // stores any cross references for this publication
  719. // get the properties from the form
  720. $properties = chado_retrieve_node_form_properties($node);
  721. // get the list of properties for easy lookup (without doing lots of database queries
  722. $properties_list = array();
  723. $sql = "
  724. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  725. FROM {cvtermpath} CVTP
  726. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  727. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  728. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  729. WHERE CV.name = 'tripal_pub' and
  730. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  731. NOT CVTS.is_obsolete = 1
  732. ORDER BY CVTS.name ASC
  733. ";
  734. $prop_types = chado_query($sql);
  735. while ($prop = $prop_types->fetchObject()) {
  736. $properties_list[$prop->cvterm_id] = $prop->name;
  737. // The 'Citation' term is special because it serves
  738. // both as a property and as the uniquename for the
  739. // pub and we want it stored in both the pub table and the pubprop table
  740. if ($prop->name == 'Citation') {
  741. $citation_id = $prop->cvterm_id;
  742. if (!empty($node->uniquename)) {
  743. $properties[$citation_id][0] = $node->uniquename;
  744. }
  745. }
  746. }
  747. // iterate through all of the properties and remove those that really are
  748. // part of the pub table fields
  749. $volume = '';
  750. $volumetitle = '';
  751. $issue = '';
  752. $pages = '';
  753. $publisher = '';
  754. $series_name = '';
  755. $pubplace = '';
  756. $miniref = '';
  757. $cross_refs = array();
  758. foreach ($properties as $type_id => $element) {
  759. foreach ($element as $index => $value) {
  760. $name = $properties_list[$type_id];
  761. // populate our $pub_array for building a citation
  762. $pub_arr[$name] = $value;
  763. // remove properties that are stored in the pub table
  764. if ($name == "Volume") {
  765. $volume = $value;
  766. unset($properties[$type_id]);
  767. }
  768. elseif ($name == "Volume Title") {
  769. $volumetitle = $value;
  770. unset($properties[$type_id]);
  771. }
  772. elseif ($name == "Issue") {
  773. $issue = $value;
  774. unset($properties[$type_id]);
  775. }
  776. elseif ($name == "Pages") {
  777. $pages = $value;
  778. unset($properties[$type_id]);
  779. }
  780. elseif ($name == "Publisher") {
  781. $publisher = $value;
  782. unset($properties[$type_id]);
  783. }
  784. elseif ($name == "Journal Name" or $name == "Conference Name") {
  785. $series_name = $value;
  786. unset($properties[$type_id]);
  787. }
  788. elseif ($name == "Journal Country" or $name == "Published Location") {
  789. $pubplace = $value;
  790. // allow this property to go into the pubprop table so we don't loose info
  791. // so don't unset it. But it will also go into the pub.pubplace field
  792. }
  793. elseif ($name == "Publication Dbxref") {
  794. // we will add the cross-references to the pub_dbxref table
  795. // but we also want to keep the property in the pubprop table so don't unset it
  796. $cross_refs[] = $value;
  797. }
  798. }
  799. }
  800. // generate a citation for this pub if one doesn't already exist
  801. if (!$node->uniquename) {
  802. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  803. $pub_arr['Title'] = $node->pubtitle;
  804. $pub_arr['Publication Type'][0] = $pub_type->name;
  805. $pub_arr['Year'] = $node->pyear;
  806. $node->uniquename = tripal_pub_create_citation($pub_arr);
  807. $properties[$citation_id][0] = $node->uniquename;
  808. }
  809. // update the pub record
  810. $match = array(
  811. 'pub_id' => $pub_id,
  812. );
  813. $values = array(
  814. 'title' => $node->pubtitle,
  815. 'type_id' => $node->type_id,
  816. 'pyear' => $node->pyear,
  817. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  818. 'uniquename' => $node->uniquename,
  819. 'series_name' => substr($series_name, 0, 255),
  820. 'volumetitle' => $volumetitle,
  821. 'volume' => $volume,
  822. 'issue' => $issue,
  823. 'pages' => $pages,
  824. 'miniref' => substr($miniref, 0, 255),
  825. 'publisher' => substr($publisher, 0, 255),
  826. 'pubplace' => substr($pubplace, 0, 255),
  827. );
  828. $status = chado_update_record('pub', $match, $values);
  829. if (!$status) {
  830. drupal_set_message("Error updating publication", "error");
  831. watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
  832. return;
  833. }
  834. // now add in the properties by first removing any the publication
  835. // already has and adding the ones we have
  836. $details = array(
  837. 'property_table' => 'pubprop',
  838. 'base_table' => 'pub',
  839. 'foreignkey_name' => 'pub_id',
  840. 'foreignkey_value'=> $pub_id
  841. );
  842. chado_update_node_form_properties($node, $details, $properties);
  843. // * Relationships Form *
  844. $details = array(
  845. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  846. 'foreignkey_value' => $pub_id // value of the pub_id key
  847. );
  848. chado_update_node_form_relationships($node, $details);
  849. // add in any database cross-references after first removing
  850. chado_delete_record('pub_dbxref', array('pub_id' => $pub_id));
  851. foreach ($cross_refs as $index => $ref) {
  852. $dbxref = array();
  853. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  854. $dbxref['db_name'] = $matches[1];
  855. $dbxref['accession'] = $matches[2];
  856. }
  857. $success = chado_associate_dbxref('pub', $pub_id, $dbxref);
  858. if (!$success) {
  859. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  860. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  861. array('%ref' => $ref), WATCHDOG_ERROR);
  862. }
  863. }
  864. // * Additional DBxrefs Form *
  865. $details = array(
  866. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  867. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  868. 'foreignkey_value' => $pub_id // the value of the pub_id key
  869. );
  870. chado_update_node_form_dbxrefs($node, $details);
  871. }
  872. /**
  873. * Implements hook_load().
  874. *
  875. * @param $node
  876. * The node that is to be loaded
  877. *
  878. * @return $node
  879. * The node with the information to be loaded into the database
  880. *
  881. * @ingroup tripal_pub
  882. */
  883. function chado_pub_load($nodes) {
  884. foreach ($nodes as $nid => $node) {
  885. // find the pub and add in the details
  886. $pub_id = chado_get_id_from_nid('pub', $nid);
  887. // get the pub
  888. $values = array('pub_id' => $pub_id);
  889. $pub = chado_generate_var('pub', $values);
  890. // expand the 'text' fields as those aren't included by default
  891. // and they really shouldn't be so large to cause problems
  892. $pub = chado_expand_var($pub, 'field', 'pub.title');
  893. $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
  894. $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
  895. // set the URL path
  896. $nodes[$nid]->path = "pub/$pub_id";
  897. $nodes[$nid]->pub = $pub;
  898. }
  899. }
  900. /**
  901. * Implements hook_delete().
  902. *
  903. * This function takes a node and if the delete button has been chosen by the user, the publication
  904. * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
  905. * the 'chado_pub' table.
  906. *
  907. * @parm $node
  908. * Then node to be deleted
  909. *
  910. * @ingroup tripal_pub
  911. */
  912. function chado_pub_delete(&$node) {
  913. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  914. // if we don't have a pub id for this node then this isn't a node of
  915. // type chado_pub or the entry in the chado_pub table was lost.
  916. if (!$pub_id) {
  917. return;
  918. }
  919. // Remove data from {chado_pub}, {node} and {node_revision} tables of
  920. // drupal database
  921. $sql_del = "DELETE FROM {chado_pub} WHERE nid = :nid AND vid = :vid";
  922. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  923. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  924. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  925. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  926. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  927. // Remove data from pub and pubprop tables of chado database as well
  928. chado_query("DELETE FROM {pubprop} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  929. chado_query("DELETE FROM {pub} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  930. }
  931. /**
  932. * Implements hook_node_view(). Acts on all content types.
  933. *
  934. * @ingroup tripal_pub
  935. */
  936. function tripal_pub_node_view($node, $view_mode, $langcode) {
  937. switch ($node->type) {
  938. case 'chado_pub':
  939. // Show feature browser and counts
  940. if ($view_mode == 'full') {
  941. $node->content['tripal_pub_authors'] = array(
  942. '#markup' => theme('tripal_pub_authors', array('node' => $node)),
  943. '#tripal_toc_id' => 'authors',
  944. '#tripal_toc_title' => 'Author Details',
  945. );
  946. $node->content['tripal_pub_base'] = array(
  947. '#markup' => theme('tripal_pub_base', array('node' => $node)),
  948. '#tripal_toc_id' => 'base',
  949. '#tripal_toc_title' => 'Overview',
  950. '#weight' => -100,
  951. );
  952. $node->content['tripal_pub_featuremaps'] = array(
  953. '#markup' => theme('tripal_pub_featuremaps', array('node' => $node)),
  954. '#tripal_toc_id' => 'featuremaps',
  955. '#tripal_toc_title' => 'Maps',
  956. );
  957. $node->content['tripal_pub_features'] = array(
  958. '#markup' => theme('tripal_pub_features', array('node' => $node)),
  959. '#tripal_toc_id' => 'features',
  960. '#tripal_toc_title' => 'Features',
  961. );
  962. $node->content['tripal_pub_libraries'] = array(
  963. '#markup' => theme('tripal_pub_libraries', array('node' => $node)),
  964. '#tripal_toc_id' => 'libraries',
  965. '#tripal_toc_title' => 'Libraries',
  966. );
  967. $node->content['tripal_pub_projects'] = array(
  968. '#markup' => theme('tripal_pub_projects', array('node' => $node)),
  969. '#tripal_toc_id' => 'projects',
  970. '#tripal_toc_title' => 'Projects',
  971. );
  972. $node->content['tripal_pub_properties'] = array(
  973. '#markup' => theme('tripal_pub_properties', array('node' => $node)),
  974. '#tripal_toc_id' => 'properties',
  975. '#tripal_toc_title' => 'Properties',
  976. );
  977. $node->content['tripal_pub_references'] = array(
  978. '#markup' => theme('tripal_pub_references', array('node' => $node)),
  979. '#tripal_toc_id' => 'references',
  980. '#tripal_toc_title' => 'Cross References',
  981. );
  982. $node->content['tripal_pub_relationships'] = array(
  983. '#markup' => theme('tripal_pub_relationships', array('node' => $node)),
  984. '#tripal_toc_id' => 'relationships',
  985. '#tripal_toc_title' => 'Relationships',
  986. );
  987. $node->content['tripal_pub_stocks'] = array(
  988. '#markup' => theme('tripal_pub_stocks', array('node' => $node)),
  989. '#tripal_toc_id' => 'stocks',
  990. '#tripal_toc_title' => 'Stocks',
  991. );
  992. }
  993. if ($view_mode == 'teaser') {
  994. $node->content['tripal_pub_teaser'] = array(
  995. '#markup' => theme('tripal_pub_teaser', array('node' => $node)),
  996. );
  997. }
  998. break;
  999. }
  1000. }
  1001. /**
  1002. * Implements hook_node_insert(). Acts on all content types.
  1003. *
  1004. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1005. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1006. * into the publication without needing to know the node. Of course if you know the
  1007. * node that will still work too (e.g. http://[base url]/node/[node id]
  1008. * so the nodeapi function ensures that the URL path is set after insert or update
  1009. * of the node and when the node is loaded if it hasn't yet been set.
  1010. *
  1011. * @ingroup tripal_pub
  1012. */
  1013. function tripal_pub_node_insert($node) {
  1014. if ($node->type == 'chado_pub') {
  1015. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1016. tripal_pub_set_pub_url($node, $pub_id);
  1017. }
  1018. }
  1019. /**
  1020. * Implements hook_node_load(). Acts on all content types.
  1021. *
  1022. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1023. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1024. * into the publication without needing to know the node. Of course if you know the
  1025. * node that will still work too (e.g. http://[base url]/node/[node id]
  1026. * so the nodeapi function ensures that the URL path is set after insert or update
  1027. * of the node and when the node is loaded if it hasn't yet been set.
  1028. *
  1029. * @ingroup tripal_pub
  1030. */
  1031. function tripal_pub_node_load($nodes, $types) {
  1032. if (count(array_intersect(array('chado_pub'), $types))) {
  1033. foreach ($nodes as $nid => $node) {
  1034. if ($node->type == 'chado_pub' and !property_exists($node, 'path')) {
  1035. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1036. $path = tripal_pub_set_pub_url($node, $pub_id);
  1037. }
  1038. }
  1039. }
  1040. }
  1041. /**
  1042. * Implements hook_node_update(). Acts on all content types.
  1043. *
  1044. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1045. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1046. * into the publication without needing to know the node. Of course if you know the
  1047. * node that will still work too (e.g. http://[base url]/node/[node id]
  1048. * so the nodeapi function ensures that the URL path is set after insert or update
  1049. * of the node and when the node is loaded if it hasn't yet been set.
  1050. *
  1051. * @ingroup tripal_pub
  1052. */
  1053. function tripal_pub_node_update($node) {
  1054. if ($node->type == 'chado_pub') {
  1055. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1056. tripal_pub_set_pub_url($node, $pub_id);
  1057. }
  1058. }