tripal_project.module 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions needed for this drupal module.
  5. * The drupal tripal_project module maps directly to the chado general module.
  6. *
  7. * For documentation regarding the Chado General module:
  8. * @see http://gmod.org/wiki/Chado_General_Module
  9. */
  10. //-----------------------------------------------------------------------------
  11. // SECTION: Main Outline for Tripal Project Module
  12. //-----------------------------------------------------------------------------
  13. /**
  14. * Implements hook_views_api()
  15. *
  16. * Purpose: Essentially this hook tells drupal that there is views support for
  17. * for this module which then includes tripal_project.views.inc where all the
  18. * views integration code is
  19. *
  20. */
  21. function tripal_project_views_api() {
  22. return array(
  23. 'api' => 2.0,
  24. );
  25. }
  26. /**
  27. * Implementation of hook_node_info()
  28. *
  29. * This node_info, is a simple node that describes the functionallity of the module. It specifies
  30. * that the title(Project Name) and body(Description) set to true so that they information can be
  31. * entered
  32. *
  33. */
  34. function tripal_project_node_info() {
  35. return array(
  36. 'tripal_project' => array(
  37. 'name' => t('Project'),
  38. 'module' => 'tripal_project',
  39. 'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of projects'),
  40. 'has_title' => TRUE,
  41. 'title_label' =>t('Project Name'),
  42. 'had_body' => TRUE,
  43. 'body_label' =>t('Description'),
  44. )
  45. );
  46. }
  47. /**
  48. * Implementation of hook_form().
  49. *
  50. * This form takes the Project Title infromation and the Project description from the user. It
  51. * then puts the infromation into the Chado_project database table.
  52. *
  53. * @parm &$node
  54. * The node that is created when the database is initialized
  55. *
  56. * @parm $form_state
  57. * The state of the form, that has the user entered information that is neccessary for, setting
  58. * up the database of the project
  59. *
  60. * @return $form
  61. * The information that was enterd allong with
  62. *
  63. */
  64. function tripal_project_form(&$node, $form_state) {
  65. $type = node_get_types('type', $node);
  66. //define form elements for the node's title and body.
  67. $form['title'] = array(
  68. '#type' => 'textfield',
  69. '#title' => check_plain($type->title_label),
  70. '#required' => TRUE,
  71. '#default_value' => $node->title,
  72. '#weight' => -5
  73. );
  74. // Putting body and filter elements to be adjacent them into a sub-array together
  75. $form['body_filter']['body'] = array(
  76. '#type' => 'textarea',
  77. '#title' => check_plain($type->body_label),
  78. '#default_value' => $node->body,
  79. '#required' => FALSE
  80. );
  81. $form['body_filter']['filter'] = filter_form($node->format);
  82. return $form;
  83. }
  84. /**
  85. * Implements Hook_help()
  86. *
  87. * This function simply states, in HTML tags, the creator of the the module and the contact
  88. * for the programmer
  89. *
  90. * @parm $path
  91. * The absolute path of the module and help information
  92. *
  93. * @parm $arg
  94. * The argument
  95. */
  96. function tripal_project_help($path, $arg) {
  97. switch ($path) {
  98. case 'admin/help#tripal_project':
  99. return '<p>'. t('Module created by:Chad Krilow (e-mail:cnk046@mail.usask.ca)') .'</p>';
  100. break;
  101. }
  102. }
  103. /**
  104. * Implements hook_perm()
  105. *
  106. * This function sets the permission for the user to access the information in the database.
  107. * This includes creating, inserting, deleting and updating of information in the database
  108. *
  109. */
  110. function tripal_project_perm() {
  111. return array('create tripal_project', 'edit own tripal_project');
  112. }
  113. /**
  114. * Implements hook_access()
  115. *
  116. * This function sets the access permission for operations on the database.
  117. *
  118. * @parm $op
  119. * The operation that is to be performed
  120. *
  121. * @parm $node
  122. * The specific node that is to have the operation performed
  123. *
  124. * @parm $account
  125. * The account of the user that is performing the operations
  126. *
  127. * @return
  128. * True if a operation was performed
  129. *
  130. */
  131. function tripal_project_access($op, $node, $account) {
  132. if ($op == 'create') {
  133. // Only users with permission to do so may create this node type.
  134. return user_access('create tripal_project', $account);
  135. }
  136. // Users who create a node may edit or delete it later, assuming they have the necessary permissions.
  137. if ($op == 'update' || $op == 'delete') {
  138. if (user_access('edit own tripal_project',$account) && ($account->uid == $node->uid)) {
  139. return TRUE;
  140. }
  141. }
  142. }
  143. /**
  144. * Implementation of hook_insert()
  145. *
  146. * @parm $node
  147. * Then node that has the information stored within, accessed given the node-Id
  148. *
  149. */
  150. function tripal_project_insert($node) {
  151. $values = array(
  152. 'name' => $node->title,
  153. 'description' => $node->body,
  154. );
  155. //inserts info into chado table.
  156. $result = tripal_core_chado_insert('project',$values);
  157. //inserts the row of vid,nid,project_id into the chado_project table
  158. db_query("INSERT INTO {chado_project} (vid, nid, project_id) VALUES (%d, %d, %d)", $node->vid, $node->nid, $result['project_id']);
  159. }
  160. /**
  161. *
  162. * Implementation of hook_delete().
  163. *
  164. * @param $node
  165. * The node which is to be deleted, automagically by Drupal Black Box
  166. *
  167. */
  168. function tripal_project_delete($node) {
  169. // Notice that we're matching all revision, by using the node's nid.
  170. $values = array(
  171. 'name' => $node->title,
  172. 'description' => $node->body,
  173. );
  174. //deleting row in chado table
  175. tripal_core_chado_delete('project',$values);
  176. //deleteing in drupal chado_project table
  177. db_query('DELETE FROM {chado_project} WHERE nid = %d', $node->nid);
  178. }
  179. /**
  180. * Implements hook_update()
  181. *
  182. * @param $node
  183. * The node which is to have its containing information updated when the user modifys information
  184. * pertaining to the specific project
  185. *
  186. */
  187. function tripal_project_update($node){
  188. $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
  189. $match= array(
  190. 'project_id'=>$result->project_id,
  191. );
  192. $values = array(
  193. 'name' => $node->title,
  194. 'description' => $node->body,
  195. );
  196. //selects:$table, $match, $value when updating
  197. $result = tripal_core_chado_update('project',$match,$values);
  198. }
  199. /**
  200. * Implementation of tripal_project_load().
  201. *
  202. * @param $node
  203. * The node that is to have its containing infromation loaded
  204. *
  205. * @return $node
  206. * The node, containing the loaded project with the current node-Id
  207. *
  208. */
  209. function tripal_project_load($node) {
  210. //selecting the coresponding table information
  211. $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
  212. //assigning the project-Id to a variable
  213. $values = array(
  214. 'project_id' => $result->project_id,
  215. );
  216. //the current project set to the 'project' with the $values(project-Id)
  217. $node->project = tripal_core_generate_chado_var('project',$values);
  218. return $node;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // END OF SOFTWARE
  222. //-----------------------------------------------------------------------------