tripal_project.module 8.1 KB

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