123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- <?php
- /**
- * @defgroup tripal_library Library Module
- * @ingroup tripal_modules
- * @{
- * Provides functions for managing chado libraries including creating details pages for each library
- * @}
- */
- require('api/tripal_library.api.inc');
- require('theme/tripal_library.theme.inc');
- require('includes/tripal_library.admin.inc');
- require('includes/tripal_library.chado_node.inc');
- /**
- * Provide information to drupal about the node types that we're creating
- * in this module
- *
- * @ingroup tripal_library
- */
- function tripal_library_node_info() {
- $nodes = array();
- $nodes['chado_library'] = array(
- 'name' => t('Library'),
- 'base' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Library'),
- 'has_body' => FALSE,
- 'locked' => TRUE,
- 'chado_node_api' => array(
- 'base_table' => 'library',
- 'hook_prefix' => 'chado_library',
- 'record_type_title' => array(
- 'singular' => t('Library'),
- 'plural' => t('Libraries')
- ),
- 'sync_filters' => array(
- 'type_id' => TRUE,
- 'organism_id' => TRUE
- ),
- )
- );
- return $nodes;
- }
- /**
- * Set the permission types that the chado module uses. Essentially we
- * want permissionis that protect creation, editing and deleting of chado
- * data objects
- *
- * @ingroup tripal_library
- */
- function tripal_library_permisssions() {
- return array(
- 'access chado_library content' => array(
- 'title' => t('View Libraries'),
- 'description' => t('Allow users to view library pages.'),
- ),
- 'create chado_library content' => array(
- 'title' => t('Create Libraries'),
- 'description' => t('Allow users to create new library pages.'),
- ),
- 'delete chado_library content' => array(
- 'title' => t('Delete Libraries'),
- 'description' => t('Allow users to delete library pages.'),
- ),
- 'edit chado_library content' => array(
- 'title' => t('Edit Libraries'),
- 'description' => t('Allow users to edit library pages.'),
- ),
- 'adminster tripal library' => array(
- 'title' => t('Administer Libraries'),
- 'description' => t('Allow users to administer all libraries.'),
- ),
- );
- }
- /**
- * Menu items are automatically added for the new node types created
- * by this module to the 'Create Content' Navigation menu item. This function
- * adds more menu items needed for this module.
- *
- * @ingroup tripal_library
- */
- function tripal_library_menu() {
- $items = array();
- // The administative settings menu
- $items['admin/tripal/chado/tripal_library'] = array(
- 'title' => 'Libraries',
- 'description' => 'Any biological library. Examples of genomic libraries include BAC, cDNA, FOSMID, etc.',
- 'page callback' => 'tripal_library_admin_libraries_listing',
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/chado/tripal_library/help'] = array(
- 'title' => 'Help',
- 'description' => 'Basic Description of Tripal Library Module Functionality',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_library_help'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10
- );
- $items['admin/tripal/chado/tripal_library/configuration'] = array(
- 'title' => 'Settings',
- 'description' => 'Configure the Tripal Library module',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_library_admin'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 5
- );
- $items['admin/tripal/chado/tripal_library/sync'] = array(
- 'title' => ' Sync',
- 'description' => 'Create pages on this site for libraries stored in Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_library', 'chado_library'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 0
- );
- return $items;
- // Synchronizing libraries from Chado to Drupal
- $items['chado_sync_libraries'] = array(
- 'title' => 'Sync Library Data',
- 'page callback' => 'tripal_library_sync_libraries',
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_CALLBACK
- );
- $items['admin/tripal/chado/tripal_library/views/libraries/enable'] = array(
- 'title' => 'Enable Library Administrative View',
- 'page callback' => 'tripal_views_admin_enable_view',
- 'page arguments' => array('tripal_library_admin_libraries', 'admin/tripal/chado/tripal_library'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implements hook_views_api()
- * Purpose: Essentially this hook tells drupal that there is views support for
- * for this module which then includes tripal_db.views.inc where all the
- * views integration code is
- *
- * @ingroup tripal_library
- */
- function tripal_library_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- /**
- * @ingroup tripal_library
- */
- function tripal_library_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_library':
- if ($view_mode == 'full') {
- $node->content['tripal_library_base'] = array(
- '#value' => theme('tripal_library_base', array('node' => $node)),
- );
- $node->content['tripal_library_properties'] = array(
- '#value' => theme('tripal_library_properties', array('node' => $node)),
- );
- $node->content['tripal_library_publications'] = array(
- '#value' => theme('tripal_library_publications', array('node' => $node)),
- );
- $node->content['tripal_library_references'] = array(
- '#value' => theme('tripal_library_references', array('node' => $node)),
- );
- $node->content['tripal_library_synonyms'] = array(
- '#value' => theme('tripal_library_synonyms', array('node' => $node)),
- );
- $node->content['tripal_library_terms'] = array(
- '#value' => theme('tripal_library_terms', array('node' => $node)),
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_library_teaser'] = array(
- '#value' => theme('tripal_library_teaser', array('node' => $node)),
- );
- }
- break;
- case 'chado_organism':
- if ($view_mode == 'full') {
- $node->content['tripal_organism.libraries'] = array(
- '#value' => theme('tripal_organism.libraries', array('node' => $node)),
- );
- }
- break;
- case 'chado_feature':
- if ($view_mode == 'full') {
- $node->content['tripal_feature.libraries'] = array(
- '#value' => theme('tripal_feature.libraries', array('node' => $node)),
- );
- }
- break;
- }
- }
- /**
- * We need to let drupal know about our theme functions and their arguments.
- * We create theme functions to allow users of the module to customize the
- * look and feel of the output generated in this module
- *
- * @ingroup tripal_library
- */
- function tripal_library_theme($existing, $type, $theme, $path) {
- $core_path = drupal_get_path('module', 'tripal_core');
-
- $items = array(
- 'node__chado_library' => array(
- 'template' => 'node--chado-generic',
- 'render element' => 'node',
- 'base hook' => 'node',
- 'path' => "$core_path/theme",
- ),
- // tripal_library templates
- 'tripal_library_base' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.base',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_properties' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.properties',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_publications' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.publications',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_references' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.references',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_synonyms' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.synonyms',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_terms' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.terms',
- 'path' => "$path/theme/tripal_library",
- ),
- 'tripal_library_help' => array(
- 'template' => 'tripal_library.help',
- 'variables' => array(NULL),
- 'path' => "$path/theme",
- ),
-
- // teaser
- 'tripal_library_teaser' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_library.teaser',
- 'path' => "$path/theme/tripal_library",
- ),
-
- // tripal_organism templates
- 'tripal_organism_libraries' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_organism.libraries',
- 'path' => "$path/theme/tripal_organism",
- ),
-
- // tripal_feature templates
- 'tripal_feature_libraries' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature.libraries',
- 'path' => "$path/theme/tripal_feature",
- ),
-
- );
- return $items;
- }
- /**
- * Implements hook_help()
- * Purpose: Adds a help page to the module list
- */
- function tripal_library_help ($path, $arg) {
- if ($path == 'admin/help#tripal_library') {
- return theme('tripal_library_help', array());
- }
- }
- /**
- * @ingroup tripal_library
- */
- function tripal_library_block_info() {
- $blocks['libreferences']['info'] = t('Tripal Library Cross References');
- $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
- $blocks['libbase']['info'] = t('Tripal Library Details');
- $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
- $blocks['libterms']['info'] = t('Tripal Library Terms');
- $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
- $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
- $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
- $blocks['libproperties']['info'] = t('Tripal Library Properties');
- $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
- $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
- $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
- $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
- $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
- return $blocks;
- }
- /**
- * @ingroup tripal_library
- */
- function tripal_library_block_view($delta = '') {
- if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch ($delta) {
- case 'libreferences':
- $block['subject'] = t('Cross References');
- $block['content'] = theme('tripal_library_references', $node);
- break;
- case 'libbase':
- $block['subject'] = t('Library Details');
- $block['content'] = theme('tripal_library_base', $node);
- break;
- case 'libsynonyms':
- $block['subject'] = t('Synonyms');
- $block['content'] = theme('tripal_library_synonyms', $node);
- break;
- case 'libproperties':
- $block['subject'] = t('Properties');
- $block['content'] = theme('tripal_library_properties', $node);
- break;
- case 'libterms':
- $block['subject'] = t('Library Terms');
- $block['content'] = theme('tripal_library_terms', $node);
- break;
- case 'featurelibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_feature_libraries', $node);
- break;
- case 'orglibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_organism_libraries', $node);
- break;
- default :
- }
- return $block;
- }
- }
- /**
- *
- * @ingroup tripal_library
- */
- function tripal_library_cron() {
- }
- /**
- * Implementation of hook_form_alter()
- *
- * @param $form
- * @param $form_state
- * @param $form_id
- */
- function tripal_library_form_alter(&$form, &$form_state, $form_id) {
- // turn of preview button for insert/updates
- if ($form_id == "chado_library_node_form") {
- $form['actions']['preview']['#access'] = FALSE;
- }
- }
- /**
- *
- * @param $node
- */
- function tripal_library_node_presave($node) {
- // if this is a chado_library and the $node->library object is set then we
- // are syncing and we want to set the node title to be the same as the node name
- if ($node->type == 'chado_library' and property_exists($node, 'library')) {
- $node->title = $node->library->name;
- }
- }
|