tripal_project.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. * @file
  8. * This file contains the basic functions needed for this drupal module.
  9. * The drupal tripal_project module maps directly to the chado general module.
  10. *
  11. * For documentation regarding the Chado General module:
  12. * @see http://gmod.org/wiki/Chado_General_Module
  13. *
  14. * @defgroup tripal_project Project Module
  15. * @ingroup tripal_modules
  16. */
  17. /**
  18. * Implementation of hook_node_info().
  19. *
  20. * This node_info, is a simple node that describes the functionallity of the module. It specifies
  21. * that the title(Project Name) and body(Description) set to true so that they information can be
  22. * entered
  23. *
  24. *
  25. * @ingroup tripal_project
  26. */
  27. function tripal_project_node_info() {
  28. return array(
  29. 'chado_project' => array(
  30. 'name' => t('Project'),
  31. 'base' => 'chado_project',
  32. 'description' => t('A project from the Chado database'),
  33. 'has_title' => TRUE,
  34. 'title_label' => t('Project Name'),
  35. 'had_body' => TRUE,
  36. 'body_label' => t('Full Description'),
  37. 'chado_node_api' => array(
  38. 'base_table' => 'project',
  39. 'hook_prefix' => 'chado_project',
  40. 'record_type_title' => array(
  41. 'singular' => t('Project'),
  42. 'plural' => t('Projects')
  43. ),
  44. 'sync_filters' => array(
  45. 'type_id' => FALSE,
  46. 'organism_id' => FALSE
  47. ),
  48. ),
  49. ),
  50. );
  51. }
  52. /**
  53. * Implements hook_views_api()
  54. *
  55. * Purpose: Essentially this hook tells drupal that there is views support for
  56. * for this module which then includes tripal_project.views.inc where all the
  57. * views integration code is
  58. *
  59. * @ingroup tripal_project
  60. *
  61. */
  62. function tripal_project_views_api() {
  63. return array(
  64. 'api' => 2.0,
  65. );
  66. }
  67. /**
  68. * Implements hook_menu
  69. *
  70. * @ingroup tripal_project
  71. */
  72. function tripal_project_menu() {
  73. $items[ 'admin/tripal/chado/tripal_project' ]= array(
  74. 'title' => 'Projects',
  75. 'description' => ('A project. Can be used for grouping data such as with the natural diversity module data.'),
  76. 'page callback' => 'tripal_project_admin_project_view',
  77. 'access arguments' => array('adminster tripal projects'),
  78. 'type' => MENU_NORMAL_ITEM
  79. );
  80. $items['admin/tripal/chado/tripal_project/help']= array(
  81. 'title' => 'Help',
  82. 'description' => ("Basic Description of Tripal Project Module Functionality."),
  83. 'page callback' => 'theme',
  84. 'page arguments' => array('tripal_project_help'),
  85. 'access arguments' => array('adminster tripal projects'),
  86. 'type' => MENU_LOCAL_TASK,
  87. 'weight' => 6
  88. );
  89. $items['admin/tripal/chado/tripal_project/configuration']= array(
  90. 'title' => 'Settings',
  91. 'page callback' => 'drupal_get_form',
  92. 'page arguments' => array('tripal_project_admin'),
  93. 'access arguments' => array('adminster tripal projects'),
  94. 'type' => MENU_LOCAL_TASK,
  95. 'weight' => 4
  96. );
  97. $items['admin/tripal/chado/tripal_project/sync'] = array(
  98. 'title' => ' Sync',
  99. 'description' => 'Create pages on this site for projects stored in Chado',
  100. 'page callback' => 'drupal_get_form',
  101. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_project', 'chado_project'),
  102. 'access arguments' => array('administer tripal projects'),
  103. 'type' => MENU_LOCAL_TASK,
  104. 'weight' => 0
  105. );
  106. $items['admin/tripal/chado/tripal_project/views/projects/enable'] = array(
  107. 'title' => 'Enable Project Administrative View',
  108. 'page callback' => 'tripal_views_admin_enable_view',
  109. 'page arguments' => array('tripal_project_admin_projects', 'admin/tripal/chado/tripal_project'),
  110. 'access arguments' => array('administer tripal projects'),
  111. 'type' => MENU_CALLBACK,
  112. );
  113. return $items;
  114. }
  115. /**
  116. * Implements hook_help()
  117. * Purpose: Adds a help page to the module list
  118. */
  119. function tripal_project_help ($path, $arg) {
  120. if ($path == 'admin/help#tripal_project') {
  121. return theme('tripal_project_help', array());
  122. }
  123. }
  124. /**
  125. * Implements hook_perm()
  126. *
  127. * This function sets the permission for the user to access the information in the database.
  128. * This includes creating, inserting, deleting and updating of information in the database
  129. *
  130. *
  131. * @ingroup tripal_project
  132. */
  133. function tripal_project_permission() {
  134. return array(
  135. 'access chado_project content' => array(
  136. 'title' => t('View Projects'),
  137. 'description' => t('Allow users to view project pages.'),
  138. ),
  139. 'create chado_project content' => array(
  140. 'title' => t('Create Projects'),
  141. 'description' => t('Allow users to create new project pages.'),
  142. ),
  143. 'delete chado_project content' => array(
  144. 'title' => t('Delete Projects'),
  145. 'description' => t('Allow users to delete project pages.'),
  146. ),
  147. 'edit chado_project content' => array(
  148. 'title' => t('Edit Projects'),
  149. 'description' => t('Allow users to edit project pages.'),
  150. ),
  151. 'adminster tripal project' => array(
  152. 'title' => t('Administer Projects'),
  153. 'description' => t('Allow users to administer all projects.'),
  154. ),
  155. );
  156. }
  157. /**
  158. * We need to let drupal know about our theme functions and their arguments.
  159. * We create theme functions to allow users of the module to customize the
  160. * look and feel of the output generated in this module
  161. *
  162. * @ingroup tripal_project
  163. */
  164. function tripal_project_theme($existing, $type, $theme, $path) {
  165. $core_path = drupal_get_path('module', 'tripal_core');
  166. $items = array(
  167. 'node__chado_project' => array(
  168. 'template' => 'node--chado-generic',
  169. 'render element' => 'node',
  170. 'base hook' => 'node',
  171. 'path' => "$core_path/theme",
  172. ),
  173. 'tripal_project_base' => array(
  174. 'variables' => array('node' => NULL),
  175. 'template' => 'tripal_project.base',
  176. 'path' => "$path/theme/tripal_project",
  177. ),
  178. 'tripal_project_contact' => array(
  179. 'variables' => array('node' => NULL),
  180. 'template' => 'tripal_project.contact',
  181. 'path' => "$path/theme/tripal_project",
  182. ),
  183. 'tripal_project_properties' => array(
  184. 'variables' => array('node' => NULL),
  185. 'template' => 'tripal_project.properties',
  186. 'path' => "$path/theme/tripal_project",
  187. ),
  188. 'tripal_project_publications' => array(
  189. 'variables' => array('node' => NULL),
  190. 'template' => 'tripal_project.publications',
  191. 'path' => "$path/theme/tripal_project",
  192. ),
  193. 'tripal_project_relationships' => array(
  194. 'variables' => array('node' => NULL),
  195. 'template' => 'tripal_project.relationships',
  196. 'path' => "$path/theme/tripal_project",
  197. ),
  198. 'tripal_project_teaser' => array(
  199. 'variables' => array('node' => NULL),
  200. 'template' => 'tripal_project.teaser',
  201. 'path' => "$path/theme/tripal_project",
  202. ),
  203. 'tripal_project_help' => array(
  204. 'variables' => 'tripal_project.help',
  205. 'variables' => array(NULL),
  206. 'path' => "$path/theme",
  207. ),
  208. );
  209. return $items;
  210. }
  211. /**
  212. *
  213. * @ingroup tripal_feature
  214. */
  215. function tripal_project_node_view($node, $view_mode, $langcode) {
  216. switch ($node->type) {
  217. case 'chado_project':
  218. // Show feature browser and counts
  219. if ($view_mode == 'full') {
  220. $node->content['tripal_project_base'] = array(
  221. '#value' => theme('tripal_project_base', array('node' => $node)),
  222. );
  223. $node->content['tripal_project_contact'] = array(
  224. '#value' => theme('tripal_project_contact', array('node' => $node)),
  225. );
  226. $node->content['tripal_project_properties'] = array(
  227. '#value' => theme('tripal_project_properties', array('node' => $node)),
  228. );
  229. $node->content['tripal_project_publications'] = array(
  230. '#value' => theme('tripal_project_publications', array('node' => $node)),
  231. );
  232. $node->content['tripal_project_relationships'] = array(
  233. '#value' => theme('tripal_project_relationships', array('node' => $node)),
  234. );
  235. }
  236. if ($view_mode == 'teaser') {
  237. $node->content['tripal_project_teaser'] = array(
  238. '#value' => theme('tripal_project_teaser', array('node' => $node)),
  239. );
  240. }
  241. break;
  242. }
  243. }
  244. /**
  245. *
  246. * @ingroup tripal_project
  247. */
  248. function tripal_project_block_info() {
  249. $blocks['projectbase']['info'] = t('Tripal Project Details');
  250. $blocks['projectbase']['cache'] = DRUPAL_NO_CACHE;
  251. $blocks['projectprops']['info'] = t('Tripal Project Properties');
  252. $blocks['projectprops']['cache'] = DRUPAL_NO_CACHE;
  253. $blocks['projectpubs']['info'] = t('Tripal Project Publications');
  254. $blocks['projectpubs']['cache'] = DRUPAL_NO_CACHE;
  255. $blocks['projectcont']['info'] = t('Tripal Project Contact');
  256. $blocks['projectcont']['cache'] = DRUPAL_NO_CACHE;
  257. $blocks['projectrels']['info'] = t('Tripal Project Relationships');
  258. $blocks['projectrels']['cache'] = DRUPAL_NO_CACHE;
  259. return $blocks;
  260. }
  261. /**
  262. *
  263. * @ingroup tripal_project
  264. */
  265. function tripal_project_block_view($delta = '') {
  266. if (user_access('access chado_project content') and arg(0) == 'node' and is_numeric(arg(1))) {
  267. $nid = arg(1);
  268. $node = node_load($nid);
  269. $block = array();
  270. switch ($delta) {
  271. case 'projectbase':
  272. $block['subject'] = t('Project Details');
  273. $block['content'] = theme('tripal_project_base', $node);
  274. break;
  275. case 'projectprops':
  276. $block['subject'] = t('Properties');
  277. $block['content'] = theme('tripal_project_properties', $node);
  278. break;
  279. case 'projectpubs':
  280. $block['subject'] = t('Publications');
  281. $block['content'] = theme('tripal_project_publications', $node);
  282. break;
  283. case 'projectcont':
  284. $block['subject'] = t('Contact');
  285. $block['content'] = theme('tripal_project_contact', $node);
  286. break;
  287. case 'projectrels':
  288. $block['subject'] = t('Relationships');
  289. $block['content'] = theme('tripal_project_relationships', $node);
  290. break;
  291. default :
  292. }
  293. return $block;
  294. }
  295. }
  296. /**
  297. * Implementation of hook_form_alter()
  298. *
  299. * @param $form
  300. * @param $form_state
  301. * @param $form_id
  302. */
  303. function tripal_project_form_alter(&$form, &$form_state, $form_id) {
  304. // turn of preview button for insert/updates
  305. if ($form_id == "chado_project_node_form") {
  306. $form['actions']['preview']['#access'] = FALSE;
  307. }
  308. }