tripal_cv.module 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. require_once "charts.php";
  3. require_once "trees.php";
  4. //
  5. // Copyright 2009 Clemson University
  6. //
  7. /*************************************************************************
  8. *
  9. */
  10. function tripal_cv_init(){
  11. // add the tripal_cv JS and CSS
  12. drupal_add_css(drupal_get_path('theme', 'tripal').
  13. '/css/tripal_cv.css');
  14. drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_cv.js');
  15. // add the jsTree JS and CSS
  16. drupal_add_css(drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.css');
  17. drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/_lib.js');
  18. drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.js');
  19. }
  20. /*************************************************************************
  21. *
  22. */
  23. function tripal_cv_menu() {
  24. $items = array();
  25. $items['admin/tripal/tripal_cv'] = array(
  26. 'title' => 'CV',
  27. 'description' => 'Manage integration of Chado controlled vocabularies',
  28. 'page callback' => 'drupal_get_form',
  29. 'page arguments' => array('tripal_cv_admin'),
  30. 'access arguments' => array('administer site configuration'),
  31. 'type' => MENU_NORMAL_ITEM,
  32. );
  33. $items['tripal_cv_chart'] = array(
  34. 'path' => 'tripal_cv_chart',
  35. 'title' => t('CV Chart'),
  36. 'page callback' => 'tripal_cv_chart',
  37. 'page arguments' => array(1),
  38. 'access arguments' => array('access content'),
  39. 'type' => MENU_CALLBACK
  40. );
  41. $items['tripal_cv_tree'] = array(
  42. 'path' => 'tripal_cv_tree',
  43. 'title' => t('CV Term Viewer'),
  44. 'page callback' => 'tripal_cv_tree',
  45. 'page arguments' => array(1),
  46. 'access arguments' => array('access content'),
  47. 'type' => MENU_CALLBACK
  48. );
  49. // menu items for working with the CV module tree browser
  50. /*
  51. $items['cv_browser'] = array(
  52. 'title' => t('CV Relationship Browser'),
  53. 'page callback' => 'tripal_cv_show_browser',
  54. 'access arguments' => array('access chado_cv content'),
  55. 'type' => MENU_NORMAL_ITEM
  56. );
  57. */
  58. $items['tripal_cv_init_browser'] = array(
  59. 'path' => 'tripal_cv_init_browser',
  60. 'title' => t('CV Browser'),
  61. 'page callback' => 'tripal_cv_init_browser',
  62. 'page arguments' => array(1),
  63. 'access arguments' => array('access content'),
  64. 'type' => MENU_CALLBACK
  65. );
  66. // menu item for interaction with the tree
  67. $items['tripal_cv_update_tree'] = array(
  68. 'path' => 'tripal_cv_update_tree',
  69. 'title' => t('CV Tree'),
  70. 'page callback' => 'tripal_cv_update_tree',
  71. 'page arguments' => array(2,3),
  72. 'access arguments' => array('access content'),
  73. 'type' => MENU_CALLBACK
  74. );
  75. // menu items for working with terms
  76. $items['tripal_cv_cvterm_info'] = array(
  77. 'path' => 'tripal_cv_cvterm_info',
  78. 'title' => t('CV Term Viewer'),
  79. 'page callback' => 'tripal_cv_cvterm_info',
  80. 'page arguments' => array(1),
  81. 'access arguments' => array('access content'),
  82. 'type' => MENU_CALLBACK
  83. );
  84. $items['tripal_cv_cvterm_edit'] = array(
  85. 'path' => 'tripal_cv_edit',
  86. 'title' => t('CV Term Editor'),
  87. 'page callback' => 'tripal_cv_cvterm_edit',
  88. 'page arguments' => array(1),
  89. 'access arguments' => array('edit chado_cv content'),
  90. 'type' => MENU_CALLBACK
  91. );
  92. return $items;
  93. }
  94. /*******************************************************************************
  95. * The following function proves access control for users trying to
  96. * perform actions on data managed by this module
  97. */
  98. function chado_cv_access($op, $node, $account){
  99. if ($op == 'create') {
  100. return user_access('create chado_cv content', $account);
  101. }
  102. if ($op == 'update') {
  103. if (user_access('edit chado_cv content', $account)) {
  104. return TRUE;
  105. }
  106. }
  107. if ($op == 'delete') {
  108. if (user_access('delete chado_cv content', $account)) {
  109. return TRUE;
  110. }
  111. }
  112. if ($op == 'view') {
  113. if (user_access('access chado_cv content', $account)) {
  114. return TRUE;
  115. }
  116. }
  117. return FALSE;
  118. }
  119. /*******************************************************************************
  120. * Set the permission types that the chado module uses. Essentially we
  121. * want permissionis that protect creation, editing and deleting of chado
  122. * data objects
  123. */
  124. function tripal_cv_perm(){
  125. return array(
  126. 'access chado_cv content',
  127. 'create chado_cv content',
  128. 'delete chado_cv content',
  129. 'edit chado_cv content',
  130. );
  131. }
  132. /*************************************************************************
  133. *
  134. */
  135. function tripal_cv_admin () {
  136. $form['update_cvtermpath'] = array(
  137. '#type' => 'fieldset',
  138. '#title' => t('Chado cvtermpath')
  139. );
  140. $form['update_cvtermpath']['description'] = array(
  141. '#type' => 'item',
  142. '#value' => t("Submit a job to update chado cvtermpath table."),
  143. '#weight' => 1,
  144. );
  145. $form['update_cvtermpath']['button'] = array(
  146. '#type' => 'submit',
  147. '#value' => t('Update cvtermpath'),
  148. '#weight' => 2,
  149. );
  150. return system_settings_form($form);
  151. }
  152. /*************************************************************************
  153. *
  154. */
  155. function tripal_cv_admin_validate($form, &$form_state) {
  156. global $user;
  157. // -------------------------------------
  158. // Submit a job to update cvtermpath
  159. $job_args = array();
  160. if ($form_state['values']['op'] == t('Update cvtermpath')) {
  161. tripal_add_job('Update cvtermpath','tripal_cv',
  162. 'tripal_cv_update_cvtermpath',$job_args,$user->uid);
  163. }
  164. }
  165. /***********************************************************
  166. * Update the cvtermpath table
  167. */
  168. function tripal_cv_update_cvtermpath($dummy = NULL, $job_id = NULL) {
  169. print "\nUpdating cvtermpath...\n";
  170. $previous_db = db_set_active('chado');
  171. $sql = "SELECT * FROM fill_cvtermpath('biological_process')";
  172. db_query($sql);
  173. $sql = "SELECT * FROM fill_cvtermpath('molecular_function')";
  174. db_query($sql);
  175. $sql = "SELECT * FROM fill_cvtermpath('cellular_component')";
  176. db_query($sql);
  177. db_set_active($previous_db);
  178. return;
  179. }
  180. /*******************************************************************************
  181. * We need to let drupal know about our theme functions and their arguments.
  182. * We create theme functions to allow users of the module to customize the
  183. * look and feel of the output generated in this module
  184. */
  185. function tripal_cv_theme () {
  186. return array(
  187. 'tripal_cv_cvterm_edit' => array (
  188. 'arguments' => array('cvterm'),
  189. ),
  190. );
  191. }
  192. /*************************************************************************
  193. */
  194. function tripal_cv_get_cv_id($cv_name){
  195. $sql = "
  196. SELECT cv_id FROM {cv} WHERE name = '%s'
  197. ";
  198. $previous_db = db_set_active('chado');
  199. $cv = db_fetch_object(db_query($sql,$cv_name));
  200. db_set_active($previous_db);
  201. return $cv->cv_id;
  202. }
  203. /*************************************************************************
  204. *
  205. */
  206. function tripal_cv_cvterm_edit($cvterm_id){
  207. $sql = "
  208. SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname
  209. FROM {CVTerm} CVT
  210. INNER JOIN CV on CVT.cv_id = CV.cv_id
  211. WHERE CVT.cvterm_id = %d
  212. ";
  213. $previous_db = db_set_active('chado');
  214. $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
  215. db_set_active($previous_db);
  216. return theme('tripal_cv_cvterm_edit',$cvterm);
  217. }
  218. /*************************************************************************
  219. *
  220. */
  221. function theme_tripal_cv_cvterm_edit(&$cvterm){
  222. $output = "
  223. <div id=\"cvterm\">
  224. <table>
  225. <tr><th>Term</th><td>$cvterm->cvtermname</td></tr>
  226. <tr><th>Vocabulary</th><td>$cvterm->cvname</td></tr>
  227. <tr><th>Definition</th><td>$cvterm->definition</td></tr>
  228. </table>
  229. </div>
  230. ";
  231. return $output;
  232. }