blast_ui.node.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. x<?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 Name'),
  70. '#required' => TRUE,
  71. '#default_value' => isset($node->db_path) ? $node->db_path : '',
  72. );
  73. return $form;
  74. }
  75. /**
  76. *
  77. * Implements hook_insert()
  78. *
  79. */
  80. function blastdb_insert($node) {
  81. db_insert('blastdb')->fields(array(
  82. 'nid' => $node->nid,
  83. 'name' => $node->db_name,
  84. 'path' => $node->db_path,
  85. ))->execute();
  86. }
  87. /**
  88. * Implements hook_node_insert().
  89. * This function acts on ALL NODES
  90. */
  91. function blastdb_node_insert($node) {
  92. if ($node->type == 'blastdb') {
  93. }
  94. }
  95. /**
  96. *
  97. * Implements hook_update()
  98. *
  99. */
  100. function blastdb_update($node) {
  101. dpm($node, 'node in module-specific insert');
  102. db_update('blastdb')->fields(array(
  103. 'name' => $node->db_name,
  104. 'path' => $node->db_path,
  105. ))->condition('nid', $node->nid)->execute();
  106. }
  107. /**
  108. * Implements hook_node_update().
  109. * This function acts on ALL NODES
  110. */
  111. function blastdb_node_update($node) {
  112. if ($node->type == 'blastdb') {
  113. }
  114. }
  115. /**
  116. *
  117. * Implements hook_delete()
  118. *
  119. */
  120. function blastdb_delete($node) {
  121. db_delete('blastdb')->condition('nid',$node->nid)->execute();
  122. }
  123. /**
  124. *
  125. * Implements hook_load()
  126. *
  127. */
  128. function blastdb_load($nodes) {
  129. $result = db_query('SELECT nid, name, path FROM {blastdb} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
  130. foreach ($result as $record) {
  131. $nodes[$record->nid]->db_name = $record->name;
  132. $nodes[$record->nid]->db_path = $record->path;
  133. $nodes[$record->nid]->title = $record->name;
  134. }
  135. }