tripal_cv.module 11 KB

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