tripal_cv.module 11 KB

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