tripal_project.module 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. * @file
  4. * Integrates the Chado Project tables with Drupal Nodes & Views
  5. */
  6. require 'api/tripal_project.api.inc';
  7. require 'theme/tripal_project.theme.inc';
  8. require 'includes/tripal_project.admin.inc';
  9. require '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('adminster 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('adminster 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('adminster 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('tripal_core_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_views_admin_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_help().
  81. * Adds a help page to the module list
  82. *
  83. * @ingroup tripal_project
  84. */
  85. function tripal_project_help ($path, $arg) {
  86. if ($path == 'admin/help#tripal_project') {
  87. return theme('tripal_project_help', array());
  88. }
  89. }
  90. /**
  91. * Implements hook_permission()
  92. *
  93. * This function sets the permission for the user to access the information in the database.
  94. * This includes creating, inserting, deleting and updating of information in the database
  95. *
  96. * @ingroup tripal_project
  97. */
  98. function tripal_project_permission() {
  99. return array(
  100. 'access chado_project content' => array(
  101. 'title' => t('View Projects'),
  102. 'description' => t('Allow users to view project pages.'),
  103. ),
  104. 'create chado_project content' => array(
  105. 'title' => t('Create Projects'),
  106. 'description' => t('Allow users to create new project pages.'),
  107. ),
  108. 'delete chado_project content' => array(
  109. 'title' => t('Delete Projects'),
  110. 'description' => t('Allow users to delete project pages.'),
  111. ),
  112. 'edit chado_project content' => array(
  113. 'title' => t('Edit Projects'),
  114. 'description' => t('Allow users to edit project pages.'),
  115. ),
  116. 'adminster tripal project' => array(
  117. 'title' => t('Administer Projects'),
  118. 'description' => t('Allow users to administer all projects.'),
  119. ),
  120. );
  121. }
  122. /**
  123. * Implements hook_theme().
  124. *
  125. * We need to let drupal know about our theme functions and their arguments.
  126. * We create theme functions to allow users of the module to customize the
  127. * look and feel of the output generated in this module
  128. *
  129. * @ingroup tripal_project
  130. */
  131. function tripal_project_theme($existing, $type, $theme, $path) {
  132. $core_path = drupal_get_path('module', 'tripal_core');
  133. $items = array(
  134. 'node__chado_project' => array(
  135. 'template' => 'node--chado-generic',
  136. 'render element' => 'node',
  137. 'base hook' => 'node',
  138. 'path' => "$core_path/theme",
  139. ),
  140. 'tripal_project_base' => array(
  141. 'variables' => array('node' => NULL),
  142. 'template' => 'tripal_project_base',
  143. 'path' => "$path/theme/tripal_project",
  144. ),
  145. 'tripal_project_contact' => array(
  146. 'variables' => array('node' => NULL),
  147. 'template' => 'tripal_project_contact',
  148. 'path' => "$path/theme/tripal_project",
  149. ),
  150. 'tripal_project_properties' => array(
  151. 'variables' => array('node' => NULL),
  152. 'template' => 'tripal_project_properties',
  153. 'path' => "$path/theme/tripal_project",
  154. ),
  155. 'tripal_project_publications' => array(
  156. 'variables' => array('node' => NULL),
  157. 'template' => 'tripal_project_publications',
  158. 'path' => "$path/theme/tripal_project",
  159. ),
  160. 'tripal_project_relationships' => array(
  161. 'variables' => array('node' => NULL),
  162. 'template' => 'tripal_project_relationships',
  163. 'path' => "$path/theme/tripal_project",
  164. ),
  165. 'tripal_project_teaser' => array(
  166. 'variables' => array('node' => NULL),
  167. 'template' => 'tripal_project_teaser',
  168. 'path' => "$path/theme/tripal_project",
  169. ),
  170. 'tripal_project_help' => array(
  171. 'variables' => 'tripal_project_help',
  172. 'variables' => array(NULL),
  173. 'path' => "$path/theme",
  174. ),
  175. );
  176. return $items;
  177. }
  178. /**
  179. * Implements hook_block_info().
  180. *
  181. * @ingroup tripal_project
  182. */
  183. function tripal_project_block_info() {
  184. $blocks['projectbase']['info'] = t('Tripal Project Details');
  185. $blocks['projectbase']['cache'] = DRUPAL_NO_CACHE;
  186. $blocks['projectprops']['info'] = t('Tripal Project Properties');
  187. $blocks['projectprops']['cache'] = DRUPAL_NO_CACHE;
  188. $blocks['projectpubs']['info'] = t('Tripal Project Publications');
  189. $blocks['projectpubs']['cache'] = DRUPAL_NO_CACHE;
  190. $blocks['projectcont']['info'] = t('Tripal Project Contact');
  191. $blocks['projectcont']['cache'] = DRUPAL_NO_CACHE;
  192. $blocks['projectrels']['info'] = t('Tripal Project Relationships');
  193. $blocks['projectrels']['cache'] = DRUPAL_NO_CACHE;
  194. return $blocks;
  195. }
  196. /**
  197. * Implements hook_block_view().
  198. *
  199. * @ingroup tripal_project
  200. */
  201. function tripal_project_block_view($delta = '') {
  202. if (user_access('access chado_project content') and arg(0) == 'node' and is_numeric(arg(1))) {
  203. $nid = arg(1);
  204. $node = node_load($nid);
  205. $block = array();
  206. switch ($delta) {
  207. case 'projectbase':
  208. $block['subject'] = t('Project Details');
  209. $block['content'] = theme('tripal_project_base', $node);
  210. break;
  211. case 'projectprops':
  212. $block['subject'] = t('Properties');
  213. $block['content'] = theme('tripal_project_properties', $node);
  214. break;
  215. case 'projectpubs':
  216. $block['subject'] = t('Publications');
  217. $block['content'] = theme('tripal_project_publications', $node);
  218. break;
  219. case 'projectcont':
  220. $block['subject'] = t('Contact');
  221. $block['content'] = theme('tripal_project_contact', $node);
  222. break;
  223. case 'projectrels':
  224. $block['subject'] = t('Relationships');
  225. $block['content'] = theme('tripal_project_relationships', $node);
  226. break;
  227. default :
  228. }
  229. return $block;
  230. }
  231. }
  232. /**
  233. * Implementation of hook_form_alter().
  234. *
  235. * @param $form
  236. * @param $form_state
  237. * @param $form_id
  238. *
  239. * @ingroup tripal_project
  240. */
  241. function tripal_project_form_alter(&$form, &$form_state, $form_id) {
  242. // turn of preview button for insert/updates
  243. if ($form_id == "chado_project_node_form") {
  244. $form['actions']['preview']['#access'] = FALSE;
  245. }
  246. }