tripal_cv.module 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. require_once "includes/charts.inc";
  3. require_once "includes/trees.inc";
  4. require_once "includes/obo_loader.inc";
  5. require_once "api/tripal_cv.api.inc";
  6. require_once "includes/cv_form.inc";
  7. require_once "includes/cvterm_form.inc";
  8. require_once "includes/cvtermpath_form.inc";
  9. /**
  10. * @defgroup tripal_cv CV Module
  11. * @ingroup tripal_modules
  12. */
  13. /**
  14. * Implements hook_init().
  15. * Adds CSS and JS needed for this modules rendered content
  16. *
  17. * @ingroup tripal_cv
  18. */
  19. function tripal_cv_init() {
  20. // add the tripal_cv JS and CSS
  21. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_cv.css');
  22. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_cv.js');
  23. // add the jgCharts.js
  24. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jgcharts/jgcharts.js');
  25. // add the jsTree JS and CSS
  26. drupal_add_css(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/tree_component.css');
  27. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/_lib.js');
  28. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/tree_component.js');
  29. }
  30. /**
  31. * Implements hook_menu().
  32. * Registers all menu items associated with this module
  33. *
  34. * @ingroup tripal_cv
  35. */
  36. function tripal_cv_menu() {
  37. $items = array();
  38. $items['admin/tripal/chado/tripal_cv'] = array(
  39. 'title' => 'Controlled Vocabularies',
  40. 'description' => 'Controlled Vocabularies control the terms available for various chado fields.',
  41. 'access arguments' => array('administer controlled vocabularies'),
  42. 'type' => MENU_NORMAL_ITEM,
  43. );
  44. $items['admin/tripal/chado/tripal_cv/help'] = array(
  45. 'title' => 'Help',
  46. 'description' => "A description of the Tripal Controlled Vocabulary module including a short description of it's usage.",
  47. 'page callback' => 'theme',
  48. 'page arguments' => array('tripal_cv_admin'),
  49. 'access arguments' => array('administer controlled vocabularies'),
  50. 'type' => MENU_NORMAL_ITEM,
  51. 'weight' => 10
  52. );
  53. $items['admin/tripal/chado/tripal_cv/obo_loader'] = array(
  54. 'title' => 'Load Ontology',
  55. 'description' => 'Load an Ontology into chado as a controlled vocabulary.',
  56. 'page callback' => 'drupal_get_form',
  57. 'page arguments' => array('tripal_cv_obo_form'),
  58. 'access arguments' => array('administer controlled vocabularies'),
  59. 'type' => MENU_NORMAL_ITEM,
  60. );
  61. /*
  62. * Menu for updating the cvtermpath
  63. */
  64. $items['admin/tripal/chado/tripal_cv/cvtermpath'] = array(
  65. 'title' => 'Update Chado cvtermpath table',
  66. 'description' => 'The Chado cvtermpath table provides lineage for terms and is useful for quickly finding any ancestor parent of a term. However, this table must be populated. This page allows for populating of this table one vocabulary at a time',
  67. 'page callback' => 'drupal_get_form',
  68. 'page arguments' => array('tripal_cv_cvtermpath_form'),
  69. 'access arguments' => array('administer controlled vocabularies'),
  70. 'type' => MENU_NORMAL_ITEM,
  71. );
  72. /*
  73. * Menu items for adding and editing CVs
  74. */
  75. $items['admin/tripal/chado/tripal_cv/edit_cv'] = array(
  76. 'title' => 'Edit a Controlled Vocabulary',
  77. 'description' => 'Edit the details such as name and description for an existing controlled vocabulary.',
  78. 'page callback' => 'drupal_get_form',
  79. 'page arguments' => array('tripal_cv_cv_edit_form'),
  80. 'access callback' => 'user_access',
  81. 'access arguments' => array('administer controlled vocabularies'),
  82. 'type' => MENU_NORMAL_ITEM,
  83. );
  84. $items['admin/tripal/chado/tripal_cv/add_cv'] = array(
  85. 'title' => 'Add a Controlled Vocabulary',
  86. 'description' => 'Manually a new controlled vocabulary.',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_cv_cv_add_form'),
  89. 'access callback' => 'user_access',
  90. 'access arguments' => array('administer controlled vocabularies'),
  91. 'type' => MENU_NORMAL_ITEM,
  92. );
  93. /*
  94. * Menu items for adding and editing CVterms
  95. */
  96. $items['admin/tripal/chado/tripal_cv/cvterm/add'] = array(
  97. 'title' => 'Add a Controlled Vocabulary Term',
  98. 'description' => 'Add a new controlled vocabulary term.',
  99. 'page callback' => 'drupal_get_form',
  100. 'page arguments' => array('tripal_cv_cvterm_add_form'),
  101. 'access arguments' => array('administer controlled vocabularies'),
  102. 'type' => MENU_NORMAL_ITEM,
  103. );
  104. $items['admin/tripal/chado/tripal_cv/cvterm/edit'] = array(
  105. 'title' => 'Edit a Controlled Vocabulary Term',
  106. 'description' => 'Edit an existing controlled vocabulary term.',
  107. 'page callback' => 'drupal_get_form',
  108. 'page arguments' => array('tripal_cv_cvterm_edit_form'),
  109. 'access arguments' => array('administer controlled vocabularies'),
  110. 'type' => MENU_NORMAL_ITEM,
  111. );
  112. $items['admin/tripal/chado/tripal_cv/cvterm/auto_name/%/%'] = array(
  113. 'page callback' => 'tripal_cv_cvterm_name_autocomplete',
  114. 'page arguments' => array(5, 6),
  115. 'access arguments' => array('administer controlled vocabularies'),
  116. 'type' => MENU_CALLBACK,
  117. );
  118. /*
  119. * Charts
  120. */
  121. $items['tripal_cv_chart'] = array(
  122. 'path' => 'tripal_cv_chart',
  123. 'page callback' => 'tripal_cv_chart',
  124. 'page arguments' => array(1),
  125. 'access arguments' => array('access content'),
  126. 'type' => MENU_CALLBACK
  127. );
  128. /*
  129. * Menu items for working with CV Trees
  130. */
  131. $items['cv_browser'] = array(
  132. 'page callback' => 'tripal_cv_show_browser',
  133. 'access arguments' => array('access content'),
  134. 'type' => MENU_CALLBACK
  135. );
  136. $items['tripal_cv_tree'] = array(
  137. 'path' => 'tripal_cv_tree',
  138. 'page callback' => 'tripal_cv_tree',
  139. 'page arguments' => array(1),
  140. 'access arguments' => array('access content'),
  141. 'type' => MENU_CALLBACK
  142. );
  143. $items['tripal_cv_init_browser'] = array(
  144. 'path' => 'tripal_cv_init_browser',
  145. 'page callback' => 'tripal_cv_init_browser',
  146. 'page arguments' => array(1),
  147. 'access arguments' => array('access content'),
  148. 'type' => MENU_CALLBACK
  149. );
  150. // menu item for interaction with the tree
  151. $items['tripal_cv_update_tree'] = array(
  152. 'path' => 'tripal_cv_update_tree',
  153. 'page callback' => 'tripal_cv_update_tree',
  154. 'page arguments' => array(2, 3),
  155. 'access arguments' => array('access content'),
  156. 'type' => MENU_CALLBACK
  157. );
  158. // menu items for working with terms
  159. $items['tripal_cv_cvterm_info'] = array(
  160. 'path' => 'tripal_cv_cvterm_info',
  161. 'title' => 'CV Term Viewer',
  162. 'page callback' => 'tripal_cv_cvterm_info',
  163. 'page arguments' => array(1),
  164. 'access arguments' => array('access content'),
  165. 'type' => MENU_CALLBACK
  166. );
  167. return $items;
  168. }
  169. /**
  170. * Implements hook_help()
  171. * Purpose: Adds a help page to the module list
  172. */
  173. function tripal_cv_help ($path, $arg) {
  174. if ($path == 'admin/help#tripal_cv') {
  175. return theme('tripal_cv_admin', array());
  176. }
  177. }
  178. /**
  179. * Set the permission types that the chado module uses. Essentially we
  180. * want permissionis that protect creation, editing and deleting of chado
  181. * data objects
  182. *
  183. * @ingroup tripal_cv
  184. */
  185. function tripal_cv_permission() {
  186. return array(
  187. 'administer controlled vocabularies' => array(
  188. 'title' => t('Administer controlled vocabularies (CVs).'),
  189. 'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
  190. ),
  191. );
  192. }
  193. /**
  194. * Implements hook_views_api()
  195. * Purpose: Essentially this hook tells drupal that there is views support for
  196. * for this module which then includes tripal_cv.views.inc where all the
  197. * views integration code is
  198. *
  199. * @ingroup tripal_cv
  200. */
  201. function tripal_cv_views_api() {
  202. return array('api' => 2.0);
  203. }
  204. /**
  205. * Implements hook_coder_ignore().
  206. * Defines the path to the file (tripal_cv.coder_ignores.txt) where ignore rules for coder are stored
  207. */
  208. function tripal_cv_coder_ignore() {
  209. return array(
  210. 'path' => drupal_get_path('module', 'tripal_cv'),
  211. 'line prefix' => drupal_get_path('module', 'tripal_cv'),
  212. );
  213. }
  214. /*
  215. *
  216. */
  217. function tripal_cv_form_alter(&$form, &$form_state, $form_id) {
  218. if ($form_id == "tripal_cv_cvterm_form") {
  219. // updating the form through the ahah callback sets the action of
  220. // the form to the ahah callback URL. We need to set it back
  221. // to the normal form URL
  222. if ($form_state['values']['form_action'] == 'edit') {
  223. $form['#action'] = url("admin/tripal/tripal_cv/cvterm/edit");
  224. }
  225. else {
  226. $form['#action'] = url("admin/tripal/tripal_cv/cvterm/add");
  227. }
  228. }
  229. }
  230. /**
  231. * We need to let drupal know about our theme functions and their arguments.
  232. * We create theme functions to allow users of the module to customize the
  233. * look and feel of the output generated in this module
  234. *
  235. * @ingroup tripal_db
  236. */
  237. function tripal_cv_theme() {
  238. return array(
  239. 'tripal_cv_admin' => array(
  240. 'template' => 'tripal_cv_admin',
  241. 'arguments' => array(NULL),
  242. 'path' => drupal_get_path('module', 'tripal_cv') . '/theme',
  243. ),
  244. );
  245. }