tripal_project.module 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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(
  112. 'create tripal_project',
  113. 'edit own tripal_project'
  114. );
  115. }
  116. /**
  117. * Implements hook_access()
  118. *
  119. * This function sets the access permission for operations on the database.
  120. *
  121. * @parm $op
  122. * The operation that is to be performed
  123. *
  124. * @parm $node
  125. * The specific node that is to have the operation performed
  126. *
  127. * @parm $account
  128. * The account of the user that is performing the operations
  129. *
  130. * @return
  131. * True if a operation was performed
  132. *
  133. */
  134. function tripal_project_access($op, $node, $account) {
  135. if ($op == 'create') {
  136. // Only users with permission to do so may create this node type.
  137. if(!user_access('create tripal_project', $account)){
  138. return FALSE;
  139. }
  140. }
  141. // Users who create a node may edit or delete it later, assuming they have the necessary permissions.
  142. if ($op == 'update' || $op == 'delete') {
  143. if(!user_access('edit own tripal_project',$account){
  144. return FALSE;
  145. }
  146. if(user_access('edit own tripal_project',$account) &&
  147. $account->uid != $node->uid){
  148. return FALSE;
  149. }
  150. }
  151. return NULL;
  152. }
  153. /**
  154. * Implementation of hook_insert()
  155. *
  156. * @parm $node
  157. * Then node that has the information stored within, accessed given the node-Id
  158. *
  159. */
  160. function tripal_project_insert($node) {
  161. $values = array(
  162. 'name' => $node->title,
  163. 'description' => $node->body,
  164. );
  165. //inserts info into chado table.
  166. $result = tripal_core_chado_insert('project',$values);
  167. //inserts the row of vid,nid,project_id into the chado_project table
  168. db_query("INSERT INTO {chado_project} (vid, nid, project_id) VALUES (%d, %d, %d)", $node->vid, $node->nid, $result['project_id']);
  169. }
  170. /**
  171. *
  172. * Implementation of hook_delete().
  173. *
  174. * @param $node
  175. * The node which is to be deleted, automagically by Drupal Black Box
  176. *
  177. */
  178. function tripal_project_delete($node) {
  179. // Notice that we're matching all revision, by using the node's nid.
  180. $values = array(
  181. 'name' => $node->title,
  182. 'description' => $node->body,
  183. );
  184. //deleting row in chado table
  185. tripal_core_chado_delete('project',$values);
  186. //deleteing in drupal chado_project table
  187. db_query('DELETE FROM {chado_project} WHERE nid = %d', $node->nid);
  188. }
  189. /**
  190. * Implements hook_update()
  191. *
  192. * @param $node
  193. * The node which is to have its containing information updated when the user modifys information
  194. * pertaining to the specific project
  195. *
  196. */
  197. function tripal_project_update($node){
  198. $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
  199. $match= array(
  200. 'project_id'=>$result->project_id,
  201. );
  202. $values = array(
  203. 'name' => $node->title,
  204. 'description' => $node->body,
  205. );
  206. //selects:$table, $match, $value when updating
  207. $result = tripal_core_chado_update('project',$match,$values);
  208. }
  209. /**
  210. * Implementation of tripal_project_load().
  211. *
  212. * @param $node
  213. * The node that is to have its containing infromation loaded
  214. *
  215. * @return $node
  216. * The node, containing the loaded project with the current node-Id
  217. *
  218. */
  219. function tripal_project_load($node) {
  220. //selecting the coresponding table information
  221. $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
  222. //assigning the project-Id to a variable
  223. $values = array(
  224. 'project_id' => $result->project_id,
  225. );
  226. //the current project set to the 'project' with the $values(project-Id)
  227. $node->project = tripal_core_generate_chado_var('project',$values);
  228. return $node;
  229. }
  230. //-----------------------------------------------------------------------------
  231. // END OF SOFTWARE
  232. //-----------------------------------------------------------------------------