tripal_project.module 8.2 KB

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