tripal_featuremap.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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_css(drupal_get_path('module', 'tripal_featuremap') . '/theme/css/tripal_featuremap.css');
  18. drupal_add_js(drupal_get_path('module', 'tripal_featuremap') . '/theme/js/tripal_featuremap.js');
  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_help'),
  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_help'),
  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. $theme_path = drupal_get_path('module', 'tripal_featuremap') . '/theme';
  193. $items = array(
  194. // themed functions
  195. 'tripal_featuremap_search_index' => array(
  196. 'arguments' => array('node'),
  197. ),
  198. 'tripal_featuremap_search_result' => array(
  199. 'arguments' => array('node'),
  200. ),
  201. // tripal_featuremap templates
  202. 'tripal_featuremap_base' => array(
  203. 'arguments' => array('node' => NULL),
  204. 'template' => 'tripal_featuremap_base',
  205. 'path' => "$theme_path/tripal_featuremap",
  206. ),
  207. 'tripal_featuremap_properties' => array(
  208. 'arguments' => array('node' => NULL),
  209. 'template' => 'tripal_featuremap_properties',
  210. 'path' => "$theme_path/tripal_featuremap",
  211. ),
  212. 'tripal_featuremap_featurepos' => array(
  213. 'arguments' => array('node' => NULL),
  214. 'template' => 'tripal_featuremap_featurepos',
  215. 'path' => "$theme_path/tripal_featuremap",
  216. ),
  217. 'tripal_featuremap_publication' => array(
  218. 'arguments' => array('node' => NULL),
  219. 'template' => 'tripal_featuremap_publication',
  220. 'path' => "$theme_path/tripal_featuremap",
  221. ),
  222. 'tripal_featuremap_references' => array(
  223. 'arguments' => array('node' => NULL),
  224. 'template' => 'tripal_featuremap_references',
  225. 'path' => "$theme_path/tripal_featuremap",
  226. ),
  227. 'tripal_featuremap_help' => array(
  228. 'template' => 'tripal_featuremap_help',
  229. 'arguments' => array(NULL),
  230. 'path' => $theme_path,
  231. ),
  232. // Themed Forms
  233. 'chado_featuremap_node_form' => array(
  234. 'arguments' => array('form'),
  235. ),
  236. );
  237. return $items;
  238. }
  239. /**
  240. * Implements hook_help()
  241. * Purpose: Adds a help page to the module list
  242. */
  243. function tripal_featuremap_help ($path, $arg) {
  244. if ($path == 'admin/help#tripal_featuremap') {
  245. return theme('tripal_featuremap_help', array());
  246. }
  247. }
  248. /**
  249. * @ingroup tripal_library
  250. */
  251. function tripal_featuremap_block_info() {
  252. $blocks['mapbase']['info'] = t('Tripal Map Details');
  253. $blocks['mapbase']['cache'] = BLOCK_NO_CACHE;
  254. $blocks['mapprops']['info'] = t('Tripal Map Properties');
  255. $blocks['mapprops']['cache'] = BLOCK_NO_CACHE;
  256. $blocks['mappos']['info'] = t('Tripal Map Features');
  257. $blocks['mappos']['cache'] = BLOCK_NO_CACHE;
  258. $blocks['mappubs']['info'] = t('Tripal Map Publications');
  259. $blocks['mappubs']['cache'] = BLOCK_NO_CACHE;
  260. $blocks['maprefs']['info'] = t('Tripal Map References');
  261. $blocks['maprefs']['cache'] = BLOCK_NO_CACHE;
  262. return $blocks;
  263. }
  264. /**
  265. * @ingroup tripal_library
  266. */
  267. function tripal_featuremap_block_view($delta = '') {
  268. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  269. $nid = arg(1);
  270. $node = node_load($nid);
  271. $block = array();
  272. switch ($delta) {
  273. case 'mapbase':
  274. $block['subject'] = t('Library Details');
  275. $block['content'] = theme('tripal_featuremap_base', $node);
  276. break;
  277. case 'mapprops':
  278. $block['subject'] = t('Properties');
  279. $block['content'] = theme('tripal_featuremap_properties', $node);
  280. break;
  281. case 'mappos':
  282. $block['subject'] = t('Features');
  283. $block['content'] = theme('tripal_featuremap_featurepos', $node);
  284. break;
  285. case 'mappubs':
  286. $block['subject'] = t('Publications');
  287. $block['content'] = theme('tripal_featuremap_publication', $node);
  288. break;
  289. case 'maprefs':
  290. $block['subject'] = t('References');
  291. $block['content'] = theme('tripal_featuremap_references', $node);
  292. break;
  293. default :
  294. }
  295. return $block;
  296. }
  297. }
  298. /**
  299. * This function is an extension of the chado_feature_view and
  300. * chado_organism_view by providing the markup for the map object
  301. * THAT WILL BE INDEXED.
  302. *
  303. * @ingroup tripal_featuremap
  304. */
  305. function theme_tripal_featuremap_search_index($node) {
  306. }
  307. /**
  308. *
  309. * @ingroup tripal_featuremap
  310. */
  311. function tripal_featuremap_cron() {
  312. }
  313. /**
  314. * Implement hook_access().
  315. *
  316. * This hook allows node modules to limit access to the node types they define.
  317. *
  318. * @param $node
  319. * The node on which the operation is to be performed, or, if it does not yet exist, the
  320. * type of node to be created
  321. *
  322. * @param $op
  323. * The operation to be performed
  324. *
  325. * @param $account
  326. * A user object representing the user for whom the operation is to be performed
  327. *
  328. * @return
  329. * If the permission for the specified operation is not set then return FALSE. If the
  330. * permission is set then return NULL as this allows other modules to disable
  331. * access. The only exception is when the $op == 'create'. We will always
  332. * return TRUE if the permission is set.
  333. *
  334. * @ingroup tripal_featuremap
  335. */
  336. function chado_featuremap_node_access($node, $op, $account) {
  337. if ($op == 'create') {
  338. if (!user_access('create chado_featuremap content', $account)) {
  339. return FALSE;
  340. }
  341. return TRUE;
  342. }
  343. if ($op == 'update') {
  344. if (!user_access('edit any chado_featuremap content', $account) &&
  345. !user_access('edit own chado_featuremap content', $account)) {
  346. return FALSE;
  347. }
  348. if (user_access('edit own chado_featuremap content', $account) &&
  349. $account->uid != $node->uid) {
  350. return FALSE;
  351. }
  352. }
  353. if ($op == 'delete') {
  354. if (!user_access('delete any chado_featuremap content', $account) &&
  355. !user_access('delete own chado_featuremap content', $account)) {
  356. return FALSE;
  357. }
  358. if (user_access('delete own chado_featuremap content', $account) &&
  359. $account->uid != $node->uid) {
  360. return FALSE;
  361. }
  362. }
  363. return NULL;
  364. }
  365. /**
  366. * When a new chado_featuremap node is created we also need to add information
  367. * to our chado_featuremap table. This function is called on insert of a new node
  368. * of type 'chado_featuremap' and inserts the necessary information.
  369. *
  370. * @ingroup tripal_featuremap
  371. */
  372. function chado_featuremap_insert($node) {
  373. // if the featuremap_id already exists then we got to the insert via
  374. // a syncing operation. We do not need to add the feature map
  375. if ($node->featuremap_id) {
  376. $featuremap['featuremap_id'] = $node->featuremap_id;
  377. }
  378. else {
  379. $values = array(
  380. 'name' => $node->title,
  381. 'description' => $node->description,
  382. 'unittype_id' => $node->unittype_id
  383. );
  384. $featuremap = tripal_core_chado_insert('featuremap', $values);
  385. if(!$featuremap) {
  386. drupal_set_message(t('Unable to add featuremap.', 'warning'));
  387. watchdog('tripal_featuremap', 'Unable to create feature map where values: %values',
  388. array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
  389. return;
  390. }
  391. // now add the properties
  392. $properties = array(); // stores all of the properties we need to add
  393. $cross_refs = array(); // stores any cross references for this featuremap
  394. // get the list of properties for easy lookup (without doing lots of database queries
  395. $properties_list = array();
  396. $sql = "
  397. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  398. FROM {cvterm} CVT
  399. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  400. WHERE
  401. CV.name = 'featuremap_property' AND
  402. NOT CVT.is_obsolete = 1
  403. ORDER BY CVT.name ASC
  404. ";
  405. $prop_types = chado_query($sql);
  406. while ($prop = $prop_types->fetchObject()) {
  407. $properties_list[$prop->cvterm_id] = $prop->name;
  408. }
  409. // get the properties that should be added. Properties are in one of two forms:
  410. // 1) prop_value-[type id]-[index]
  411. // 2) new_value-[type id]-[index]
  412. // 3) new_id, new_value
  413. foreach ($node as $name => $value) {
  414. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  415. $type_id = $matches[1];
  416. $index = $matches[2];
  417. $name = $properties_list[$type_id];
  418. $properties[$name][$index] = trim($value);
  419. }
  420. }
  421. if ($node->new_id and $node->new_value) {
  422. $type_id = $node->new_id;
  423. $index = count($properties[$name]);
  424. $name = $properties_list[$type_id];
  425. $properties[$name][$index] = trim($node->new_value);
  426. }
  427. // iterate through all of the properties to see if the Map dbxref is set,
  428. // if so, add it to the $cross_refs array
  429. foreach ($properties as $name => $element) {
  430. foreach ($element as $index => $value) {
  431. if ($name == "Map Dbxref") {
  432. // we will add the cross-references to the featuremap_dbxref table
  433. // but we also want to keep the property in the featuremapprop table so don't unset it
  434. $cross_refs[] = $value;
  435. }
  436. }
  437. }
  438. // now add in the properties
  439. foreach ($properties as $property => $elements) {
  440. foreach ($elements as $rank => $value) {
  441. $status = tripal_featuremap_insert_property($featuremap['featuremap_id'], $property, $value, FALSE);
  442. if (!$status) {
  443. drupal_set_message("Error cannot add property: $property", "error");
  444. watchdog('t_featuremap', "Error cannot add property: %prop",
  445. array('%property' => $property), WATCHDOG_ERROR);
  446. }
  447. }
  448. }
  449. // add in any database cross-references
  450. foreach ($cross_refs as $index => $ref) {
  451. $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap['featuremap_id'], trim($ref));
  452. if (!$featuremap_dbxref) {
  453. drupal_set_message("Error cannot add map cross reference: $ref", "error");
  454. watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
  455. array('%ref' => $ref), WATCHDOG_ERROR);
  456. }
  457. }
  458. }
  459. // add the record to the chado_featuremap table in Drupal
  460. if ($featuremap) {
  461. // make sure the entry for this feature doesn't already exist in the chado_featuremap table
  462. // if it doesn't exist then we want to add it.
  463. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
  464. if (!$featuremap_id) {
  465. // next add the item to the drupal table
  466. $sql = "
  467. INSERT INTO {chado_featuremap} (nid, vid, featuremap_id)
  468. VALUES (:nid, :vid, :featuremap_id)
  469. ";
  470. db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':featuremap_id' => $featuremap['featuremap_id']));
  471. }
  472. }
  473. }
  474. /**
  475. * Update nodes
  476. *
  477. * @ingroup tripal_featuremap
  478. */
  479. function chado_featuremap_update($node) {
  480. if ($node->revision) {
  481. // there is no way to handle revisions in Chado but leave
  482. // this here just to make not we've addressed it.
  483. }
  484. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
  485. // update the map record
  486. $match = array(
  487. 'featuremap_id' => $featuremap_id,
  488. );
  489. $values = array(
  490. 'name' => $node->title,
  491. 'description' => $node->description,
  492. 'unittype_id' => $node->unittype_id
  493. );
  494. $status = tripal_core_chado_update('featuremap', $match, $values);
  495. if (!$status) {
  496. drupal_set_message("Error updating map", "error");
  497. watchdog('t_featuremap', "Error updating map", array(), WATCHDOG_ERROR);
  498. return;
  499. }
  500. // now update the properties
  501. $properties = array(); // stores all of the properties we need to add
  502. $cross_refs = array(); // stores any cross references for this map
  503. // get the list of properties for easy lookup (without doing lots of database queries
  504. $properties_list = array();
  505. $sql = "
  506. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  507. FROM {cvterm} CVT
  508. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  509. WHERE
  510. CV.name = 'featuremap_property' AND
  511. NOT CVT.is_obsolete = 1
  512. ORDER BY CVT.name ASC
  513. ";
  514. $prop_types = chado_query($sql);
  515. while ($prop = $prop_types->fetchObject()) {
  516. $properties_list[$prop->cvterm_id] = $prop->name;
  517. }
  518. // get the properties that should be added. Properties are in one of three forms:
  519. // 1) prop_value-[type id]-[index]
  520. // 2) new_value-[type id]-[index]
  521. // 3) new_id, new_value
  522. // dpm($node);
  523. foreach ($node as $key => $value) {
  524. if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
  525. $type_id = $matches[1];
  526. $index = $matches[2];
  527. $name = $properties_list[$type_id];
  528. $properties[$name][$index] = trim($value);
  529. }
  530. if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
  531. $type_id = $matches[1];
  532. $index = $matches[2];
  533. $name = $properties_list[$type_id];
  534. $properties[$name][$index] = trim($value);
  535. }
  536. }
  537. if ($node->new_id and $node->new_value) {
  538. $type_id = $node->new_id;
  539. $name = $properties_list[$type_id];
  540. $index = count($properties[$name]);
  541. $properties[$name][$index] = trim($node->new_value);
  542. }
  543. // iterate through all of the properties to see if the Map dbxref is set,
  544. // if so, add it to the $cross_refs array
  545. foreach ($properties as $name => $element) {
  546. foreach ($element as $index => $value) {
  547. if ($name == "Map Dbxref") {
  548. // we will add the cross-references to the featuremap_dbxref table
  549. // but we also want to keep the property in the featuremapprop table so don't unset it
  550. $cross_refs[] = $value;
  551. }
  552. }
  553. }
  554. // now add in the properties by first removing any the featuremap
  555. // already has and adding the ones we have
  556. tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
  557. foreach ($properties as $property => $elements) {
  558. foreach ($elements as $rank => $value) {
  559. $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE);
  560. if (!$status) {
  561. drupal_set_message("Error cannot add property: '$property'", "error");
  562. watchdog('t_featuremap', "Error cannot add property: '%prop'",
  563. array('%prop' => $property), WATCHDOG_ERROR);
  564. }
  565. }
  566. }
  567. // add in any database cross-references after first removing
  568. tripal_core_chado_delete('featuremap_dbxref', array('featuremap_id' => $featuremap_id));
  569. foreach ($cross_refs as $index => $ref) {
  570. $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, trim($ref));
  571. if (!$featuremap_dbxref) {
  572. drupal_set_message("Error cannot add map cross reference: $ref", "error");
  573. watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
  574. array('%ref' => $ref), WATCHDOG_ERROR);
  575. }
  576. }
  577. }
  578. /**
  579. * When a node is requested by the user this function is called to allow us
  580. * to add auxiliary data to the node object.
  581. *
  582. * @ingroup tripal_featuremap
  583. */
  584. function chado_featuremap_load($node) {
  585. // get the feature details from chado
  586. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
  587. $values = array('featuremap_id' => $featuremap_id);
  588. $featuremap = tripal_core_generate_chado_var('featuremap', $values);
  589. // expand the description field as it is needed by the form
  590. $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
  591. $additions = new stdClass();
  592. $additions->featuremap = $featuremap;
  593. return $additions;
  594. }
  595. /**
  596. * This function customizes the view of the chado_featuremap node. It allows
  597. * us to generate the markup. This function is required for node [Preview]
  598. *
  599. * @ingroup tripal_featuremap
  600. */
  601. function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
  602. // use drupal's default node view:
  603. if (!$teaser) {
  604. $node = node_prepare($node, $teaser);
  605. }
  606. return $node;
  607. }
  608. /**
  609. * Delete data from drupal and chado databases when a node is deleted
  610. * @ingroup tripal_featuremap
  611. */
  612. function chado_featuremap_delete(&$node) {
  613. $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
  614. // if we don't have a map id for this node then this isn't a node of
  615. // type chado_featuremap or the entry in the chado_featuremap table was lost.
  616. if (!$featuremap_id) {
  617. return;
  618. }
  619. // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
  620. // drupal database
  621. $sql_del = "DELETE FROM {chado_featuremap} WHERE nid = :nid AND vid = :vid";
  622. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  623. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  624. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  625. $sql_del = "DELETE FROM {node_revisions} WHERE nid = :nid AND vid = :vid";
  626. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  627. // Remove data from map and mapprop tables of chado database as well
  628. chado_query("DELETE FROM {featuremap} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
  629. chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
  630. }