tripal_project.module 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * @file
  4. * Integrates the Chado Project tables with Drupal Nodes & Views
  5. */
  6. require_once 'api/tripal_project.DEPRECATED.inc';
  7. require_once 'theme/tripal_project.theme.inc';
  8. require_once 'includes/tripal_project.admin.inc';
  9. require_once 'includes/tripal_project.chado_node.inc';
  10. /**
  11. * @defgroup tripal_project Project Module
  12. * @ingroup tripal_modules
  13. * @{
  14. * Integrates the Chado Project tables with Drupal Nodes & Views
  15. * @}
  16. */
  17. /**
  18. * Implements hook_views_api().
  19. *
  20. * Essentially this hook tells drupal that there is views support for
  21. * for this module which then includes tripal_project.views.inc where all the
  22. * views integration code is
  23. *
  24. * @ingroup tripal_project
  25. */
  26. function tripal_project_views_api() {
  27. return array(
  28. 'api' => 3.0,
  29. );
  30. }
  31. /**
  32. * Implements hook_menu().
  33. *
  34. * @ingroup tripal_project
  35. */
  36. function tripal_project_menu() {
  37. $items[ 'admin/tripal/chado/tripal_project' ]= array(
  38. 'title' => 'Projects',
  39. 'description' => ('A project. Can be used for grouping data such as with the natural diversity module data.'),
  40. 'page callback' => 'tripal_project_admin_project_view',
  41. 'access arguments' => array('administer tripal project'),
  42. 'type' => MENU_NORMAL_ITEM
  43. );
  44. $items['admin/tripal/chado/tripal_project/help']= array(
  45. 'title' => 'Help',
  46. 'description' => ("Basic Description of Tripal Project Module Functionality."),
  47. 'page callback' => 'theme',
  48. 'page arguments' => array('tripal_project_help'),
  49. 'access arguments' => array('administer tripal project'),
  50. 'type' => MENU_LOCAL_TASK,
  51. 'weight' => 6
  52. );
  53. $items['admin/tripal/chado/tripal_project/configuration']= array(
  54. 'title' => 'Settings',
  55. 'page callback' => 'drupal_get_form',
  56. 'page arguments' => array('tripal_project_admin'),
  57. 'access arguments' => array('administer tripal project'),
  58. 'type' => MENU_LOCAL_TASK,
  59. 'weight' => 4
  60. );
  61. $items['admin/tripal/chado/tripal_project/sync'] = array(
  62. 'title' => ' Sync',
  63. 'description' => 'Create pages on this site for projects stored in Chado',
  64. 'page callback' => 'drupal_get_form',
  65. 'page arguments' => array('chado_node_sync_form', 'tripal_project', 'chado_project'),
  66. 'access arguments' => array('administer tripal project'),
  67. 'type' => MENU_LOCAL_TASK,
  68. 'weight' => 0
  69. );
  70. $items['admin/tripal/chado/tripal_project/views/projects/enable'] = array(
  71. 'title' => 'Enable Project Administrative View',
  72. 'page callback' => 'tripal_enable_view',
  73. 'page arguments' => array('tripal_project_admin_projects', 'admin/tripal/chado/tripal_project'),
  74. 'access arguments' => array('administer tripal project'),
  75. 'type' => MENU_CALLBACK,
  76. );
  77. return $items;
  78. }
  79. /**
  80. * Implements hook_search_biological_data_views().
  81. *
  82. * Adds the described views to the "Search Data" Page created by Tripal Views
  83. */
  84. function tripal_project_search_biological_data_views() {
  85. return array(
  86. 'tripal_project_user_projects' => array(
  87. 'machine_name' => 'tripal_project_user_projects',
  88. 'human_name' => 'Projects',
  89. 'description' => 'A project. Can be used for grouping data such as with the natural diversity module data.',
  90. 'link' => 'chado/project'
  91. ),
  92. );
  93. }
  94. /**
  95. * Implements hook_help().
  96. * Adds a help page to the module list
  97. *
  98. * @ingroup tripal_project
  99. */
  100. function tripal_project_help ($path, $arg) {
  101. if ($path == 'admin/help#tripal_project') {
  102. return theme('tripal_project_help', array());
  103. }
  104. }
  105. /**
  106. * Implements hook_permission()
  107. *
  108. * This function sets the permission for the user to access the information in the database.
  109. * This includes creating, inserting, deleting and updating of information in the database
  110. *
  111. * @ingroup tripal_project
  112. */
  113. function tripal_project_permission() {
  114. return array(
  115. 'access chado_project content' => array(
  116. 'title' => t('View Projects'),
  117. 'description' => t('Allow users to view project pages.'),
  118. ),
  119. 'create chado_project content' => array(
  120. 'title' => t('Create Projects'),
  121. 'description' => t('Allow users to create new project pages.'),
  122. ),
  123. 'delete chado_project content' => array(
  124. 'title' => t('Delete Projects'),
  125. 'description' => t('Allow users to delete project pages.'),
  126. ),
  127. 'edit chado_project content' => array(
  128. 'title' => t('Edit Projects'),
  129. 'description' => t('Allow users to edit project pages.'),
  130. ),
  131. 'administer tripal project' => array(
  132. 'title' => t('Administer Projects'),
  133. 'description' => t('Allow users to administer all projects.'),
  134. ),
  135. );
  136. }
  137. /**
  138. * Implements hook_theme().
  139. *
  140. * We need to let drupal know about our theme functions and their arguments.
  141. * We create theme functions to allow users of the module to customize the
  142. * look and feel of the output generated in this module
  143. *
  144. * @ingroup tripal_project
  145. */
  146. function tripal_project_theme($existing, $type, $theme, $path) {
  147. $core_path = drupal_get_path('module', 'tripal_core');
  148. $items = array(
  149. 'node__chado_project' => array(
  150. 'template' => 'node--chado-generic',
  151. 'render element' => 'node',
  152. 'base hook' => 'node',
  153. 'path' => "$core_path/theme/templates",
  154. ),
  155. 'tripal_project_base' => array(
  156. 'variables' => array('node' => NULL),
  157. 'template' => 'tripal_project_base',
  158. 'path' => "$path/theme/templates",
  159. ),
  160. 'tripal_project_contact' => array(
  161. 'variables' => array('node' => NULL),
  162. 'template' => 'tripal_project_contact',
  163. 'path' => "$path/theme/templates",
  164. ),
  165. 'tripal_project_properties' => array(
  166. 'variables' => array('node' => NULL),
  167. 'template' => 'tripal_project_properties',
  168. 'path' => "$path/theme/templates",
  169. ),
  170. 'tripal_project_publications' => array(
  171. 'variables' => array('node' => NULL),
  172. 'template' => 'tripal_project_publications',
  173. 'path' => "$path/theme/templates",
  174. ),
  175. 'tripal_project_relationships' => array(
  176. 'variables' => array('node' => NULL),
  177. 'template' => 'tripal_project_relationships',
  178. 'path' => "$path/theme/templates",
  179. ),
  180. 'tripal_project_teaser' => array(
  181. 'variables' => array('node' => NULL),
  182. 'template' => 'tripal_project_teaser',
  183. 'path' => "$path/theme/templates",
  184. ),
  185. 'tripal_project_help' => array(
  186. 'variables' => 'tripal_project_help',
  187. 'variables' => array(NULL),
  188. 'path' => "$path/theme/templates",
  189. ),
  190. );
  191. return $items;
  192. }
  193. /**
  194. * Implements hook_block_info().
  195. *
  196. * @ingroup tripal_project
  197. */
  198. function tripal_project_block_info() {
  199. $blocks['projectbase']['info'] = t('Tripal Project Details');
  200. $blocks['projectbase']['cache'] = DRUPAL_NO_CACHE;
  201. $blocks['projectprops']['info'] = t('Tripal Project Properties');
  202. $blocks['projectprops']['cache'] = DRUPAL_NO_CACHE;
  203. $blocks['projectpubs']['info'] = t('Tripal Project Publications');
  204. $blocks['projectpubs']['cache'] = DRUPAL_NO_CACHE;
  205. $blocks['projectcont']['info'] = t('Tripal Project Contact');
  206. $blocks['projectcont']['cache'] = DRUPAL_NO_CACHE;
  207. $blocks['projectrels']['info'] = t('Tripal Project Relationships');
  208. $blocks['projectrels']['cache'] = DRUPAL_NO_CACHE;
  209. return $blocks;
  210. }
  211. /**
  212. * Implements hook_block_view().
  213. *
  214. * @ingroup tripal_project
  215. */
  216. function tripal_project_block_view($delta = '') {
  217. if (user_access('access chado_project content') and arg(0) == 'node' and is_numeric(arg(1))) {
  218. $nid = arg(1);
  219. $node = node_load($nid);
  220. $block = array();
  221. switch ($delta) {
  222. case 'projectbase':
  223. $block['subject'] = t('Project Details');
  224. $block['content'] = theme('tripal_project_base', $node);
  225. break;
  226. case 'projectprops':
  227. $block['subject'] = t('Properties');
  228. $block['content'] = theme('tripal_project_properties', $node);
  229. break;
  230. case 'projectpubs':
  231. $block['subject'] = t('Publications');
  232. $block['content'] = theme('tripal_project_publications', $node);
  233. break;
  234. case 'projectcont':
  235. $block['subject'] = t('Contact');
  236. $block['content'] = theme('tripal_project_contact', $node);
  237. break;
  238. case 'projectrels':
  239. $block['subject'] = t('Relationships');
  240. $block['content'] = theme('tripal_project_relationships', $node);
  241. break;
  242. default :
  243. }
  244. return $block;
  245. }
  246. }
  247. /**
  248. * Implementation of hook_form_alter().
  249. *
  250. * @param $form
  251. * @param $form_state
  252. * @param $form_id
  253. *
  254. * @ingroup tripal_project
  255. */
  256. function tripal_project_form_alter(&$form, &$form_state, $form_id) {
  257. if ($form_id == "chado_project_node_form") {
  258. // turn of preview button for insert/updates
  259. $form['actions']['preview']['#access'] = FALSE;
  260. //remove the body field
  261. unset($form['body']);
  262. }
  263. }