tripal_cv.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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/cv/edit/%'] = 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', 6),
  82. 'access callback' => 'user_access',
  83. 'access arguments' => array('administer controlled vocabularies'),
  84. 'type' => MENU_CALLBACK,
  85. );
  86. $items['admin/tripal/chado/tripal_cv/cv/add'] = 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/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',5),
  103. 'access arguments' => array('administer controlled vocabularies'),
  104. 'type' => MENU_CALLBACK,
  105. );
  106. $items['admin/tripal/chado/tripal_cv/cvterm/add'] = array(
  107. 'title' => 'Add a Controlled Vocabulary Term',
  108. 'description' => 'Add a new controlled vocabulary term.',
  109. 'page callback' => 'drupal_get_form',
  110. 'page arguments' => array('tripal_cv_cvterm_add_form'),
  111. 'access arguments' => array('administer controlled vocabularies'),
  112. 'type' => MENU_CALLBACK,
  113. );
  114. $items['admin/tripal/chado/tripal_cv/cv/%/cvterm/edit/%'] = array(
  115. 'title' => 'Edit a Controlled Vocabulary Term',
  116. 'description' => 'Edit an existing controlled vocabulary term.',
  117. 'page callback' => 'drupal_get_form',
  118. 'page arguments' => array('tripal_cv_cvterm_edit_form',5,8),
  119. 'access arguments' => array('administer controlled vocabularies'),
  120. 'type' => MENU_CALLBACK,
  121. );
  122. $items['admin/tripal/chado/tripal_cv/cvterm/auto_name/%/%'] = array(
  123. 'page callback' => 'tripal_cv_cvterm_name_autocomplete',
  124. 'page arguments' => array(5, 6),
  125. 'access arguments' => array('administer controlled vocabularies'),
  126. 'type' => MENU_CALLBACK,
  127. );
  128. /*
  129. * Charts
  130. */
  131. $items['tripal_cv_chart'] = array(
  132. 'path' => 'tripal_cv_chart',
  133. 'page callback' => 'tripal_cv_chart',
  134. 'page arguments' => array(1),
  135. 'access arguments' => array('access content'),
  136. 'type' => MENU_CALLBACK
  137. );
  138. /*
  139. * Menu items for enabling views
  140. */
  141. $items['admin/tripal/chado/tripal_cv/views/cvs/enable'] = array(
  142. 'title' => 'Enable Vocabulary Administrative View',
  143. 'page callback' => 'tripal_views_admin_enable_view',
  144. 'page arguments' => array('tripal_cv_admin_cvs', 'admin/tripal/chado/tripal_cv'),
  145. 'access arguments' => array('administer controlled vocabularies'),
  146. 'type' => MENU_CALLBACK,
  147. );
  148. $items['admin/tripal/chado/tripal_cv/views/cvterms/enable'] = array(
  149. 'title' => 'Enable Vocabulary Terms Administrative View',
  150. 'page callback' => 'tripal_views_admin_enable_view',
  151. 'page arguments' => array('tripal_cv_admin_cvterms', 'admin/tripal/chado/tripal_cv'),
  152. 'access arguments' => array('administer controlled vocabularies'),
  153. 'type' => MENU_CALLBACK,
  154. );
  155. /*
  156. * Menu items for working with CV Trees
  157. */
  158. $items['cv_browser'] = array(
  159. 'page callback' => 'tripal_cv_show_browser',
  160. 'access arguments' => array('access content'),
  161. 'type' => MENU_CALLBACK
  162. );
  163. $items['tripal_cv_tree'] = array(
  164. 'path' => 'tripal_cv_tree',
  165. 'page callback' => 'tripal_cv_tree',
  166. 'page arguments' => array(1),
  167. 'access arguments' => array('access content'),
  168. 'type' => MENU_CALLBACK
  169. );
  170. $items['tripal_cv_init_browser'] = array(
  171. 'path' => 'tripal_cv_init_browser',
  172. 'page callback' => 'tripal_cv_init_browser',
  173. 'page arguments' => array(1),
  174. 'access arguments' => array('access content'),
  175. 'type' => MENU_CALLBACK
  176. );
  177. // menu item for interaction with the tree
  178. $items['tripal_cv_update_tree'] = array(
  179. 'path' => 'tripal_cv_update_tree',
  180. 'page callback' => 'tripal_cv_update_tree',
  181. 'page arguments' => array(2, 3),
  182. 'access arguments' => array('access content'),
  183. 'type' => MENU_CALLBACK
  184. );
  185. // menu items for working with terms
  186. $items['tripal_cv_cvterm_info'] = array(
  187. 'path' => 'tripal_cv_cvterm_info',
  188. 'title' => 'CV Term Viewer',
  189. 'page callback' => 'tripal_cv_cvterm_info',
  190. 'page arguments' => array(1),
  191. 'access arguments' => array('access content'),
  192. 'type' => MENU_CALLBACK
  193. );
  194. return $items;
  195. }
  196. /**
  197. * Implements hook_help()
  198. * Purpose: Adds a help page to the module list
  199. */
  200. function tripal_cv_help ($path, $arg) {
  201. if ($path == 'admin/help#tripal_cv') {
  202. return theme('tripal_cv_help', array());
  203. }
  204. }
  205. /**
  206. * Set the permission types that the chado module uses. Essentially we
  207. * want permissionis that protect creation, editing and deleting of chado
  208. * data objects
  209. *
  210. * @ingroup tripal_cv
  211. */
  212. function tripal_cv_permission() {
  213. return array(
  214. 'administer controlled vocabularies' => array(
  215. 'title' => t('Administer controlled vocabularies (CVs).'),
  216. 'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
  217. ),
  218. );
  219. }
  220. /**
  221. * Implements hook_views_api()
  222. * Purpose: Essentially this hook tells drupal that there is views support for
  223. * for this module which then includes tripal_cv.views.inc where all the
  224. * views integration code is
  225. *
  226. * @ingroup tripal_cv
  227. */
  228. function tripal_cv_views_api() {
  229. return array('api' => 2.0);
  230. }
  231. /**
  232. * Implements hook_coder_ignore().
  233. * Defines the path to the file (tripal_cv.coder_ignores.txt) where ignore rules for coder are stored
  234. */
  235. function tripal_cv_coder_ignore() {
  236. return array(
  237. 'path' => drupal_get_path('module', 'tripal_cv'),
  238. 'line prefix' => drupal_get_path('module', 'tripal_cv'),
  239. );
  240. }
  241. /*
  242. *
  243. */
  244. function tripal_cv_form_alter(&$form, &$form_state, $form_id) {
  245. if ($form_id == "tripal_cv_cvterm_form") {
  246. // updating the form through the ahah callback sets the action of
  247. // the form to the ahah callback URL. We need to set it back
  248. // to the normal form URL
  249. if ($form_state['values']['form_action'] == 'edit') {
  250. $form['#action'] = url("admin/tripal/tripal_cv/cvterm/edit");
  251. }
  252. else {
  253. $form['#action'] = url("admin/tripal/tripal_cv/cvterm/add");
  254. }
  255. }
  256. }
  257. /**
  258. * We need to let drupal know about our theme functions and their arguments.
  259. * We create theme functions to allow users of the module to customize the
  260. * look and feel of the output generated in this module
  261. *
  262. * @ingroup tripal_db
  263. */
  264. function tripal_cv_theme() {
  265. $theme_path = drupal_get_path('module', 'tripal_cv') . '/theme';
  266. $items = array(
  267. 'tripal_cv_help' => array(
  268. 'template' => 'tripal_cv_help',
  269. 'arguments' => array(NULL),
  270. 'path' => $theme_path,
  271. ),
  272. );
  273. return $items;
  274. }