tripal_featuremap.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. /**
  3. * @defgroup tripal_featuremap Feature Map Module
  4. * @ingroup tripal_modules
  5. * @{
  6. * Provides functions for managing chado maps including creating details pages for each map
  7. * @}
  8. */
  9. require('api/tripal_featuremap.api.inc');
  10. require('includes/tripal_featuremap.admin.inc');
  11. require('includes/tripal_featuremap.form.inc');
  12. /**
  13. *
  14. * @ingroup tripal_featuremap
  15. */
  16. function tripal_featuremap_init() {
  17. //drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_pub.js');
  18. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_featuremap.css');
  19. }
  20. /**
  21. * Display help and module information
  22. * @param path which path of the site we're displaying help
  23. * @param arg array that holds the current path as would be returned from arg()
  24. * function
  25. * @return help text for the path
  26. *
  27. * @ingroup tripal_featuremap
  28. */
  29. function tripal_featuremap_help($path, $arg) {
  30. $output = '';
  31. switch ($path) {
  32. case "admin/help#tripal_featuremap":
  33. $output = '<p>'.
  34. t("Displays links to nodes created on this date") .
  35. '</p>';
  36. break;
  37. }
  38. return $output;
  39. }
  40. /**
  41. * Provide information to drupal about the node types that we're creating
  42. * in this module
  43. *
  44. * @ingroup tripal_featuremap
  45. */
  46. function tripal_featuremap_node_info() {
  47. $nodes = array();
  48. $nodes['chado_featuremap'] = array(
  49. 'name' => t('Map'),
  50. 'base' => 'chado_featuremap',
  51. 'description' => t('A feature map from the chado database (e.g. genetic map)'),
  52. 'has_title' => FALSE,
  53. 'title_label' => t('Feature Map'),
  54. 'has_body' => FALSE,
  55. 'body_label' => t('Feature Map Description'),
  56. 'locked' => TRUE
  57. );
  58. return $nodes;
  59. }
  60. /**
  61. * Set the permission types that the chado module uses. Essentially we
  62. * want permissionis that protect creation, editing and deleting of chado
  63. * data objects
  64. *
  65. * @ingroup tripal_featuremap
  66. */
  67. function tripal_featuremap_permissions() {
  68. return array(
  69. 'access chado_featuremap content' => array(
  70. 'title' => t('View Maps'),
  71. 'description' => t('Allow users to view map pages.'),
  72. ),
  73. 'create chado_featuremap content' => array(
  74. 'title' => t('Create Maps'),
  75. 'description' => t('Allow users to create new map pages.'),
  76. ),
  77. 'delete chado_featuremap content' => array(
  78. 'title' => t('Delete Maps'),
  79. 'description' => t('Allow users to delete map pages.'),
  80. ),
  81. 'edit chado_featuremap content' => array(
  82. 'title' => t('Edit Maps'),
  83. 'description' => t('Allow users to edit map pages.'),
  84. ),
  85. 'adminster tripal featuremap' => array(
  86. 'title' => t('Administer Maps'),
  87. 'description' => t('Allow users to administer all maps.'),
  88. ),
  89. );
  90. }
  91. /**
  92. * Set the permission types that the module uses.
  93. *
  94. * @ingroup tripal_featuremap
  95. */
  96. function chado_featuremap_access($op, $node, $account) {
  97. if ($op == 'create') {
  98. if (!user_access('create chado_featuremap content', $account)) {
  99. return FALSE;
  100. }
  101. }
  102. if ($op == 'update') {
  103. if (!user_access('edit chado_featuremap content', $account)) {
  104. return FALSE;
  105. }
  106. }
  107. if ($op == 'delete') {
  108. if (!user_access('delete chado_featuremap content', $account)) {
  109. return FALSE;
  110. }
  111. }
  112. if ($op == 'view') {
  113. if (!user_access('access chado_featuremap content', $account)) {
  114. return FALSE;
  115. }
  116. }
  117. return NULL;
  118. }
  119. /**
  120. * Menu items are automatically added for the new node types created
  121. * by this module to the 'Create Content' Navigation menu item. This function
  122. * adds more menu items needed for this module.
  123. *
  124. * @ingroup tripal_featuremap
  125. */
  126. function tripal_featuremap_menu() {
  127. $items = array();
  128. // The administative settings menu
  129. $items['admin/tripal/tripal_featuremap'] = array(
  130. 'title' => 'Maps',
  131. 'description' => 'Basic Description of Tripal Map Module Functionality',
  132. 'page callback' => 'theme',
  133. 'page arguments' => array('tripal_featuremap_admin'),
  134. 'access arguments' => array('administer tripal featuremap'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. );
  137. $items['admin/tripal/tripal_featuremap/configuration'] = array(
  138. 'title' => 'Configuration',
  139. 'description' => 'Manage integration of Chado maps including associated features.',
  140. 'page callback' => 'drupal_get_form',
  141. 'page arguments' => array('tripal_featuremap_admin'),
  142. 'access arguments' => array('administer tripal featuremap'),
  143. 'type' => MENU_NORMAL_ITEM,
  144. );
  145. // Synchronizing maps from Chado to Drupal
  146. $items['chado_sync_featuremaps'] = array(
  147. 'title' => 'Sync Data',
  148. 'page callback' => 'tripal_featuremap_sync_featuremaps',
  149. 'access arguments' => array('administer tripal featuremap'),
  150. 'type' => MENU_CALLBACK
  151. );
  152. // AJAX calls for adding/removing properties to a featuremap
  153. $items['tripal_featuremap/properties/add'] = array(
  154. 'page callback' => 'tripal_featuremap_property_add',
  155. 'access arguments' => array('edit chado_featuremap content'),
  156. 'type ' => MENU_CALLBACK,
  157. );
  158. $items['tripal_featuremap/properties/description'] = array(
  159. 'page callback' => 'tripal_featuremap_property_get_description',
  160. 'access arguments' => array('edit chado_featuremap content'),
  161. 'type ' => MENU_CALLBACK,
  162. );
  163. $items['tripal_featuremap/properties/minus/%/%'] = array(
  164. 'page callback' => 'tripal_featuremap_property_delete',
  165. 'page arguments' => array(3, 4),
  166. 'access arguments' => array('edit chado_featuremap content'),
  167. 'type ' => MENU_CALLBACK,
  168. );
  169. return $items;
  170. }
  171. /**
  172. * Implements hook_views_api()
  173. * Purpose: Essentially this hook tells drupal that there is views support for
  174. * for this module which then includes tripal_db.views.inc where all the
  175. * views integration code is
  176. *
  177. * @ingroup tripal_featuremap
  178. */
  179. function tripal_featuremap_views_api() {
  180. return array(
  181. 'api' => 2.0,
  182. );
  183. }
  184. /**
  185. * We need to let drupal know about our theme functions and their arguments.
  186. * We create theme functions to allow users of the module to customize the
  187. * look and feel of the output generated in this module
  188. *
  189. * @ingroup tripal_featuremap
  190. */
  191. function tripal_featuremap_theme() {
  192. return array(
  193. 'tripal_featuremap_search_index' => array(
  194. 'arguments' => array('node'),
  195. ),
  196. 'tripal_featuremap_search_result' => array(
  197. 'arguments' => array('node'),
  198. ),
  199. 'tripal_featuremap_base' => array(
  200. 'arguments' => array('node' => NULL),
  201. 'template' => 'tripal_featuremap_base',
  202. ),
  203. 'tripal_featuremap_properties' => array(
  204. 'arguments' => array('node' => NULL),
  205. 'template' => 'tripal_featuremap_properties',
  206. ),
  207. 'tripal_featuremap_featurepos' => array(
  208. 'arguments' => array('node' => NULL),
  209. 'template' => 'tripal_featuremap_featurepos',
  210. ),
  211. 'tripal_featuremap_publication' => array(
  212. 'arguments' => array('node' => NULL),
  213. 'template' => 'tripal_featuremap_publication',
  214. ),
  215. 'tripal_featuremap_references' => array(
  216. 'arguments' => array('node' => NULL),
  217. 'template' => 'tripal_featuremap_references',
  218. ),
  219. 'tripal_featuremap_admin' => array(
  220. 'template' => 'tripal_featuremap_admin',
  221. 'arguments' => array(NULL),
  222. 'path' => drupal_get_path('module', 'tripal_featuremap') . '/theme'
  223. ),
  224. // Themed Forms
  225. 'chado_featuremap_node_form' => array(
  226. 'arguments' => array('form'),
  227. ),
  228. );
  229. }
  230. /**
  231. * @ingroup tripal_library
  232. */
  233. function tripal_featuremap_block_info() {
  234. $blocks['mapbase']['info'] = t('Tripal Map Details');
  235. $blocks['mapbase']['cache'] = BLOCK_NO_CACHE;
  236. $blocks['mapprops']['info'] = t('Tripal Map Properties');
  237. $blocks['mapprops']['cache'] = BLOCK_NO_CACHE;
  238. $blocks['mappos']['info'] = t('Tripal Map Features');
  239. $blocks['mappos']['cache'] = BLOCK_NO_CACHE;
  240. $blocks['mappubs']['info'] = t('Tripal Map Publications');
  241. $blocks['mappubs']['cache'] = BLOCK_NO_CACHE;
  242. $blocks['maprefs']['info'] = t('Tripal Map References');
  243. $blocks['maprefs']['cache'] = BLOCK_NO_CACHE;
  244. return $blocks;
  245. }
  246. /**
  247. * @ingroup tripal_library
  248. */
  249. function tripal_featuremap_block_view($delta = '') {
  250. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  251. $nid = arg(1);
  252. $node = node_load($nid);
  253. $block = array();
  254. switch ($delta) {
  255. case 'mapbase':
  256. $block['subject'] = t('Library Details');
  257. $block['content'] = theme('tripal_featuremap_base', $node);
  258. break;
  259. case 'mapprops':
  260. $block['subject'] = t('Properties');
  261. $block['content'] = theme('tripal_featuremap_properties', $node);
  262. break;
  263. case 'mappos':
  264. $block['subject'] = t('Features');
  265. $block['content'] = theme('tripal_featuremap_featurepos', $node);
  266. break;
  267. case 'mappubs':
  268. $block['subject'] = t('Publications');
  269. $block['content'] = theme('tripal_featuremap_publication', $node);
  270. break;
  271. case 'maprefs':
  272. $block['subject'] = t('References');
  273. $block['content'] = theme('tripal_featuremap_references', $node);
  274. break;
  275. default :
  276. }
  277. return $block;
  278. }
  279. }
  280. /**
  281. * This function is an extension of the chado_feature_view and
  282. * chado_organism_view by providing the markup for the map object
  283. * THAT WILL BE INDEXED.
  284. *
  285. * @ingroup tripal_featuremap
  286. */
  287. function theme_tripal_featuremap_search_index($node) {
  288. }
  289. /**
  290. *
  291. * @ingroup tripal_featuremap
  292. */
  293. function tripal_featuremap_cron() {
  294. }
  295. /**
  296. * Implement hook_access().
  297. *
  298. * This hook allows node modules to limit access to the node types they define.
  299. *
  300. * @param $node
  301. * The node on which the operation is to be performed, or, if it does not yet exist, the
  302. * type of node to be created
  303. *
  304. * @param $op
  305. * The operation to be performed
  306. *
  307. * @param $account
  308. * A user object representing the user for whom the operation is to be performed
  309. *
  310. * @return
  311. * If the permission for the specified operation is not set then return FALSE. If the
  312. * permission is set then return NULL as this allows other modules to disable
  313. * access. The only exception is when the $op == 'create'. We will always
  314. * return TRUE if the permission is set.
  315. *
  316. * @ingroup tripal_featuremap
  317. */
  318. function chado_featuremap_node_access($node, $op, $account) {
  319. if ($op == 'create') {
  320. if (!user_access('create chado_featuremap content', $account)) {
  321. return FALSE;
  322. }
  323. return TRUE;
  324. }
  325. if ($op == 'update') {
  326. if (!user_access('edit any chado_featuremap content', $account) &&
  327. !user_access('edit own chado_featuremap content', $account)) {
  328. return FALSE;
  329. }
  330. if (user_access('edit own chado_featuremap content', $account) &&
  331. $account->uid != $node->uid) {
  332. return FALSE;
  333. }
  334. }
  335. if ($op == 'delete') {
  336. if (!user_access('delete any chado_featuremap content', $account) &&
  337. !user_access('delete own chado_featuremap content', $account)) {
  338. return FALSE;
  339. }
  340. if (user_access('delete own chado_featuremap content', $account) &&
  341. $account->uid != $node->uid) {
  342. return FALSE;
  343. }
  344. }
  345. return NULL;
  346. }
  347. /**
  348. * When a new chado_featuremap node is created we also need to add information
  349. * to our chado_featuremap table. This function is called on insert of a new node
  350. * of type 'chado_featuremap' and inserts the necessary information.
  351. *
  352. * @ingroup tripal_featuremap
  353. */
  354. function chado_featuremap_insert($node) {
  355. // if the featuremap_id already exists then we got to the insert via
  356. // a syncing operation. We do not need to add the feature map
  357. if ($node->featuremap_id) {
  358. $featuremap['featuremap_id'] = $node->featuremap_id;
  359. }
  360. else {
  361. $values = array(
  362. 'name' => $node->title,
  363. 'description' => $node->description,
  364. 'unittype_id' => $node->unittype_id
  365. );
  366. $featuremap = tripal_core_chado_insert('featuremap', $values);
  367. if(!$featuremap) {
  368. drupal_set_message(t('Unable to add featuremap.', 'warning'));
  369. watchdog('tripal_featuremap', 'Unable to create feature map where values: %values',
  370. array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
  371. return;
  372. }
  373. // now add the properties
  374. $properties = array(); // stores all of the properties we need to add
  375. $cross_refs = array(); // stores any cross references for this featuremap
  376. // get the list of properties for easy lookup (without doing lots of database queries
  377. $properties_list = array();
  378. $sql = "
  379. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  380. FROM {cvterm} CVT
  381. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  382. WHERE
  383. CV.name = 'featuremap_property' AND
  384. NOT CVT.is_obsolete = 1
  385. ORDER BY CVT.name ASC
  386. ";
  387. $prop_types = chado_query($sql);
  388. while ($prop = $prop_types->fetchObject()) {
  389. $properties_list[$prop->cvterm_id] = $prop->name;
  390. }
  391. // get the properties that should be added. Properties are in one of two forms:
  392. // 1) prop_value-[type id]-[index]
  393. // 2) new_value-[type id]-[index]
  394. // 3) new_id, new_value
  395. foreach ($node as $name => $value) {
  396. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  397. $type_id = $matches[1];
  398. $index = $matches[2];
  399. $name = $properties_list[$type_id];
  400. $properties[$name][$index] = trim($value);
  401. }
  402. }
  403. if ($node->new_id and $node->new_value) {
  404. $type_id = $node->new_id;
  405. $index = count($properties[$name]);
  406. $name = $properties_list[$type_id];
  407. $properties[$name][$index] = trim($node->new_value);
  408. }
  409. // iterate through all of the properties to see if the Map dbxref is set,
  410. // if so, add it to the $cross_refs array
  411. foreach ($properties as $name => $element) {
  412. foreach ($element as $index => $value) {
  413. if ($name == "Map Dbxref") {
  414. // we will add the cross-references to the featuremap_dbxref table
  415. // but we also want to keep the property in the featuremapprop table so don't unset it
  416. $cross_refs[] = $value;
  417. }
  418. }
  419. }
  420. // now add in the properties
  421. foreach ($properties as $property => $elements) {
  422. foreach ($elements as $rank => $value) {
  423. $status = tripal_featuremap_insert_property($featuremap['featuremap_id'], $property, $value, FALSE);
  424. if (!$status) {
  425. drupal_set_message("Error cannot add property: $property", "error");
  426. watchdog('t_featuremap', "Error cannot add property: %prop",
  427. array('%property' => $property), WATCHDOG_ERROR);
  428. }
  429. }
  430. }
  431. // add in any database cross-references
  432. foreach ($cross_refs as $index => $ref) {
  433. $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap['featuremap_id'], trim($ref));
  434. if (!$featuremap_dbxref) {
  435. drupal_set_message("Error cannot add map cross reference: $ref", "error");
  436. watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
  437. array('%ref' => $ref), WATCHDOG_ERROR);
  438. }
  439. }
  440. }
  441. // add the record to the chado_featuremap table in Drupal
  442. if ($featuremap) {
  443. // make sure the entry for this feature doesn't already exist in the chado_featuremap table
  444. // if it doesn't exist then we want to add it.
  445. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
  446. if (!$featuremap_id) {
  447. // next add the item to the drupal table
  448. $sql = "
  449. INSERT INTO {chado_featuremap} (nid, vid, featuremap_id)
  450. VALUES (:nid, :vid, :featuremap_id)
  451. ";
  452. db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':featuremap_id' => $featuremap['featuremap_id']));
  453. }
  454. }
  455. }
  456. /**
  457. * Update nodes
  458. *
  459. * @ingroup tripal_featuremap
  460. */
  461. function chado_featuremap_update($node) {
  462. if ($node->revision) {
  463. // there is no way to handle revisions in Chado but leave
  464. // this here just to make not we've addressed it.
  465. }
  466. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
  467. // update the map record
  468. $match = array(
  469. 'featuremap_id' => $featuremap_id,
  470. );
  471. $values = array(
  472. 'name' => $node->title,
  473. 'description' => $node->description,
  474. 'unittype_id' => $node->unittype_id
  475. );
  476. $status = tripal_core_chado_update('featuremap', $match, $values);
  477. if (!$status) {
  478. drupal_set_message("Error updating map", "error");
  479. watchdog('t_featuremap', "Error updating map", array(), WATCHDOG_ERROR);
  480. return;
  481. }
  482. // now update the properties
  483. $properties = array(); // stores all of the properties we need to add
  484. $cross_refs = array(); // stores any cross references for this map
  485. // get the list of properties for easy lookup (without doing lots of database queries
  486. $properties_list = array();
  487. $sql = "
  488. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  489. FROM {cvterm} CVT
  490. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  491. WHERE
  492. CV.name = 'featuremap_property' AND
  493. NOT CVT.is_obsolete = 1
  494. ORDER BY CVT.name ASC
  495. ";
  496. $prop_types = chado_query($sql);
  497. while ($prop = $prop_types->fetchObject()) {
  498. $properties_list[$prop->cvterm_id] = $prop->name;
  499. }
  500. // get the properties that should be added. Properties are in one of three forms:
  501. // 1) prop_value-[type id]-[index]
  502. // 2) new_value-[type id]-[index]
  503. // 3) new_id, new_value
  504. // dpm($node);
  505. foreach ($node as $key => $value) {
  506. if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
  507. $type_id = $matches[1];
  508. $index = $matches[2];
  509. $name = $properties_list[$type_id];
  510. $properties[$name][$index] = trim($value);
  511. }
  512. if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
  513. $type_id = $matches[1];
  514. $index = $matches[2];
  515. $name = $properties_list[$type_id];
  516. $properties[$name][$index] = trim($value);
  517. }
  518. }
  519. if ($node->new_id and $node->new_value) {
  520. $type_id = $node->new_id;
  521. $name = $properties_list[$type_id];
  522. $index = count($properties[$name]);
  523. $properties[$name][$index] = trim($node->new_value);
  524. }
  525. // iterate through all of the properties to see if the Map dbxref is set,
  526. // if so, add it to the $cross_refs array
  527. foreach ($properties as $name => $element) {
  528. foreach ($element as $index => $value) {
  529. if ($name == "Map Dbxref") {
  530. // we will add the cross-references to the featuremap_dbxref table
  531. // but we also want to keep the property in the featuremapprop table so don't unset it
  532. $cross_refs[] = $value;
  533. }
  534. }
  535. }
  536. // now add in the properties by first removing any the featuremap
  537. // already has and adding the ones we have
  538. tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
  539. foreach ($properties as $property => $elements) {
  540. foreach ($elements as $rank => $value) {
  541. $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE);
  542. if (!$status) {
  543. drupal_set_message("Error cannot add property: '$property'", "error");
  544. watchdog('t_featuremap', "Error cannot add property: '%prop'",
  545. array('%prop' => $property), WATCHDOG_ERROR);
  546. }
  547. }
  548. }
  549. // add in any database cross-references after first removing
  550. tripal_core_chado_delete('featuremap_dbxref', array('featuremap_id' => $featuremap_id));
  551. foreach ($cross_refs as $index => $ref) {
  552. $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, trim($ref));
  553. if (!$featuremap_dbxref) {
  554. drupal_set_message("Error cannot add map cross reference: $ref", "error");
  555. watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
  556. array('%ref' => $ref), WATCHDOG_ERROR);
  557. }
  558. }
  559. }
  560. /**
  561. * When a node is requested by the user this function is called to allow us
  562. * to add auxiliary data to the node object.
  563. *
  564. * @ingroup tripal_featuremap
  565. */
  566. function chado_featuremap_load($node) {
  567. // get the feature details from chado
  568. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
  569. $values = array('featuremap_id' => $featuremap_id);
  570. $featuremap = tripal_core_generate_chado_var('featuremap', $values);
  571. // expand the description field as it is needed by the form
  572. $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
  573. $additions = new stdClass();
  574. $additions->featuremap = $featuremap;
  575. return $additions;
  576. }
  577. /**
  578. * This function customizes the view of the chado_featuremap node. It allows
  579. * us to generate the markup. This function is required for node [Preview]
  580. *
  581. * @ingroup tripal_featuremap
  582. */
  583. function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
  584. // use drupal's default node view:
  585. if (!$teaser) {
  586. $node = node_prepare($node, $teaser);
  587. }
  588. return $node;
  589. }
  590. /**
  591. * Delete data from drupal and chado databases when a node is deleted
  592. * @ingroup tripal_featuremap
  593. */
  594. function chado_featuremap_delete(&$node) {
  595. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
  596. // if we don't have a map id for this node then this isn't a node of
  597. // type chado_featuremap or the entry in the chado_featuremap table was lost.
  598. if (!$featuremap_id) {
  599. return;
  600. }
  601. // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
  602. // drupal database
  603. $sql_del = "DELETE FROM {chado_featuremap} WHERE nid = :nid AND vid = :vid";
  604. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  605. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  606. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  607. $sql_del = "DELETE FROM {node_revisions} WHERE nid = :nid AND vid = :vid";
  608. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  609. // Remove data from map and mapprop tables of chado database as well
  610. chado_query("DELETE FROM {featuremap} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
  611. chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
  612. }