tripal_featuremap.module 23 KB

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