tripal_project.module 7.8 KB

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