blast_ui.node.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @file
  4. * Contains all functions for creating the blastdb node type
  5. */
  6. /**
  7. * Implements hook_node_info().
  8. */
  9. function blast_ui_node_info() {
  10. return array(
  11. 'blastdb' => array(
  12. 'name' => t('Blast Database'),
  13. 'base' => 'blastdb',
  14. 'description' => t('Registers a BLAST Database for use with the BLAST UI.'),
  15. ),
  16. );
  17. }
  18. /**
  19. * Implements hook_node_access().
  20. */
  21. function blastdb_node_access($node, $op, $account) {
  22. $node_type = $node;
  23. if (is_object($node)) {
  24. $node_type = $node->type;
  25. }
  26. if($node_type == 'blastdb') {
  27. if ($op == 'create') {
  28. if (!user_access('create Blast Database', $account)) {
  29. return NODE_ACCESS_DENY;
  30. }
  31. return NODE_ACCESS_ALLOW;
  32. }
  33. if ($op == 'update') {
  34. if (!user_access('edit Blast Database', $account)) {
  35. return NODE_ACCESS_DENY;
  36. }
  37. }
  38. if ($op == 'delete') {
  39. if (!user_access('delete Blast Database', $account)) {
  40. return NODE_ACCESS_DENY;
  41. }
  42. }
  43. if ($op == 'view') {
  44. if (!user_access('access Blast Database', $account)) {
  45. return NODE_ACCESS_DENY;
  46. }
  47. }
  48. return NODE_ACCESS_IGNORE;
  49. }
  50. }
  51. /**
  52. * Form constructor for the blastdb node
  53. *
  54. * @see blastdb_insert()
  55. * @see blastdb_update()
  56. * @see blastdb_delete()
  57. * @see blastdb_load()
  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. * Implements hook_insert().
  88. */
  89. function blastdb_insert($node) {
  90. db_insert('blastdb')->fields(array(
  91. 'nid' => $node->nid,
  92. 'name' => $node->db_name,
  93. 'path' => $node->db_path,
  94. 'dbtype' => $node->db_dbtype,
  95. ))->execute();
  96. }
  97. /**
  98. * Implements hook_node_insert().
  99. * This function acts on ALL NODES
  100. */
  101. function blast_ui_node_insert($node) {
  102. if ($node->type == 'blastdb') {
  103. $node->title = $node->db_name;
  104. }
  105. }
  106. /**
  107. * Implements hook_update().
  108. */
  109. function blastdb_update($node) {
  110. db_update('blastdb')->fields(array(
  111. 'name' => $node->db_name,
  112. 'path' => $node->db_path,
  113. 'dbtype' => $node->db_dbtype,
  114. ))->condition('nid', $node->nid)->execute();
  115. }
  116. /**
  117. * Implements hook_node_update().
  118. * This function acts on ALL NODES
  119. */
  120. function blast_ui_node_update($node) {
  121. if ($node->type == 'blastdb') {
  122. $node->title = $node->db_name;
  123. }
  124. }
  125. /**
  126. * Implements hook_delete().
  127. */
  128. function blastdb_delete($node) {
  129. db_delete('blastdb')->condition('nid',$node->nid)->execute();
  130. }
  131. /**
  132. * Implements hook_load() .
  133. */
  134. function blastdb_load($nodes) {
  135. $result = db_query('SELECT nid, name, path, dbtype FROM {blastdb} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
  136. foreach ($result as $record) {
  137. $nodes[$record->nid]->db_name = $record->name;
  138. $nodes[$record->nid]->db_path = $record->path;
  139. $nodes[$record->nid]->title = $record->name;
  140. $nodes[$record->nid]->db_dbtype = $record->dbtype;
  141. }
  142. }