tripal_pub.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. require_once "api/tripal_pub.api.inc";
  3. require_once "includes/tripal_pub.admin.inc";
  4. require_once "includes/pub_sync.inc";
  5. require_once "includes/pub_form.inc";
  6. require_once "includes/pub_importers.inc";
  7. require_once "includes/pubmed.inc";
  8. require_once "includes/agricola.inc";
  9. /**
  10. * @file
  11. *
  12. * The Tripal Publication module allows you to search the PubMed databse for academic articles,
  13. * that relate to user specified tpoic\s. As well, it allows management of publications so that
  14. * a user can enter specified details regarding a desired publication. This allows all of the important
  15. * information that is unique to a Academic Publication to be stored for access.
  16. */
  17. /**
  18. *
  19. * @ingroup tripal_pub
  20. */
  21. function tripal_pub_init() {
  22. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_pub.js');
  23. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_pub.css');
  24. }
  25. /**
  26. * Implementation of hook_tripal_pub_node_info().
  27. *
  28. * This node_info, is a simple node that describes the functionallity of the module.
  29. *
  30. */
  31. function tripal_pub_node_info() {
  32. return array(
  33. 'chado_pub' => array(
  34. 'name' => t('Publication'),
  35. 'module' => 'chado_pub',
  36. 'description' => t('A publication from the Chado database'),
  37. 'title_label' => t('Article Title'),
  38. 'body_label' => t('Abstract'),
  39. 'has_title' => TRUE,
  40. 'has_body' => FALSE,
  41. ),
  42. );
  43. }
  44. /**
  45. * Tripal-Publication-Menu
  46. *
  47. * Implemets hook_menu(): Adds menu items for the tripal_pub module menu. This section
  48. * gives the outline for the main menu of the Tripal-Publication module
  49. *
  50. * @return
  51. * An array of menu items that is visible within the Drupal Menu, returned as soon
  52. * as the program is ran
  53. */
  54. function tripal_pub_menu() {
  55. $items = array();
  56. $items['admin/tripal/tripal_pub' ]= array(
  57. 'title' => 'Publications',
  58. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
  59. 'page callback' => 'theme',
  60. 'page arguments' => array('tripal_pub_admin'),
  61. 'access arguments' => array('administer tripal pubs'),
  62. 'type' => MENU_NORMAL_ITEM
  63. );
  64. $items['admin/tripal/tripal_pub/configuration'] = array(
  65. 'title' => 'Configuration',
  66. 'description' => 'Configure the Tripal publication module.',
  67. 'page callback' => 'drupal_get_form',
  68. 'page arguments' => array('tripal_pub_admin'),
  69. 'access arguments' => array('administer tripal pubs'),
  70. 'type' => MENU_NORMAL_ITEM,
  71. );
  72. $items['admin/tripal/tripal_pub/sync'] = array(
  73. 'title' => ' Sync Publications',
  74. 'description' => 'Sync publications in Chado with Drupal',
  75. 'page callback' => 'drupal_get_form',
  76. 'page arguments' => array('tripal_pub_sync_form'),
  77. 'access arguments' => array('administer tripal pubs'),
  78. 'type' => MENU_NORMAL_ITEM,
  79. );
  80. $items['admin/tripal/tripal_pub/import_list'] = array(
  81. 'title' => t('Importers List'),
  82. 'description' => t('List all publication importers'),
  83. 'page callback' => 'tripal_pub_importers_list',
  84. 'access arguments' => array('administer tripal pubs'),
  85. 'type ' => MENU_CALLBACK,
  86. );
  87. $items['admin/tripal/tripal_pub/import/new'] = array(
  88. 'title' => t('Add an Importer'),
  89. 'description' => t('Add a new publication importer.'),
  90. 'page callback' => 'tripal_pub_importer_setup',
  91. 'page arguments' => array(4, NULL),
  92. 'access arguments' => array('administer tripal pubs'),
  93. 'type ' => MENU_CALLBACK,
  94. );
  95. $items['admin/tripal/tripal_pub/import/edit/%'] = array(
  96. 'page callback' => 'tripal_pub_importer_setup',
  97. 'page arguments' => array(4, 5),
  98. 'access arguments' => array('administer tripal pubs'),
  99. 'type ' => MENU_CALLBACK,
  100. );
  101. $items['admin/tripal/tripal_pub/import/delete/%'] = array(
  102. 'page callback' => 'tripal_pub_importer_delete',
  103. 'page arguments' => array(5),
  104. 'access arguments' => array('administer tripal pubs'),
  105. 'type ' => MENU_CALLBACK,
  106. );
  107. $items['admin/tripal/tripal_pub/import/criteria/%/%'] = array(
  108. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  109. 'page arguments' => array(5, 6),
  110. 'access arguments' => array('administer tripal pubs'),
  111. 'type ' => MENU_CALLBACK,
  112. );
  113. $items['tripal_pub/properties/add'] = array(
  114. 'page callback' => 'tripal_pub_property_add',
  115. 'access arguments' => array('edit chado_pub content'),
  116. 'type ' => MENU_CALLBACK,
  117. );
  118. $items['tripal_pub/properties/description'] = array(
  119. 'page callback' => 'tripal_pub_property_get_description',
  120. 'access arguments' => array('edit chado_pub content'),
  121. 'type ' => MENU_CALLBACK,
  122. );
  123. $items['tripal_pub/properties/minus/%/%'] = array(
  124. 'page callback' => 'tripal_pub_property_delete',
  125. 'page arguments' => array(3, 4),
  126. 'access arguments' => array('edit chado_pub content'),
  127. 'type ' => MENU_CALLBACK,
  128. );
  129. return $items;
  130. }
  131. /**
  132. * Implements hook_theme(): Register themeing functions for this module
  133. *
  134. *
  135. * @return
  136. * An array of themeing functions to register
  137. *
  138. */
  139. function tripal_pub_theme() {
  140. return array(
  141. 'tripal_pub_base' => array(
  142. 'arguments' => array('node' => NULL),
  143. ),
  144. 'tripal_pub_properties' => array(
  145. 'arguments' => array('node' => NULL)
  146. ),
  147. 'tripal_pub_authors' => array(
  148. 'arguments' => array('node' => NULL)
  149. ),
  150. 'tripal_pub_references' => array(
  151. 'arguments' => array('node' => NULL)
  152. ),
  153. 'tripal_pub_relationships' => array(
  154. 'arguments' => array('node' => NULL)
  155. ),
  156. 'tripal_pub_importer_setup_form' => array(
  157. 'arguments' => array('form'),
  158. ),
  159. 'chado_pub_node_form' => array(
  160. 'arguments' => array('form'),
  161. ),
  162. 'tripal_pub_admin' => array(
  163. 'template' => 'tripal_pub_admin',
  164. 'arguments' => array(NULL),
  165. 'path' => drupal_get_path('module', 'tripal_pub') . '/theme'
  166. ),
  167. );
  168. }
  169. /**
  170. * Implement hook_perm().
  171. */
  172. function tripal_pub_perm() {
  173. return array(
  174. 'access chado_pub content',
  175. 'create chado_pub content',
  176. 'delete chado_pub content',
  177. 'edit chado_pub content',
  178. 'administer tripal pubs',
  179. );
  180. }
  181. /**
  182. * Implement hook_access().
  183. *
  184. * This hook allows node modules to limit access to the node types they define.
  185. *
  186. * @param $op
  187. * The operation to be performed
  188. *
  189. * @param $node
  190. * The node on which the operation is to be performed, or, if it does not yet exist, the
  191. * type of node to be created
  192. *
  193. * @param $account
  194. * A user object representing the user for whom the operation is to be performed
  195. *
  196. * @return
  197. * TRUE
  198. *
  199. */
  200. function chado_pub_access($op, $node, $account ) {
  201. if ($op == 'create') {
  202. if (!user_access('create chado_pub content', $account)) {
  203. return FALSE;
  204. }
  205. }
  206. if ($op == 'update') {
  207. if (!user_access('edit chado_pub content', $account)) {
  208. return FALSE;
  209. }
  210. }
  211. if ($op == 'delete') {
  212. if (!user_access('delete chado_pub content', $account)) {
  213. return FALSE;
  214. }
  215. }
  216. if ($op == 'view') {
  217. if (!user_access('access chado_pub content', $account)) {
  218. return FALSE;
  219. }
  220. }
  221. return NULL;
  222. }
  223. /**
  224. * Implementation of tripal_pub_insert().
  225. *
  226. * This function inserts user entered information pertaining to the Publication instance into the
  227. * 'pubauthor', 'pubprop', 'chado_pub', 'pub' talble of the database.
  228. *
  229. * @parm $node
  230. * Then node which contains the information stored within the node-ID
  231. *
  232. *
  233. */
  234. function chado_pub_insert($node) {
  235. // if a pub_id already exists for this node then it already exists in Chado and
  236. // we get here because we are syncing the node. Therefore, we can skip the insert
  237. if ($node->pub_id) {
  238. $pub['pub_id'] = $node->pub_id;
  239. }
  240. else {
  241. // get the list of properties for easy lookup (without doing lots of database queries
  242. $properties_list = array();
  243. $sql = "
  244. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  245. FROM {cvtermpath} CVTP
  246. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  247. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  248. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  249. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  250. NOT CVTS.is_obsolete = 1
  251. ORDER BY CVTS.name ASC
  252. ";
  253. $prop_types = chado_query($sql);
  254. $properties = array();
  255. while ($prop = db_fetch_object($prop_types)) {
  256. $properties_list[$prop->cvterm_id] = $prop->name;
  257. // The 'Citation' term is special because it serves
  258. // both as a property and as the uniquename for the
  259. // pub and we want it stored in both the pub table and the pubprop table
  260. if ($prop->name == 'Citation') {
  261. $properties[$prop->name][0] = $node->uniquename;
  262. }
  263. }
  264. // get the properties that should be added. Properties are in one of two forms:
  265. // 1) prop_value-[type id]-[index]
  266. // 2) new_value-[type id]-[index]
  267. // 3) new_id, new_value
  268. foreach ($node as $name => $value) {
  269. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  270. $type_id = $matches[1];
  271. $index = $matches[2];
  272. $name = $properties_list[$type_id];
  273. $properties[$name][$index] = $value;
  274. }
  275. }
  276. if ($node->new_id and $node->new_value) {
  277. $type_id = $node->new_id;
  278. $index = count($properties[$name]);
  279. $name = $properties_list[$type_id];
  280. $properties[$name][$index] = $node->new_value;
  281. }
  282. // iterate through all of the properties and remove those that really are
  283. // part of the pub table fields
  284. foreach ($properties as $name => $element) {
  285. $value = $element[0];
  286. if ($name == "Volume") {
  287. $volume = $value;
  288. unset($properties[$name]);
  289. }
  290. elseif ($name == "Volume Title") {
  291. $volumetitle = $value;
  292. unset($properties[$name]);
  293. }
  294. elseif ($name == "Issue") {
  295. $issue = $value;
  296. unset($properties[$name]);
  297. }
  298. elseif ($name == "Pages") {
  299. $pages = $value;
  300. unset($properties[$name]);
  301. }
  302. elseif ($name == "Publisher") {
  303. $publisher = $value;
  304. unset($properties[$name]);
  305. }
  306. elseif ($name == "Journal Country" or $name == "Published Location") {
  307. $pubplace = $value;
  308. unset($properties[$name]);
  309. }
  310. }
  311. // insert the pub record
  312. $values = array(
  313. 'title' => $node->title,
  314. 'series_name' => $node->series_name,
  315. 'type_id' => $node->type_id,
  316. 'pyear' => $node->pyear,
  317. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  318. 'uniquename' => $node->uniquename,
  319. 'volumetitle' => $volumetitle,
  320. 'volume' => $volume,
  321. 'issue' => $issue,
  322. 'pages' => $pages,
  323. 'miniref' => $miniref,
  324. 'publisher' => $publisher,
  325. 'pubplace' => $pubplace,
  326. );
  327. $pub = tripal_core_chado_insert('pub', $values);
  328. if (!$pub) {
  329. drupal_set_message("Error inserting publication", "error");
  330. watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
  331. return;
  332. }
  333. // now add in the properties
  334. foreach ($properties as $property => $elements) {
  335. foreach ($elements as $rank => $value) {
  336. $status = tripal_pub_insert_property($pub['pub_id'], $property, $value, FALSE);
  337. if (!$status) {
  338. drupal_set_message("Error cannot add property: $property", "error");
  339. watchdog('tripal_pub', "Error cannot add property: %prop",
  340. array('%property' => $property), WATCHDOG_ERROR);
  341. }
  342. }
  343. }
  344. } // if ($node->pub_id) {} else
  345. if ($pub) {
  346. // make sure the entry for this feature doesn't already exist in the chado_pub table
  347. // if it doesn't exist then we want to add it.
  348. $pub_id = chado_get_id_for_node('pub', $node) ;
  349. if (!$pub_id) {
  350. // next add the item to the drupal table
  351. $sql = "INSERT INTO {chado_pub} (nid, vid, pub_id) ".
  352. "VALUES (%d, %d, %d)";
  353. db_query($sql, $node->nid, $node->vid, $pub['pub_id']);
  354. }
  355. }
  356. else {
  357. drupal_set_message(t('Unable to add publication.', 'warning'));
  358. watchdog('tripal_pub', 'Insert publication: Unable to create pub where values: %values',
  359. array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
  360. }
  361. }
  362. /*
  363. *
  364. * Implements hook_update
  365. *
  366. * The purpose of the function is to allow the module to take action when an edited node is being
  367. * updated. It updates any name changes to the database tables that werec reated upon registering a Publication.
  368. * As well, the database will be changed, so the user changed information will be saved to the database.
  369. *
  370. * @param $node
  371. * The node being updated
  372. *
  373. * @ingroup tripal_pub
  374. */
  375. function chado_pub_update($node) {
  376. if ($node->revision) {
  377. // there is no way to handle revisions in Chado but leave
  378. // this here just to make not we've addressed it.
  379. }
  380. // get the publication ID for this publication
  381. $pub_id = chado_get_id_for_node('pub', $node) ;
  382. // get the list of properties for easy lookup (without doing lots of database queries
  383. $properties_list = array();
  384. $sql = "
  385. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  386. FROM {cvtermpath} CVTP
  387. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  388. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  389. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  390. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  391. NOT CVTS.is_obsolete = 1
  392. ORDER BY CVTS.name ASC
  393. ";
  394. $prop_types = chado_query($sql);
  395. $properties = array();
  396. while ($prop = db_fetch_object($prop_types)) {
  397. $properties_list[$prop->cvterm_id] = $prop->name;
  398. // The 'Citation' term is special because it serves
  399. // both as a property and as the uniquename for the
  400. // pub and we want it stored in both the pub table and the pubprop table
  401. if ($prop->name == 'Citation') {
  402. $properties[$prop->name][0] = $node->uniquename;
  403. }
  404. }
  405. // get the properties that should be added. Properties are in one of three forms:
  406. // 1) prop_value-[type id]-[index]
  407. // 2) new_value-[type id]-[index]
  408. // 3) new_id, new_value
  409. foreach ($node as $name => $value) {
  410. if (preg_match('/^prop_value-(\d+)-(\d+)/', $name, $matches)) {
  411. $type_id = $matches[1];
  412. $index = $matches[2];
  413. $name = $properties_list[$type_id];
  414. $properties[$name][$index] = $value;
  415. }
  416. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  417. $type_id = $matches[1];
  418. $index = $matches[2];
  419. $name = $properties_list[$type_id];
  420. $properties[$name][$index] = $value;
  421. }
  422. }
  423. if ($node->new_id and $node->new_value) {
  424. $type_id = $node->new_id;
  425. $index = count($properties[$name]);
  426. $name = $properties_list[$type_id];
  427. $properties[$name][$index] = $node->new_value;
  428. }
  429. // iterate through all of the properties and remove those that really are
  430. // part of the pub table fields
  431. foreach ($properties as $name => $element) {
  432. $value = $element[0];
  433. if ($name == "Volume") {
  434. $volume = $value;
  435. unset($properties[$name]);
  436. }
  437. elseif ($name == "Volume Title") {
  438. $volumetitle = $value;
  439. unset($properties[$name]);
  440. }
  441. elseif ($name == "Issue") {
  442. $issue = $value;
  443. unset($properties[$name]);
  444. }
  445. elseif ($name == "Pages") {
  446. $pages = $value;
  447. unset($properties[$name]);
  448. }
  449. elseif ($name == "Publisher") {
  450. $publisher = $value;
  451. unset($properties[$name]);
  452. }
  453. elseif ($name == "Journal Country" or $name == "Published Location") {
  454. $pubplace = $value;
  455. unset($properties[$name]);
  456. }
  457. }
  458. // update the pub record
  459. $match = array(
  460. 'pub_id' => $pub_id,
  461. );
  462. $values = array(
  463. 'title' => $node->title,
  464. 'series_name' => $node->series_name,
  465. 'type_id' => $node->type_id,
  466. 'pyear' => $node->pyear,
  467. 'is_obsolete' => $node->is_obsolete ? 'true' : 'false',
  468. 'uniquename' => $node->uniquename,
  469. 'volumetitle' => $volumetitle,
  470. 'volume' => $volume,
  471. 'issue' => $issue,
  472. 'pages' => $pages,
  473. 'miniref' => $miniref,
  474. 'publisher' => $publisher,
  475. 'pubplace' => $pubplace,
  476. );
  477. $status = tripal_core_chado_update('pub', $match, $values);
  478. if (!$status) {
  479. drupal_set_message("Error updating publication", "error");
  480. watchdog('tripal_pub', "Error updating publication", array(), WATCHDOG_ERROR);
  481. return;
  482. }
  483. // now add in the properties by first removing any the publication
  484. // already has and adding the ones we have
  485. tripal_core_chado_delete('pubprop', array('pub_id' => $pub_id));
  486. foreach ($properties as $property => $elements) {
  487. foreach ($elements as $rank => $value) {
  488. $status = tripal_pub_insert_property($pub_id, $property, $value, FALSE);
  489. if (!$status) {
  490. drupal_set_message("Error cannot add property: $property", "error");
  491. watchdog('tripal_pub', "Error cannot add property: %prop",
  492. array('%property' => $property), WATCHDOG_ERROR);
  493. }
  494. }
  495. }
  496. }
  497. /**
  498. * Implementation of tripal_pub_load().
  499. *
  500. *
  501. * @param $node
  502. * The node that is to be accessed from the database
  503. *
  504. * @return $node
  505. * The node with the information to be loaded into the database
  506. *
  507. */
  508. function chado_pub_load($node) {
  509. // get the feature details from chado
  510. $pub_id = chado_get_id_for_node('pub', $node);
  511. $values = array('pub_id' => $pub_id);
  512. $pub = tripal_core_generate_chado_var('pub', $values);
  513. // expand the 'text' fields as those aren't included by default
  514. // and they really shouldn't be so large to cause problems
  515. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
  516. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
  517. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');;
  518. $additions = new stdClass();
  519. $additions->pub = $pub;
  520. return $additions;
  521. }
  522. /**
  523. * Implementation of tripal_pub_delete().
  524. *
  525. * This function takes a node and if the delete button has been chosen by the user, the publication
  526. * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
  527. * the 'chado_pub' table.
  528. *
  529. * @parm $node
  530. * Then node which contains the information stored within the node-ID
  531. *
  532. */
  533. function chado_pub_delete(&$node) {
  534. $pub_id = chado_get_id_for_node('pub', $node);
  535. // if we don't have a pub id for this node then this isn't a node of
  536. // type chado_pub or the entry in the chado_pub table was lost.
  537. if (!$pub_id) {
  538. return;
  539. }
  540. // Remove data from {chado_pub}, {node} and {node_revisions} tables of
  541. // drupal database
  542. $sql_del = "DELETE FROM {chado_pub} ".
  543. "WHERE nid = %d ".
  544. "AND vid = %d";
  545. db_query($sql_del, $node->nid, $node->vid);
  546. $sql_del = "DELETE FROM {node_revisions} ".
  547. "WHERE nid = %d ".
  548. "AND vid = %d";
  549. db_query($sql_del, $node->nid, $node->vid);
  550. $sql_del = "DELETE FROM {node} ".
  551. "WHERE nid = %d ".
  552. "AND vid = %d";
  553. db_query($sql_del, $node->nid, $node->vid);
  554. // Remove data from pub and pubprop tables of chado database as well
  555. chado_query("DELETE FROM {pubprop} WHERE pub_id = %d", $pub_id);
  556. chado_query("DELETE FROM {pub} WHERE pub_id = %d", $pub_id);
  557. }
  558. /**
  559. * Because we are using AJAX with a node form we need to provide a callback
  560. * for the chado_pub node form. This callback is different from the
  561. * default 'chado_pub_form' callback
  562. */
  563. /*
  564. function tripal_pub_forms($form_id, $args) {
  565. $forms = array();
  566. if($form_id == 'chado_pub_node_form') {
  567. $forms[$form_id] = array(
  568. 'callback' => 'chado_pub_node_form',
  569. 'callback arguments' => array($args)
  570. );
  571. }
  572. return $forms;
  573. }*/
  574. /*
  575. *
  576. */
  577. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  578. if ($form_id == "tripal_pub_importer_setup_form") {
  579. // updating the form through the ahah callback sets the action of
  580. // the form to the ahah callback URL. We need to set it back
  581. // to the normal form URL
  582. if ($form_state['values']['action'] == 'edit') {
  583. $form['#action'] = url("admin/tripal/tripal_pub/import/edit/" . $form['pub_import_id']);
  584. }
  585. if ($form_state['values']['action'] == 'new') {
  586. $form['#action'] = url("admin/tripal/tripal_pub/import/new");
  587. }
  588. }
  589. if ($form_id == "chado_pub_node_form") {
  590. }
  591. }
  592. /**
  593. *
  594. *
  595. * @ingroup tripal_pub
  596. */
  597. function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
  598. // we want to provide a new variable that contains the matched pubs.
  599. $pub = $variables['node']->pub;
  600. // normally we would use tripal_core_expand_chado_vars to expand our
  601. // organism object and add in the relationships, however whan a large
  602. // number of relationships are present this significantly slows the
  603. // query, therefore we will manually perform the query
  604. $sql = "
  605. SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
  606. FROM pub_relationship PR
  607. INNER JOIN {pub} P ON PR.object_id = P.pub_id
  608. INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
  609. LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
  610. WHERE PR.subject_id = %d
  611. ";
  612. $as_subject = chado_query($sql, $pub->pub_id);
  613. $sql = "
  614. SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
  615. FROM pub_relationship PR
  616. INNER JOIN {pub} P ON PR.subject_id = P.pub_id
  617. INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
  618. LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
  619. WHERE PR.object_id = %d
  620. ";
  621. $as_object = chado_query($sql, $pub->pub_id);
  622. // combine both object and subject relationshisp into a single array
  623. $relationships = array();
  624. $relationships['object'] = array();
  625. $relationships['subject'] = array();
  626. // iterate through the object relationships
  627. while ($relationship = db_fetch_object($as_object)) {
  628. // get the relationship and child types
  629. $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
  630. $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
  631. if (!array_key_exists($rel_type, $relationships['object'])) {
  632. $relationships['object'][$rel_type] = array();
  633. }
  634. if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
  635. $relationships['object'][$rel_type][$sub_type] = array();
  636. }
  637. $relationships['object'][$rel_type][$sub_type][] = $relationship;
  638. }
  639. // now add in the subject relationships
  640. while ($relationship = db_fetch_object($as_subject)) {
  641. // get the relationship and child types
  642. $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
  643. $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
  644. if (!array_key_exists($rel_type, $relationships['subject'])) {
  645. $relationships['subject'][$rel_type] = array();
  646. }
  647. if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
  648. $relationships['subject'][$rel_type][$obj_type] = array();
  649. }
  650. $relationships['subject'][$rel_type][$obj_type][] = $relationship;
  651. }
  652. $pub->all_relationships = $relationships;
  653. }