tripal_cv.module 11 KB

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