blast_ui.node.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. $form['db_dbtype'] = array(
  75. '#type' => 'radios',
  76. '#title' => t('Type of the blast database'),
  77. '#options' => array(
  78. 'n' => t('Nucleotide'),
  79. 'p' => t('Protein'),
  80. ),
  81. '#required' => TRUE,
  82. '#default_value' => isset($node->db_dbtype) ? $node->db_dbtype : 'n',
  83. );
  84. return $form;
  85. }
  86. /**
  87. *
  88. * Implements hook_insert()
  89. *
  90. */
  91. function blastdb_insert($node) {
  92. db_insert('blastdb')->fields(array(
  93. 'nid' => $node->nid,
  94. 'name' => $node->db_name,
  95. 'path' => $node->db_path,
  96. 'dbtype' => $node->db_dbtype,
  97. ))->execute();
  98. }
  99. /**
  100. * Implements hook_node_insert().
  101. * This function acts on ALL NODES
  102. */
  103. function blast_ui_node_insert($node) {
  104. if ($node->type == 'blastdb') {
  105. $node->title = $node->db_name;
  106. }
  107. }
  108. /**
  109. *
  110. * Implements hook_update()
  111. *
  112. */
  113. function blastdb_update($node) {
  114. db_update('blastdb')->fields(array(
  115. 'name' => $node->db_name,
  116. 'path' => $node->db_path,
  117. 'dbtype' => $node->db_dbtype,
  118. ))->condition('nid', $node->nid)->execute();
  119. }
  120. /**
  121. * Implements hook_node_update().
  122. * This function acts on ALL NODES
  123. */
  124. function blast_ui_node_update($node) {
  125. if ($node->type == 'blastdb') {
  126. $node->title = $node->db_name;
  127. }
  128. }
  129. /**
  130. *
  131. * Implements hook_delete()
  132. *
  133. */
  134. function blastdb_delete($node) {
  135. db_delete('blastdb')->condition('nid',$node->nid)->execute();
  136. }
  137. /**
  138. *
  139. * Implements hook_load()
  140. *
  141. */
  142. function blastdb_load($nodes) {
  143. $result = db_query('SELECT nid, name, path, dbtype FROM {blastdb} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
  144. foreach ($result as $record) {
  145. $nodes[$record->nid]->db_name = $record->name;
  146. $nodes[$record->nid]->db_path = $record->path;
  147. $nodes[$record->nid]->title = $record->name;
  148. $nodes[$record->nid]->db_dbtype = $record->dbtype;
  149. }
  150. }