tripal_cv.module 11 KB

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