tripal_cv.module 9.7 KB

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