blast_ui.node.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * @file
  4. * Contains all functions for creating the blastdb node type
  5. */
  6. /**
  7. *
  8. * Implements hook_node_info()
  9. *
  10. */
  11. function blast_ui_node_info() {
  12. return array(
  13. 'blastdb' => array(
  14. 'name' => t('Blast Database'),
  15. 'base' => 'blastdb',
  16. 'description' => t('Registers a BLAST Database for use with the BLAST UI.'),
  17. ),
  18. );
  19. }
  20. function blastdb_node_access($node, $op, $account) {
  21. $node_type = $node;
  22. if (is_object($node)) {
  23. $node_type = $node->type;
  24. }
  25. if($node_type == 'blastdb') {
  26. if ($op == 'create') {
  27. if (!user_access('create Blast Database', $account)) {
  28. return NODE_ACCESS_DENY;
  29. }
  30. return NODE_ACCESS_ALLOW;
  31. }
  32. if ($op == 'update') {
  33. if (!user_access('edit Blast Database', $account)) {
  34. return NODE_ACCESS_DENY;
  35. }
  36. }
  37. if ($op == 'delete') {
  38. if (!user_access('delete Blast Database', $account)) {
  39. return NODE_ACCESS_DENY;
  40. }
  41. }
  42. if ($op == 'view') {
  43. if (!user_access('access Blast Database', $account)) {
  44. return NODE_ACCESS_DENY;
  45. }
  46. }
  47. return NODE_ACCESS_IGNORE;
  48. }
  49. }
  50. /**
  51. * Form constructor for the blastdb node
  52. *
  53. * @see blastdb_insert()
  54. * @see blastdb_update()
  55. * @see blastdb_delete()
  56. * @see blastdb_load()
  57. *
  58. */
  59. function blastdb_form($node, &$form_state) {
  60. $form = array();
  61. $form['db_name']= array(
  62. '#type' => 'textfield',
  63. '#title' => t('Human-readable Name for Blast database'),
  64. '#required' => TRUE,
  65. '#default_value' => isset($node->db_name) ? $node->db_name : '',
  66. );
  67. $form['db_path']= array(
  68. '#type' => 'textfield',
  69. '#title' => t('File Prefix including Full Path'),
  70. '#description' => t('The full path to your blast database including the file name but not the file type suffix. For example, /var/www/website/sites/default/files/myblastdb'),
  71. '#required' => TRUE,
  72. '#default_value' => isset($node->db_path) ? $node->db_path : '',
  73. );
  74. return $form;
  75. }
  76. /**
  77. *
  78. * Implements hook_insert()
  79. *
  80. */
  81. function blastdb_insert($node) {
  82. db_insert('blastdb')->fields(array(
  83. 'nid' => $node->nid,
  84. 'name' => $node->db_name,
  85. 'path' => $node->db_path,
  86. ))->execute();
  87. }
  88. /**
  89. * Implements hook_node_insert().
  90. * This function acts on ALL NODES
  91. */
  92. function blast_ui_node_insert($node) {
  93. if ($node->type == 'blastdb') {
  94. $node->title = $node->db_name;
  95. }
  96. }
  97. /**
  98. *
  99. * Implements hook_update()
  100. *
  101. */
  102. function blastdb_update($node) {
  103. db_update('blastdb')->fields(array(
  104. 'name' => $node->db_name,
  105. 'path' => $node->db_path,
  106. ))->condition('nid', $node->nid)->execute();
  107. }
  108. /**
  109. * Implements hook_node_update().
  110. * This function acts on ALL NODES
  111. */
  112. function blast_ui_node_update($node) {
  113. if ($node->type == 'blastdb') {
  114. $node->title = $node->db_name;
  115. }
  116. }
  117. /**
  118. *
  119. * Implements hook_delete()
  120. *
  121. */
  122. function blastdb_delete($node) {
  123. db_delete('blastdb')->condition('nid',$node->nid)->execute();
  124. }
  125. /**
  126. *
  127. * Implements hook_load()
  128. *
  129. */
  130. function blastdb_load($nodes) {
  131. $result = db_query('SELECT nid, name, path FROM {blastdb} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
  132. foreach ($result as $record) {
  133. $nodes[$record->nid]->db_name = $record->name;
  134. $nodes[$record->nid]->db_path = $record->path;
  135. $nodes[$record->nid]->title = $record->name;
  136. }
  137. }