tripal_pub.chado_node.inc 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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. $form['pubtitle'] = array(
  144. '#type' => 'textarea',
  145. '#title' => t('Publication Title'),
  146. '#default_value' => $title,
  147. '#required' => TRUE,
  148. );
  149. $type_cv = tripal_get_default_cv('pub', 'type_id');
  150. if ($type_cv->name == 'tripal_pub') {
  151. // get the list of publication types. In the Tripal publication
  152. // ontologies these are all grouped under the term 'Publication Type'
  153. // we want the default to be 'Journal Article'
  154. $sql = "
  155. SELECT
  156. CVTS.cvterm_id, CVTS.name
  157. FROM {cvtermpath} CVTP
  158. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  159. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  160. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  161. WHERE
  162. CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  163. NOT CVTS.is_obsolete = 1
  164. ORDER BY CVTS.name ASC
  165. ";
  166. $results = chado_query($sql);
  167. $pub_types = array();
  168. while ($pub_type = $results->fetchObject()) {
  169. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  170. // if we don't have a default type then set the default to be 'Journal Article'
  171. if (strcmp($pub_type->name,"Journal Article") == 0 and !$type_id) {
  172. $type_id = $pub_type->cvterm_id;
  173. }
  174. }
  175. }
  176. else {
  177. $pub_types = tripal_get_cvterm_default_select_options('pub', 'type_id', 'publication types');
  178. $pub_types[0] = 'Select a Type';
  179. }
  180. $form['type_id'] = array(
  181. '#type' => 'select',
  182. '#title' => t('Publication Type'),
  183. '#options' => $pub_types,
  184. '#required' => TRUE,
  185. '#default_value' => $type_id,
  186. );
  187. $form['pyear'] = array(
  188. '#type' => 'textfield',
  189. '#title' => t('Publication Year'),
  190. '#default_value' => $pyear,
  191. '#required' => TRUE,
  192. '#size' => 5,
  193. '#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.'),
  194. );
  195. $form['uniquename'] = array(
  196. '#type' => 'textarea',
  197. '#title' => t('Citation'),
  198. '#default_value' => $uniquename,
  199. '#description' => t('All publications must have a unique citation.
  200. <b>Please enter the full citation for this publication or leave blank and one will be generated
  201. automatically if possible</b>. For PubMed style citations list
  202. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  203. 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.
  204. 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
  205. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
  206. );
  207. $form['is_obsolete'] = array(
  208. '#type' => 'checkbox',
  209. '#title' => t('Is Obsolete? (Check for Yes)'),
  210. '#default_value' => $is_obsolete,
  211. );
  212. // Properties Form
  213. // ----------------------------------
  214. $select_options = array();
  215. $prop_cv = tripal_get_default_cv('pubprop', 'type_id');
  216. $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  217. // if the poperty cv is 'tripal_pub' then we need to pass in our own select_options
  218. // for only a subset of the vocabulary
  219. if ($prop_cv->name == 'tripal_pub') {
  220. $select_options[] = 'Select a Property';
  221. $sql = "
  222. SELECT
  223. DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  224. FROM {cvtermpath} CVTP
  225. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  226. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  227. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  228. WHERE CV.name = 'tripal_pub' and
  229. (CVTO.name = 'Publication Details' OR CVTS.name = 'Publication Type') AND
  230. NOT CVTS.is_obsolete = 1
  231. ORDER BY CVTS.name ASC
  232. ";
  233. $prop_types = chado_query($sql);
  234. while ($prop = $prop_types->fetchObject()) {
  235. // add all properties except the Citation. That property is set via the uniquename field
  236. if ($prop->name == 'Citation') {
  237. continue;
  238. }
  239. // Publication Dbxref's are handled by the dbxref form addition below
  240. if ($prop->name == 'Publication Dbxref') {
  241. continue;
  242. }
  243. $select_options[$prop->cvterm_id] = $prop->name;
  244. }
  245. }
  246. $details = array(
  247. 'property_table' => 'pubprop',
  248. 'chado_id' => $pub_id,
  249. 'cv_id' => $cv_id,
  250. 'select_options' => $select_options,
  251. 'default_properties' => $more_props,
  252. );
  253. chado_add_node_form_properties($form, $form_state, $details);
  254. // RELATIONSHIPS FORM
  255. //---------------------------------------------
  256. $relationship_cv = tripal_get_default_cv('pub_relationship', 'type_id');
  257. $cv_id = $relationship_cv ? $relationship_cv->cv_id : NULL;
  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_id' => $cv_id, // the cv.cv_id 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. // if this is a delete then don't validate
  288. if($node->op == 'Delete') {
  289. return;
  290. }
  291. // we are syncing if we do not have a node ID but we do have a pub_id. We don't
  292. // need to validate during syncing so just skip it.
  293. if (is_null($node->nid) and property_exists($node, 'pub_id') and $node->pub_id != 0) {
  294. return;
  295. }
  296. // get the submitted values
  297. $title = trim($node->pubtitle);
  298. $pyear = trim($node->pyear);
  299. $uniquename = trim($node->uniquename);
  300. $is_obsolete = $node->is_obsolete;
  301. $type_id = $node->type_id;
  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. $cvterm = chado_select_record('cvterm', array('name'), $values);
  311. if (count($cvterm) == 0) {
  312. $message = t('Invalid publication type.');
  313. form_set_error('type_id', $message);
  314. return;
  315. }
  316. // get the media name looking at the properties
  317. $series_name = '';
  318. $properties = chado_retrieve_node_form_properties($node);
  319. foreach ($properties as $key => $prop_values) {
  320. $values = array('cvterm_id' => $key);
  321. $prop_type = chado_select_record('cvterm', array('name'), $values);
  322. if ($prop_type[0]->name == 'Conference Name' or
  323. $prop_type[0]->name == 'Journal Name' or
  324. $prop_type[0]->name == 'Series Name') {
  325. $series_name = $prop_values[0];
  326. }
  327. if ($prop_type[0]->name == 'Citation') {
  328. $uniquename = $prop_values[0];
  329. }
  330. if (count($prop_values) == 1) {
  331. $pub[$prop_type[0]->name] = $prop_values[0];
  332. }
  333. else {
  334. $pub[$prop_type[0]->name] = $prop_values;
  335. }
  336. }
  337. // if the citation is missing then try to generate one
  338. if (!$uniquename) {
  339. $pub['Title'] = $title;
  340. $pub['Publication Type'][0] = $cvterm[0]->name;
  341. $pub['Year'] = $pyear;
  342. $uniquename = tripal_pub_create_citation($pub);
  343. if (!$uniquename) {
  344. form_set_error('uniquename', "Cannot automatically generate a citation for this publication type. Please add one manually.");
  345. }
  346. }
  347. $skip_duplicate_check = 0;
  348. // if this publication is a Patent then skip the validation below. Patents can have the title
  349. // name and year but be different
  350. if (strcmp($cvterm[0]->name,'Patent') == 0) {
  351. $skip_duplicate_check = 1;
  352. }
  353. // Validating for an update
  354. if (!is_null($node->nid)) {
  355. $pub_id = $node->pub_id;
  356. // check to see if a duplicate publication already exists
  357. if (!$skip_duplicate_check) {
  358. chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm[0], $pub_id);
  359. }
  360. chado_pub_validate_check_uniquename($uniquename, $pub_id);
  361. }
  362. // Validating for an insert
  363. else {
  364. chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm[0]);
  365. chado_pub_validate_check_uniquename($uniquename);
  366. }
  367. }
  368. /**
  369. * Validate the publication uniquename. To be called from hook_validate().
  370. *
  371. * @param $uniquename
  372. * The uniquename of the publication
  373. * @param $pub_id
  374. * If an update, provide the pub_id so we don't check for a matching
  375. * uniquename of the pub we are editing
  376. *
  377. * @ingroup tripal_pub
  378. */
  379. function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
  380. // check to see if a pub exists with this uniquename
  381. $pub = chado_get_publication(array('uniquename' => $uniquename));
  382. if ($pub) {
  383. // if a $pub_id is provided to the function then this is an update
  384. // if the pub_id's don't match then a different pub with the same
  385. // uniquename already exists.
  386. if ($pub->pub_id != $pub_id) {
  387. $message = t('A publication with this unique citation already exists.');
  388. form_set_error('uniquename', $message);
  389. }
  390. }
  391. }
  392. /**
  393. * Check for duplicate publications. To be called from hook_validate(). Sets
  394. * the form error if a duplicate
  395. *
  396. * @param $title
  397. * The title of the publication
  398. * @param $pyear
  399. * The year the publication was published
  400. * @param $series_name
  401. * The series name of the publication
  402. * @param $cvterm
  403. * The type of publication
  404. * @param $pub_id
  405. * the unique id of the publication
  406. *
  407. *
  408. * @ingroup tripal_pub
  409. */
  410. function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
  411. $pub_details = array(
  412. 'Title' => $title,
  413. 'Year' => $pyear,
  414. 'Series Name' => $series_name,
  415. 'Publication Type' => $cvterm->name,
  416. );
  417. // TODO: need to include the Publication Dbxref in the $pub_details as well
  418. $pub_ids = tripal_publication_exists($pub_details);
  419. // if we found only one publication and it is our publication then return, we're good.
  420. if (count($pub_ids) == 1 and in_array($pub_id, $pub_ids)) {
  421. return;
  422. }
  423. if (count($pub_ids) == 0) {
  424. // there is no match so return
  425. return;
  426. }
  427. // return an appropriate message based on the unique constraint settings
  428. $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
  429. switch ($import_dups_check) {
  430. case 'title_year':
  431. $message = t('A publication with this title and publication year already exists.');
  432. form_set_error('pubtitle', $message);
  433. break;
  434. case 'title_year_type':
  435. $message = t('A publication with this title, type and publication year already exists.');
  436. form_set_error('pubtitle', $message);
  437. break;
  438. case 'title_year_media':
  439. $message = t('A publication with this title, media name (e.g. Journal Name) and publication year already exists.');
  440. form_set_error('pubtitle', $message);
  441. break;
  442. }
  443. }
  444. /**
  445. * Implement hook_node_access().
  446. *
  447. * This hook allows node modules to limit access to the node types they define.
  448. *
  449. * @param $node
  450. * The node on which the operation is to be performed, or, if it does not yet exist, the
  451. * type of node to be created
  452. *
  453. * @param $op
  454. * The operation to be performed
  455. *
  456. * @param $account
  457. * A user object representing the user for whom the operation is to be performed
  458. *
  459. * @return
  460. * If the permission for the specified operation is not set then return FALSE. If the
  461. * permission is set then return NULL as this allows other modules to disable
  462. * access. The only exception is when the $op == 'create'. We will always
  463. * return TRUE if the permission is set.
  464. *
  465. * @ingroup tripal_pub
  466. */
  467. function chado_pub_node_access($node, $op, $account) {
  468. $node_type = $node;
  469. if (is_object($node)) {
  470. $node_type = $node->type;
  471. }
  472. if($node_type == 'chado_pub') {
  473. if ($op == 'create') {
  474. if (!user_access('create chado_pub', $account)) {
  475. return NODE_ACCESS_DENY;
  476. }
  477. return NODE_ACCESS_ALLOW;
  478. }
  479. if ($op == 'update') {
  480. if (!user_access('edit chado_pub', $account)) {
  481. return NODE_ACCESS_DENY;
  482. }
  483. }
  484. if ($op == 'delete') {
  485. if (!user_access('delete chado_pub', $account)) {
  486. return NODE_ACCESS_DENY;
  487. }
  488. }
  489. if ($op == 'view') {
  490. if (!user_access('access chado_pub', $account)) {
  491. return NODE_ACCESS_DENY;
  492. }
  493. }
  494. return NODE_ACCESS_IGNORE;
  495. }
  496. }
  497. /**
  498. * Implements hook_insert().
  499. *
  500. * @ingroup tripal_pub
  501. */
  502. function chado_pub_insert($node) {
  503. $node->pubtitle = trim($node->pubtitle);
  504. $node->pyear = trim($node->pyear);
  505. $node->uniquename = trim($node->uniquename);
  506. $is_obsolete = $node->is_obsolete;
  507. $type_id = $node->type_id;
  508. // we need an array suitable for the tripal_pub_create_citation() function
  509. // to automatically generate a citation if a uniquename doesn't already exist
  510. $pub_arr = array();
  511. // if there is an pub_id in the $node object then this must be a sync so
  512. // we can skip adding the pub as it is already there, although
  513. // we do need to proceed with the rest of the insert
  514. if (!property_exists($node, 'pub_id')) {
  515. $properties = array(); // stores all of the properties we need to add
  516. $cross_refs = array(); // stores any cross references for this publication
  517. // get the properties from the form
  518. $properties = chado_retrieve_node_form_properties($node);
  519. // get the list of properties for easy lookup (without doing lots of database queries
  520. $properties_list = array();
  521. $sql = "
  522. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  523. FROM {cvtermpath} CVTP
  524. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  525. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  526. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  527. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  528. NOT CVTS.is_obsolete = 1
  529. ORDER BY CVTS.name ASC
  530. ";
  531. $prop_types = chado_query($sql);
  532. while ($prop = $prop_types->fetchObject()) {
  533. $properties_list[$prop->cvterm_id] = $prop->name;
  534. // The 'Citation' term is special because it serves
  535. // both as a property and as the uniquename for the
  536. // pub and we want it stored in both the pub table and the pubprop table
  537. if ($prop->name == 'Citation') {
  538. $citation_id = $prop->cvterm_id;
  539. if (!empty($node->uniquename)) {
  540. $properties[$citation_id] = $node->uniquename;
  541. }
  542. }
  543. }
  544. // iterate through all of the properties and remove those that really are
  545. // part of the pub table fields
  546. $volume = '';
  547. $volumetitle = '';
  548. $issue = '';
  549. $pages = '';
  550. $publisher = '';
  551. $series_name = '';
  552. $pubplace = '';
  553. $miniref = '';
  554. $cross_refs = array();
  555. foreach ($properties as $type_id => $element) {
  556. $value = trim($element[0]);
  557. $name = $properties_list[$type_id];
  558. // populate our $pub_array for building a citation
  559. $pub_arr[$name] = $value;
  560. // remove properties that are stored in the pub table
  561. if ($name == "Volume") {
  562. $volume = $value;
  563. unset($properties[$type_id]);
  564. }
  565. elseif ($name == "Volume Title") {
  566. $volumetitle = $value;
  567. unset($properties[$type_id]);
  568. }
  569. elseif ($name == "Issue") {
  570. $issue = $value;
  571. unset($properties[$type_id]);
  572. }
  573. elseif ($name == "Pages") {
  574. $pages = $value;
  575. unset($properties[$type_id]);
  576. }
  577. elseif ($name == "Publisher") {
  578. $publisher = $value;
  579. unset($properties[$type_id]);
  580. }
  581. elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
  582. $series_name = $value;
  583. unset($properties[$type_id]);
  584. }
  585. elseif ($name == "Journal Country" or $name == "Published Location") {
  586. $pubplace = $value;
  587. // allow this property to go into the pubprop table so we don't loose info
  588. // so don't unset it. But it will also go into the pub.pubplace field
  589. }
  590. elseif ($name == "Publication Dbxref") {
  591. // we will add the cross-references to the pub_dbxref table
  592. // but we also want to keep the property in the pubprop table so don't unset it
  593. $cross_refs[] = $value;
  594. }
  595. }
  596. // generate a citation for this pub if one doesn't already exist
  597. if (!$node->uniquename and !array_key_exists($citation_id, $properties)) {
  598. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  599. $pub_arr['Title'] = $node->pubtitle;
  600. $pub_arr['Publication Type'][0] = $pub_type->name;
  601. $pub_arr['Year'] = $node->pyear;
  602. $node->uniquename = tripal_pub_create_citation($pub_arr);
  603. $properties[$citation_id][0] = $node->uniquename;
  604. }
  605. // insert the pub record
  606. $values = array(
  607. 'title' => $node->pubtitle,
  608. 'series_name' => substr($series_name, 0, 255),
  609. 'type_id' => $node->type_id,
  610. 'pyear' => $node->pyear,
  611. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  612. 'uniquename' => $node->uniquename,
  613. 'volumetitle' => $volumetitle,
  614. 'volume' => $volume,
  615. 'issue' => $issue,
  616. 'pages' => $pages,
  617. 'miniref' => substr($miniref, 0, 255),
  618. 'publisher' => substr($publisher, 0, 255),
  619. 'pubplace' => substr($pubplace, 0, 255),
  620. );
  621. $pub = chado_insert_record('pub', $values);
  622. if (!$pub) {
  623. drupal_set_message("Error inserting publication", "error");
  624. watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
  625. return;
  626. }
  627. $pub_id = $pub['pub_id'];
  628. // now add in the properties
  629. // Only adds in those not used in the pub record
  630. $details = array(
  631. 'property_table' => 'pubprop',
  632. 'base_table' => 'pub',
  633. 'foreignkey_name' => 'pub_id',
  634. 'foreignkey_value' => $pub_id
  635. );
  636. chado_update_node_form_properties($node, $details, $properties);
  637. // * Relationships Form *
  638. $details = array(
  639. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  640. 'foreignkey_value' => $pub_id // value of the pub_id key
  641. );
  642. chado_update_node_form_relationships($node, $details);
  643. // add in any database cross-references
  644. foreach ($cross_refs as $index => $ref) {
  645. $dbxref = array();
  646. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  647. $dbxref['db_name'] = $matches[1];
  648. $dbxref['accession'] = $matches[2];
  649. }
  650. $success = chado_associate_dbxref('pub', $pub['pub_id'], $dbxref);
  651. if (!$success) {
  652. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  653. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  654. array('%ref' => $ref), WATCHDOG_ERROR);
  655. }
  656. }
  657. // * Additional DBxrefs Form *
  658. $details = array(
  659. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  660. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  661. 'foreignkey_value' => $pub_id // the value of the pub_id key
  662. );
  663. chado_update_node_form_dbxrefs($node, $details);
  664. }
  665. else {
  666. $pub_id = $node->pub_id;
  667. }
  668. // Make sure the entry for this pub doesn't already exist in the
  669. // chado_pub table if it doesn't exist then we want to add it.
  670. $check_org_id = chado_get_id_from_nid('pub', $node->nid);
  671. if (!$check_org_id) {
  672. $record = new stdClass();
  673. $record->nid = $node->nid;
  674. $record->vid = $node->vid;
  675. $record->pub_id = $pub_id;
  676. drupal_write_record('chado_pub', $record);
  677. }
  678. }
  679. /**
  680. * Implements hook_update().
  681. *
  682. * The purpose of the function is to allow the module to take action when an edited node is being
  683. * updated. It updates any name changes to the database tables that werec reated upon registering a Publication.
  684. * As well, the database will be changed, so the user changed information will be saved to the database.
  685. *
  686. * @param $node
  687. * The node being updated
  688. *
  689. * @ingroup tripal_pub
  690. */
  691. function chado_pub_update($node) {
  692. $node->pubtitle = trim($node->pubtitle);
  693. $node->pyear = trim($node->pyear);
  694. $node->uniquename = trim($node->uniquename);
  695. $is_obsolete = $node->is_obsolete;
  696. $type_id = $node->type_id;
  697. // we need an array suitable for the tripal_pub_create_citation() function
  698. // to automatically generate a citation if a uniquename doesn't already exist
  699. $pub_arr = array();
  700. // get the publication ID for this publication
  701. $pub_id = chado_get_id_from_nid('pub', $node->nid) ;
  702. $properties = array(); // stores all of the properties we need to add
  703. $cross_refs = array(); // stores any cross references for this publication
  704. // get the properties from the form
  705. $properties = chado_retrieve_node_form_properties($node);
  706. // get the list of properties for easy lookup (without doing lots of database queries
  707. $properties_list = array();
  708. $sql = "
  709. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  710. FROM {cvtermpath} CVTP
  711. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  712. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  713. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  714. WHERE CV.name = 'tripal_pub' and
  715. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  716. NOT CVTS.is_obsolete = 1
  717. ORDER BY CVTS.name ASC
  718. ";
  719. $prop_types = chado_query($sql);
  720. while ($prop = $prop_types->fetchObject()) {
  721. $properties_list[$prop->cvterm_id] = $prop->name;
  722. // The 'Citation' term is special because it serves
  723. // both as a property and as the uniquename for the
  724. // pub and we want it stored in both the pub table and the pubprop table
  725. if ($prop->name == 'Citation') {
  726. $citation_id = $prop->cvterm_id;
  727. if (!empty($node->uniquename)) {
  728. $properties[$citation_id][0] = $node->uniquename;
  729. }
  730. }
  731. }
  732. // iterate through all of the properties and remove those that really are
  733. // part of the pub table fields
  734. $volume = '';
  735. $volumetitle = '';
  736. $issue = '';
  737. $pages = '';
  738. $publisher = '';
  739. $series_name = '';
  740. $pubplace = '';
  741. $miniref = '';
  742. $cross_refs = array();
  743. foreach ($properties as $type_id => $element) {
  744. foreach ($element as $index => $value) {
  745. $name = $properties_list[$type_id];
  746. // populate our $pub_array for building a citation
  747. $pub_arr[$name] = $value;
  748. // remove properties that are stored in the pub table
  749. if ($name == "Volume") {
  750. $volume = $value;
  751. unset($properties[$type_id]);
  752. }
  753. elseif ($name == "Volume Title") {
  754. $volumetitle = $value;
  755. unset($properties[$type_id]);
  756. }
  757. elseif ($name == "Issue") {
  758. $issue = $value;
  759. unset($properties[$type_id]);
  760. }
  761. elseif ($name == "Pages") {
  762. $pages = $value;
  763. unset($properties[$type_id]);
  764. }
  765. elseif ($name == "Publisher") {
  766. $publisher = $value;
  767. unset($properties[$type_id]);
  768. }
  769. elseif ($name == "Journal Name" or $name == "Conference Name") {
  770. $series_name = $value;
  771. unset($properties[$type_id]);
  772. }
  773. elseif ($name == "Journal Country" or $name == "Published Location") {
  774. $pubplace = $value;
  775. // allow this property to go into the pubprop table so we don't loose info
  776. // so don't unset it. But it will also go into the pub.pubplace field
  777. }
  778. elseif ($name == "Publication Dbxref") {
  779. // we will add the cross-references to the pub_dbxref table
  780. // but we also want to keep the property in the pubprop table so don't unset it
  781. $cross_refs[] = $value;
  782. }
  783. }
  784. }
  785. // generate a citation for this pub if one doesn't already exist
  786. if (!$node->uniquename) {
  787. $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
  788. $pub_arr['Title'] = $node->pubtitle;
  789. $pub_arr['Publication Type'][0] = $pub_type->name;
  790. $pub_arr['Year'] = $node->pyear;
  791. $node->uniquename = tripal_pub_create_citation($pub_arr);
  792. $properties[$citation_id][0] = $node->uniquename;
  793. }
  794. // update the pub record
  795. $match = array(
  796. 'pub_id' => $pub_id,
  797. );
  798. $values = array(
  799. 'title' => $node->pubtitle,
  800. 'type_id' => $node->type_id,
  801. 'pyear' => $node->pyear,
  802. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  803. 'uniquename' => $node->uniquename,
  804. 'series_name' => substr($series_name, 0, 255),
  805. 'volumetitle' => $volumetitle,
  806. 'volume' => $volume,
  807. 'issue' => $issue,
  808. 'pages' => $pages,
  809. 'miniref' => substr($miniref, 0, 255),
  810. 'publisher' => substr($publisher, 0, 255),
  811. 'pubplace' => substr($pubplace, 0, 255),
  812. );
  813. $status = chado_update_record('pub', $match, $values);
  814. if (!$status) {
  815. drupal_set_message("Error updating publication", "error");
  816. watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
  817. return;
  818. }
  819. // now add in the properties by first removing any the publication
  820. // already has and adding the ones we have
  821. $details = array(
  822. 'property_table' => 'pubprop',
  823. 'base_table' => 'pub',
  824. 'foreignkey_name' => 'pub_id',
  825. 'foreignkey_value'=> $pub_id
  826. );
  827. chado_update_node_form_properties($node, $details, $properties);
  828. // * Relationships Form *
  829. $details = array(
  830. 'relationship_table' => 'pub_relationship', // name of the _relationship table
  831. 'foreignkey_value' => $pub_id // value of the pub_id key
  832. );
  833. chado_update_node_form_relationships($node, $details);
  834. // add in any database cross-references after first removing
  835. chado_delete_record('pub_dbxref', array('pub_id' => $pub_id));
  836. foreach ($cross_refs as $index => $ref) {
  837. $dbxref = array();
  838. if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
  839. $dbxref['db_name'] = $matches[1];
  840. $dbxref['accession'] = $matches[2];
  841. }
  842. $success = chado_associate_dbxref('pub', $pub_id, $dbxref);
  843. if (!$success) {
  844. drupal_set_message("Error cannot add publication cross reference: $ref", "error");
  845. watchdog('tripal_pub', "Error cannot add publication cross reference: %ref",
  846. array('%ref' => $ref), WATCHDOG_ERROR);
  847. }
  848. }
  849. // * Additional DBxrefs Form *
  850. $details = array(
  851. 'linking_table' => 'pub_dbxref', // the name of your _dbxref table
  852. 'foreignkey_name' => 'pub_id', // the name of the key in your base table
  853. 'foreignkey_value' => $pub_id // the value of the pub_id key
  854. );
  855. chado_update_node_form_dbxrefs($node, $details);
  856. }
  857. /**
  858. * Implements hook_load().
  859. *
  860. * @param $node
  861. * The node that is to be loaded
  862. *
  863. * @return $node
  864. * The node with the information to be loaded into the database
  865. *
  866. * @ingroup tripal_pub
  867. */
  868. function chado_pub_load($nodes) {
  869. foreach ($nodes as $nid => $node) {
  870. // find the pub and add in the details
  871. $pub_id = chado_get_id_from_nid('pub', $nid);
  872. // if the nid does not have a matching record then skip this node.
  873. // this can happen with orphaned nodes.
  874. if (!$pub_id) {
  875. continue;
  876. }
  877. // get the pub
  878. $values = array('pub_id' => $pub_id);
  879. $pub = chado_generate_var('pub', $values);
  880. // expand the 'text' fields as those aren't included by default
  881. // and they really shouldn't be so large to cause problems
  882. $pub = chado_expand_var($pub, 'field', 'pub.title');
  883. $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
  884. $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
  885. // set the URL path
  886. $nodes[$nid]->path = "pub/$pub_id";
  887. $nodes[$nid]->pub = $pub;
  888. // Now get the title
  889. $node->title = chado_get_node_title($node);
  890. }
  891. }
  892. /**
  893. * Implements hook_delete().
  894. *
  895. * This function takes a node and if the delete button has been chosen by the user, the publication
  896. * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
  897. * the 'chado_pub' table.
  898. *
  899. * @parm $node
  900. * Then node to be deleted
  901. *
  902. * @ingroup tripal_pub
  903. */
  904. function chado_pub_delete(&$node) {
  905. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  906. // if we don't have a pub id for this node then this isn't a node of
  907. // type chado_pub or the entry in the chado_pub table was lost.
  908. if (!$pub_id) {
  909. return;
  910. }
  911. // Remove data from {chado_pub}, {node} and {node_revision} tables of
  912. // drupal database
  913. $sql_del = "DELETE FROM {chado_pub} WHERE nid = :nid AND vid = :vid";
  914. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  915. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  916. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  917. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  918. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  919. // Remove data from pub and pubprop tables of chado database as well
  920. chado_query("DELETE FROM {pubprop} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  921. chado_query("DELETE FROM {pub} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
  922. }
  923. /**
  924. * Implements hook_node_view(). Acts on all content types.
  925. *
  926. * @ingroup tripal_pub
  927. */
  928. function tripal_pub_node_view($node, $view_mode, $langcode) {
  929. switch ($node->type) {
  930. case 'chado_pub':
  931. // Show feature browser and counts
  932. if ($view_mode == 'full') {
  933. $node->content['tripal_pub_authors'] = array(
  934. '#markup' => theme('tripal_pub_authors', array('node' => $node)),
  935. '#tripal_toc_id' => 'authors',
  936. '#tripal_toc_title' => 'Author Details',
  937. );
  938. $node->content['tripal_pub_base'] = array(
  939. '#markup' => theme('tripal_pub_base', array('node' => $node)),
  940. '#tripal_toc_id' => 'base',
  941. '#tripal_toc_title' => 'Overview',
  942. '#weight' => -100,
  943. );
  944. $node->content['tripal_pub_featuremaps'] = array(
  945. '#markup' => theme('tripal_pub_featuremaps', array('node' => $node)),
  946. '#tripal_toc_id' => 'featuremaps',
  947. '#tripal_toc_title' => 'Maps',
  948. );
  949. $node->content['tripal_pub_features'] = array(
  950. '#markup' => theme('tripal_pub_features', array('node' => $node)),
  951. '#tripal_toc_id' => 'features',
  952. '#tripal_toc_title' => 'Features',
  953. );
  954. $node->content['tripal_pub_libraries'] = array(
  955. '#markup' => theme('tripal_pub_libraries', array('node' => $node)),
  956. '#tripal_toc_id' => 'libraries',
  957. '#tripal_toc_title' => 'Libraries',
  958. );
  959. $node->content['tripal_pub_projects'] = array(
  960. '#markup' => theme('tripal_pub_projects', array('node' => $node)),
  961. '#tripal_toc_id' => 'projects',
  962. '#tripal_toc_title' => 'Projects',
  963. );
  964. $node->content['tripal_pub_properties'] = array(
  965. '#markup' => theme('tripal_pub_properties', array('node' => $node)),
  966. '#tripal_toc_id' => 'properties',
  967. '#tripal_toc_title' => 'Properties',
  968. );
  969. $node->content['tripal_pub_references'] = array(
  970. '#markup' => theme('tripal_pub_references', array('node' => $node)),
  971. '#tripal_toc_id' => 'references',
  972. '#tripal_toc_title' => 'Cross References',
  973. );
  974. $node->content['tripal_pub_relationships'] = array(
  975. '#markup' => theme('tripal_pub_relationships', array('node' => $node)),
  976. '#tripal_toc_id' => 'relationships',
  977. '#tripal_toc_title' => 'Relationships',
  978. );
  979. $node->content['tripal_pub_stocks'] = array(
  980. '#markup' => theme('tripal_pub_stocks', array('node' => $node)),
  981. '#tripal_toc_id' => 'stocks',
  982. '#tripal_toc_title' => 'Stocks',
  983. );
  984. }
  985. if ($view_mode == 'teaser') {
  986. $node->content['tripal_pub_teaser'] = array(
  987. '#markup' => theme('tripal_pub_teaser', array('node' => $node)),
  988. );
  989. }
  990. break;
  991. }
  992. }
  993. /**
  994. * Implements hook_node_insert(). Acts on all content types.
  995. *
  996. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  997. * where [pub id] is the Chado publication ID. This will allow for easy linking
  998. * into the publication without needing to know the node. Of course if you know the
  999. * node that will still work too (e.g. http://[base url]/node/[node id]
  1000. * so the nodeapi function ensures that the URL path is set after insert or update
  1001. * of the node and when the node is loaded if it hasn't yet been set.
  1002. *
  1003. * @ingroup tripal_pub
  1004. */
  1005. function tripal_pub_node_insert($node) {
  1006. if ($node->type == 'chado_pub') {
  1007. // Now get the title
  1008. $node->title = chado_get_node_title($node);
  1009. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1010. tripal_pub_set_pub_url($node, $pub_id);
  1011. }
  1012. }
  1013. /**
  1014. * Implements hook_node_load(). 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_load($nodes, $types) {
  1026. if (count(array_intersect(array('chado_pub'), $types))) {
  1027. foreach ($nodes as $nid => $node) {
  1028. if ($node->type == 'chado_pub' and !property_exists($node, 'path')) {
  1029. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1030. $path = tripal_pub_set_pub_url($node, $pub_id);
  1031. }
  1032. }
  1033. }
  1034. }
  1035. /**
  1036. * Implements hook_node_update(). Acts on all content types.
  1037. *
  1038. * We want the publications to always have a URL of http://[base url]/pub/[pub id]
  1039. * where [pub id] is the Chado publication ID. This will allow for easy linking
  1040. * into the publication without needing to know the node. Of course if you know the
  1041. * node that will still work too (e.g. http://[base url]/node/[node id]
  1042. * so the nodeapi function ensures that the URL path is set after insert or update
  1043. * of the node and when the node is loaded if it hasn't yet been set.
  1044. *
  1045. * @ingroup tripal_pub
  1046. */
  1047. function tripal_pub_node_update($node) {
  1048. if ($node->type == 'chado_pub') {
  1049. // Now get the title
  1050. $node->title = chado_get_node_title($node);
  1051. $pub_id = chado_get_id_from_nid('pub', $node->nid);
  1052. tripal_pub_set_pub_url($node, $pub_id);
  1053. }
  1054. }
  1055. /**
  1056. * Implements hook_node_presave(). Acts on all content types.
  1057. *
  1058. * @ingroup tripal_pub
  1059. */
  1060. function tripal_pub_node_presave($node) {
  1061. switch ($node->type) {
  1062. case 'chado_pub':
  1063. // when syncing the details are not present in the $node object
  1064. // as they are when submitted via the form. Therefore, if we do
  1065. // not see any field values from the form, we assume this fucntion
  1066. // is being called for syncing, so we must set the title accordingly
  1067. if (property_exists($node, 'title')) {
  1068. // do nothing, the title is set
  1069. }
  1070. else if (property_exists($node, 'pub')) {
  1071. // in Drupal a node title can only be 255 characters so we truncate
  1072. // it just in case
  1073. $node->title = substr($node->pub->title, 0, 255);
  1074. }
  1075. break;
  1076. }
  1077. }
  1078. /**
  1079. * Implements [content_type]_chado_node_default_title_format().
  1080. *
  1081. * Defines a default title format for the Chado Node API to set the titles on
  1082. * Chado pub nodes based on chado fields.
  1083. */
  1084. function chado_pub_chado_node_default_title_format() {
  1085. return '[pub.title]';
  1086. }