tripal_cv.module 10 KB

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