tripal_cv.module 11 KB

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