tripal_cv.module 11 KB

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