12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601 |
- <?php
- // APPLICATION PROGRAMMER INTERFACE -------------
- // Chado API
- require_once "api/tripal_chado.api.inc";
- require_once 'api/tripal_chado.property.api.inc';
- require_once 'api/tripal_chado.query.api.inc';
- require_once 'api/tripal_chado.variables.api.inc';
- require_once 'api/tripal_chado.schema.api.inc';
- require_once 'api/tripal_chado.custom_tables.api.inc';
- require_once 'api/tripal_chado.mviews.api.inc';
- require_once 'api/tripal_chado.schema_v1.2.api.inc';
- require_once 'api/tripal_chado.schema_v1.11.api.inc';
- require_once 'api/modules/tripal_chado.analysis.api.inc';
- require_once 'api/modules/tripal_chado.contact.api.inc';
- require_once 'api/modules/tripal_chado.cv.api.inc';
- require_once 'api/modules/tripal_chado.db.api.inc';
- require_once 'api/modules/tripal_chado.feature.api.inc';
- require_once 'api/modules/tripal_chado.organism.api.inc';
- require_once 'api/modules/tripal_chado.pub.api.inc';
- require_once 'api/modules/tripal_chado.stock.api.inc';
- require_once "includes/tripal_chado.entity.inc";
- require_once "includes/tripal_chado.schema.inc";
- require_once "includes/tripal_chado.term_storage.inc";
- require_once "includes/tripal_chado.field_storage.inc";
- tripal_chado_set_globals();
- /**
- * This function is used to set the global Chado variables
- *
- * @ingroup tripal_chado
- */
- function tripal_chado_set_globals() {
- // these global variables are meant to be accessed by all Tripal
- // modules to find the chado version installed and if Chado is local.
- // these variables are stored as globals rather than using the drupal_set_variable
- // functions because the Drupal functions make databaes queries and for long
- // running loaders we don't want those queries repeatedly.
- $GLOBALS["chado_is_installed"] = chado_is_installed();
- if ($GLOBALS["chado_is_installed"]) {
- $GLOBALS["chado_is_local"] = chado_is_local();
- $GLOBALS["chado_version"] = chado_get_version();
- $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
- }
- }
- /**
- * Implements hook_init().
- * Used to set the search_path, create default content and set default variables.
- *
- * @ingroup tripal_chado
- */
- function tripal_chado_init() {
- if ($GLOBALS["chado_is_installed"]) {
- // Check to see if the Chado and Drupal have been prepared
- if (!variable_get('tripal_chado_is_prepared', FALSE)) {
- drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
- l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
- ' before continuing.', 'warning');
- }
- }
- else {
- drupal_set_message('Tripal cannot find a Chado installation. Please ' .
- l('install Chado', 'admin/tripal/storage/chado/chado_install') .
- ' before continuing.', 'warning');
- }
- }
- /**
- * Implements hook_views_api().
- *
- * 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_feature
- */
- function tripal_chado_views_api() {
- return array(
- 'api' => 3.0,
- );
- }
- /**
- * Implements hook_menu().
- */
- function tripal_chado_menu() {
- $items = array();
- $items['admin/tripal/storage/term/%/%'] = array(
- 'page callback' => 'tripal_autocomplete_cvterm',
- 'page arguments' => array(4, 5),
- 'access arguments' => array('administer content'),
- 'type' => MENU_CALLBACK,
- );
- //////////////////////////////////////////////////////////////////////////////
- // Chado Storage Backend
- //////////////////////////////////////////////////////////////////////////////
- $items['admin/tripal/storage/chado'] = array(
- 'title' => 'Chado',
- 'description' => t("Integrates Chado with Tripal and includes tools to
- load data, and extend the chado schema through custom tables &
- materialized views."),
- 'weight' => -100,
- 'access arguments' => array('administer tripal'),
- );
- $items['admin/tripal/storage/chado/chado_install'] = array(
- 'title' => 'Install Chado',
- 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_chado_install_form'),
- 'type' => MENU_NORMAL_ITEM,
- 'access arguments' => array('install chado'),
- 'file' => 'includes/tripal_chado.setup.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => -100
- );
- $items['admin/tripal/storage/chado/chado_prepare'] = array(
- 'title' => 'Prepare Chado',
- 'description' => t('Prepares Drupal to use Chado.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_chado_prepare_form'),
- 'type' => MENU_NORMAL_ITEM,
- 'access arguments' => array('install chado'),
- 'file' => 'includes/tripal_chado.setup.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => -99
- );
- $items['admin/tripal/storage/chado/publish'] = array(
- 'title' => 'Publish',
- 'description' => t('Publish data that is present in Chado but which does
- not yet have a page on this site for viewing. In Tripal v2.0 or
- earlier this was refered to as "syncing".'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_chado_publish_form'),
- 'type' => MENU_NORMAL_ITEM,
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.publish.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => -99
- );
- //////////////////////////////////////////////////////////////////////////////
- // Materialized Views
- //////////////////////////////////////////////////////////////////////////////
- $items['admin/tripal/storage/chado/mviews'] = array(
- 'title' => 'Materialized Views',
- 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
- 'page callback' => 'tripal_mview_admin_view',
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => -10
- );
- $items['admin/tripal/storage/chado/mviews/help'] = array(
- 'title' => 'Help',
- 'description' => t('Help for the materialized views management system'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_mviews_help'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => 10
- );
- $items['admin/tripal/storage/chado/mviews/report/%'] = array(
- 'title' => 'Materialized View',
- 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
- 'page callback' => 'tripal_mview_report',
- 'page arguments' => array(6),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- $items['admin/tripal/storage/chado/mviews/new'] = array(
- 'title' => 'Create Materialized View',
- 'description' => t('Create a new materialized view.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_form'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
- 'title' => 'Edit Materialized View',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_form', 6),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- $items['admin/tripal/storage/chado/mviews/update/%'] = array(
- 'title' => 'Create Materialized View',
- 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
- 'page callback' => 'tripal_mviews_add_populate_job',
- 'page arguments' => array(6),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
- 'title' => 'Create Materialized View',
- 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_delete_form', 5),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- // TODO: complete the code for exporting and importing of MViews.
- // Need to address security issues of sharing SQL.
- $items['admin/tripal/storage/chado/mviews/import'] = array(
- 'title' => 'Import MView',
- 'description' => 'Import a materialized view from another Tripal instance.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_import_form'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
- 'title' => 'Export MView',
- 'description' => 'Export a materialized view for use by another Tripal instance.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_export_form', 5),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/tripal_chado.mviews.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- );
- //////////////////////////////////////////////////////////////////////////////
- // Custom Tables
- //////////////////////////////////////////////////////////////////////////////
- $items['admin/tripal/storage/chado/custom_tables'] = array(
- 'title' => 'Custom Tables',
- 'description' => t('Creation of custom tables that are added to Chado database.'),
- 'page callback' => 'tripal_custom_table_admin_view',
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => -10
- );
- $items['admin/tripal/storage/chado/custom_tables/help'] = array(
- 'title' => 'Help',
- 'description' => t('Help for the tripal job management system'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_job_help'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'weight' => 10
- );
- $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
- 'title' => 'Custom Tables',
- 'description' => t('Custom tables are added to Chado.'),
- 'page callback' => 'tripal_custom_table_view',
- 'page arguments' => array(6),
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/storage/chado/custom_tables/new'] = array(
- 'title' => 'Create Custom Table',
- 'description' => t('An interface for creating your own custom tables.'),
- 'page callback' => 'tripal_custom_table_new_page',
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
- 'title' => 'Edit Custom Table',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_custom_tables_form', 6),
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
- 'title' => 'Create Custom Table',
- 'description' => t('Custom tables are added to Chado.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_custom_tables_delete_form', 6),
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
- 'title' => 'Enable Custom Tables Administrative View',
- 'page callback' => 'tripal_enable_view',
- 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
- 'access arguments' => array('administer tripal'),
- 'file' => 'includes/tripal_chado.custom_tables.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- //////////////////////////////////////////////////////////////////////////////
- // Data Loaders
- //////////////////////////////////////////////////////////////////////////////
- $items['admin/tripal/storage/chado/loaders'] = array(
- 'title' => 'Data Loaders',
- 'description' => t('Tools facilitating data import.'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_NORMAL_ITEM,
- 'weight' => 6
- );
- $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
- 'title' => 'FASTA file Loader',
- 'description' => 'Load sequences from a multi-FASTA file into Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_fasta_load_form'),
- 'access arguments' => array('administer tripal feature'),
- 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
- 'title' => 'GFF3 file Loader',
- 'description' => 'Import a GFF3 file into Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_gff3_load_form'),
- 'access arguments' => array('administer tripal feature'),
- 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_NORMAL_ITEM,
- );
- //////////////////////////////////////////////////////////////////////////////
- // Auto Completes
- //////////////////////////////////////////////////////////////////////////////
- $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
- 'page callback' => 'tripal_autocomplete_dbxref',
- 'page arguments' => array(6, 7),
- 'access arguments' => array('access content'),
- 'file' => 'api/modules/tripal_chado.db.api.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
- 'page callback' => 'tripal_autocomplete_cvterm',
- 'page arguments' => array(6, 7),
- 'access arguments' => array('access content'),
- 'file' => 'api/modules/tripal_chado.db.api.inc',
- 'file path' => drupal_get_path('module', 'tripal_chado'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implements hook_permission().
- *
- * 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
- */
- function tripal_chado_permission() {
- return array(
- 'install chado' => array(
- 'title' => t('Install Chado'),
- 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
- ),
- 'view chado_ids' => array(
- 'title' => t('View Internal IDs'),
- 'description' => t('On content pages Tripal will typically provide
- a table of information pulled from the Chado database but the
- primary key IDs for that data is typically not shown. The
- default Tripal templates can show the primary key ID inside of a
- blue shaded table row if this permission is enabled. This can
- be useful for site developers who might want these IDs when working
- with the underlying database.'),
- 'restrict access' => TRUE,
- )
- );
- }
- /**
- * Implements hook_field_info().
- */
- function tripal_chado_field_info() {
- $fields = array(
- 'organism_id' => array(
- 'label' => t('Organism'),
- 'description' => t('A field for specifying an organism.'),
- 'default_widget' => 'tripal_chado_organism_select_widget',
- 'default_formatter' => 'tripal_chado_organism_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- 'dbxref_id' => array(
- 'label' => t('Cross reference'),
- 'description' => t('This record can be cross referenced with a record in
- another online database. This field is intended for the most prominent
- reference. At a minimum, the database and accession must be provided.'),
- 'default_widget' => 'tripal_chado_dbxref_id_widget',
- 'default_formatter' => 'tripal_chado_dbxref_id_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- 'residues' => array(
- 'label' => t('Residues'),
- 'description' => t('A field for managing nucleotide and protein residues.'),
- 'default_widget' => 'tripal_chado_residue_textarea_widget',
- 'default_formatter' => 'tripal_chado_residues_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- 'md5checksum' => array(
- 'label' => t('MD5 checksum'),
- 'description' => t('A field for generating MD5 checksum for a sequence.'),
- 'default_widget' => 'tripal_chado_md5checksum_checkbox_widget',
- 'default_formatter' => 'tripal_chado_md5checksum_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- 'seqlen' => array(
- 'label' => t('Sequence length'),
- 'description' => t('A field for calculating the length of a sequence.'),
- 'default_widget' => 'tripal_chado_seqlen_hidden_widget',
- 'default_formatter' => 'tripal_chado_seqlen_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- // The field provides a widget for adding new properties
- // to an entity that is connected to a base table that has a prop table
- // in Chado.
- 'kvproperty_adder' => array(
- 'label' => t('Add a Property Type'),
- 'description' => t('This record may have any number of properties. Use
- this field to first add the type.'),
- 'default_widget' => 'tripal_chado_kvproperty_adder_widget',
- //'default_formatter' => 'tripal_chado_kvproperty_adder_formatter',
- 'default_formatter' => 'hidden',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- // The field provides form elements for adding a property to an entity
- // that in turn gets stored in a prop table of Chado (e.g. featureprop,
- // stockprop, etc).
- 'kvproperty' => array(
- 'label' => t('Add a Property'),
- 'description' => t('Add details about this property.'),
- 'default_widget' => 'tripal_chado_kvproperty_widget',
- 'default_formatter' => 'tripal_chado_kvproperty_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- // The field provides form elements for adding multiple dbxrefs to an
- // entity that in turn get stored in a [base]_dbxref table of Chado
- // (e.g. organism_dbxref, feature_dbxref). This is different
- // from the dbxref_id field as that is specific to a dbxref_id in
- // a base table.
- 'dbxref' => array(
- 'label' => t('Cross references'),
- 'description' => t('This record can be cross referenced with a record in
- another online database. This field is intended for one or more
- references. At a minimum, the database and accession must be provided.'),
- 'default_widget' => 'tripal_chado_dbxref_widget',
- 'default_formatter' => 'tripal_chado_dbxref_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- // The field provides a widget for adding new vocabularies for cvterm
- // linker tables. This will allow cvterms to be grouped by vocabulary
- // ('category').
- 'cvterm_class_adder' => array(
- 'label' => t('Add an Annotation Type'),
- 'description' => t('This record may have any number of types of
- annotations. Use this field to first add the type.'),
- 'default_widget' => 'tripal_chado_cvterm_class_adder_widget',
- //'default_formatter' => 'tripal_chado_cvterm_class_adder_formatter',
- 'default_formatter' => 'hidden',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- // The field provides form elements for adding multiple cvterms to an
- // entity that in turn get stored in a [base]_cvterm table of Chado
- // (e.g. feature_cvterm).
- 'cvterm' => array(
- 'label' => t('Annotations'),
- 'description' => t('This record can be annotated with terms
- from other vocabularies.'),
- 'default_widget' => 'tripal_chado_cvterm_widget',
- 'default_formatter' => 'tripal_chado_cvterm_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'field_chado_storage',
- 'module' => 'tripal_chado',
- 'active' => TRUE
- ),
- ),
- );
- return $fields;
- }
- /**
- * Implements hook_field_widget_info().
- */
- function tripal_chado_field_widget_info() {
- return array(
- 'tripal_chado_organism_select_widget' => array(
- 'label' => t('Organism Select'),
- 'field types' => array('organism_id')
- ),
- 'tripal_chado_dbxref_id_widget' => array(
- 'label' => t('Cross reference'),
- 'field types' => array('dbxref_id'),
- 'description' => t('This record can be cross referenced with a record in
- another online database. This field is intended for the most
- prominent reference. At a minimum, the database and accession
- must be provided.'),
- ),
- 'tripal_chado_dbxref_widget' => array(
- 'label' => t('Cross references'),
- 'field types' => array('dbxref'),
- 'description' => t('This record can be cross referenced with a record
- in another online database. This field is intended for the most
- prominent reference. At a minimum, the database and accession
- must be provided.'),
- ),
- 'tripal_chado_cvterm_class_adder_widget' => array(
- 'label' => t('Add an Annotation'),
- 'field types' => array('cvterm_class_adder'),
- ),
- 'tripal_chado_cvterm_widget' => array(
- 'label' => t('Annotations'),
- 'field types' => array('cvterm'),
- 'description' => t('This record can be annotated with terms
- from other vocabularies.'),
- ),
- 'tripal_chado_md5checksum_checkbox_widget' => array(
- 'label' => t('MD5 Checksum Checkbox'),
- 'field types' => array('md5checksum'),
- ),
- 'tripal_chado_residues_textarea_widget' => array(
- 'label' => t('Residues'),
- 'field types' => array('residues'),
- ),
- 'tripal_chado_seqlen_hidden_widget' => array(
- 'label' => t('Sequence Length'),
- 'field types' => array('seqlen'),
- ),
- 'tripal_chado_kvproperty_adder_widget' => array(
- 'label' => t('Add a Property'),
- 'field types' => array('kvproperty_adder'),
- ),
- 'tripal_chado_kvproperty_widget' => array(
- 'label' => t('Property'),
- 'field types' => array('kvproperty'),
- ),
- );
- }
- /**
- * Implements hook_field_formatter_info().
- */
- function tripal_chado_field_formatter_info() {
- return array(
- 'tripal_chado_organism_formatter' => array(
- 'label' => t('Organism'),
- 'field types' => array('organism_id')
- ),
- 'tripal_chado_dbxref_id_formatter' => array(
- 'label' => t('Cross reference'),
- 'field types' => array('dbxref_id')
- ),
- 'tripal_chado_dbxref_formatter' => array(
- 'label' => t('Cross references'),
- 'field types' => array('dbxref')
- ),
- 'tripal_chado_cvterm_class_adder_formatter' => array(
- 'label' => t('Add an Annotation'),
- 'field types' => array('cvterm_class_adder')
- ),
- 'tripal_chado_cvterm_formatter' => array(
- 'label' => t('Annotations'),
- 'field types' => array('cvterm')
- ),
- 'tripal_chado_md5checksum_formatter' => array(
- 'label' => t('MD5 checksum'),
- 'field types' => array('md5checksum')
- ),
- 'tripal_chado_residues_formatter' => array(
- 'label' => t('Residues'),
- 'field types' => array('residues')
- ),
- 'tripal_chado_seqlen_formatter' => array(
- 'label' => t('Sequence length'),
- 'field types' => array('seqlen')
- ),
- 'tripal_chado_kvproperty_adder_formatter' => array(
- 'label' => t('Add a Property'),
- 'field types' => array('kvproperty_adder')
- ),
- 'tripal_chado_kvproperty_formatter' => array(
- 'label' => t('Property'),
- 'field types' => array('kvproperty')
- ),
- );
- }
- /**
- * Implements hook_field_widget_form_alter().
- */
- function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
- if (array_key_exists('#field_name', $element)) {
- $field_name = $element['#field_name'];
- $matches = array();
- if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
- $tablename = $matches[1];
- $colname = $matches[2];
- $schema = chado_get_schema($tablename);
- // The timelastmodified field exists in many Chado tables. We want
- // the form element to update to the most recent time rather than the time
- // in the database.
- if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
- // We want the default value for the field to be the current time.
- $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
- $element['#date_items']['value'] = $element['#default_value']['value'];
- }
- // We want the date combo fieldset to be collaspible so we will
- // add our own theme_wrapper to replace the one added by the date
- // module.
- if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
- $element['#theme_wrappers'] = array('tripal_chado_date_combo');
- }
- }
- }
- }
- /**
- * Implements hook_field_formatter_view().
- */
- function tripal_chado_field_formatter_view($entity_type, $entity, $field,
- $instance, $langcode, $items, $display) {
- $element = array();
- switch ($display['type']) {
- case 'tripal_chado_organism_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
- tripal_chado_organism_select_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_dbxref_id_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
- tripal_chado_dbxref_id_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_dbxref_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
- tripal_chado_dbxref_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_cvterm_class_adder_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
- tripal_chado_cvterm_class_adder_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_cvterm_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
- tripal_chado_cvterm_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_md5checksum_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
- tripal_chado_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_residues_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
- tripal_chado_residues_textarea_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_seqlen_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
- tripal_chado_seqlen_hidden_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_kvproperty_adder_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
- tripal_chado_kvproperty_adder_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- case 'tripal_chado_kvproperty_formatter':
- module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
- tripal_chado_kvproperty_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- }
- return $element;
- }
- /**
- * Implements hook_field_widget_form().
- */
- function tripal_chado_field_widget_form(&$form, &$form_state, $field,
- $instance, $langcode, $items, $delta, $element) {
- $widget = $element;
- switch ($instance['widget']['type']) {
- case 'tripal_chado_organism_select_widget':
- // Make sure the include files get parsed now and for the form submits.
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/organism_id');
- module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
- // Update the widget with the new field.
- tripal_chado_organism_select_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_dbxref_id_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref_id');
- module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
- tripal_chado_dbxref_id_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_dbxref_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref');
- module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
- tripal_chado_dbxref_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_cvterm_class_adder_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
- module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
- tripal_chado_cvterm_class_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_cvterm_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm');
- module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
- tripal_chado_cvterm_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_md5checksum_checkbox_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/md5checksum');
- module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
- tripal_chado_md5checksum_checkbox_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_residues_textarea_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/residues');
- module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
- tripal_chado_residues_textarea_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_seqlen_hidden_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/seqlen');
- module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
- tripal_chado_seqlen_hidden_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_kvproperty_adder_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
- module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
- tripal_chado_kvproperty_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- case 'tripal_chado_kvproperty_widget':
- form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty');
- module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
- tripal_chado_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- break;
- }
- return $widget;
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- *
- * The field_ui_display_overview_form is used for formatting the display
- * or layout of fields attached to an entity and shown on the entity view page.
- *
- * This function removes the cvterm class and property adder field as those are
- * really not meant for users to show or manage.
- */
- function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
- // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
- // on the add/edit form of an entity for adding new property fields.
- $fields_names = element_children($form['fields']);
- foreach ($fields_names as $field_name) {
- $field_info = field_info_field($field_name);
- if ($field_info['type'] == 'kvproperty_adder') {
- unset($form['fields'][$field_name]);
- }
- if ($field_info['type'] == 'cvterm_class_adder') {
- unset($form['fields'][$field_name]);
- }
- }
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- *
- * The field_ui_field_overview_form is used for ordering and configuring the
- * fields attached to an entity.
- *
- * This function removes the property adder field as that is really not meant
- * for users to show or manage.
- */
- function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
- // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
- // on the add/edit form of an entity for adding new property fields.
- $fields_names = element_children($form['fields']);
- foreach ($fields_names as $field_name) {
- $field_info = field_info_field($field_name);
- if ($field_info['type'] == 'kvproperty_adder') {
- unset($form['fields'][$field_name]);
- }
- if ($field_info['type'] == 'cvterm_class_adder') {
- unset($form['fields'][$field_name]);
- }
- }
- }
- /**
- * Implements hook_field_is_empty().
- */
- function tripal_chado_field_is_empty($item, $field) {
- // If there is no value field then the field is empty.
- if (!array_key_exists('value', $item)) {
- return TRUE;
- }
- // Iterate through all of the fields and if at least one has a value
- // the field is not empty.
- foreach ($item as $form_field_name => $value) {
- if (isset($value) and $value != NULL and $value != '') {
- return FALSE;
- }
- }
- // Otherwise, the field is empty.
- return TRUE;
- }
- /**
- * Returns the values of the field from the $form_state.
- */
- function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
- $value = NULL;
- // The form_state must have the 'values' key. If not then just return.
- if (!array_key_exists('values', $form_state)) {
- return $value;
- }
- // If the field name is not in the form_state['values'] then return.
- if (!array_key_exists($field_name, $form_state['values'])) {
- return $value;
- }
- // Iterate through the values looking for the field_name provided.
- foreach ($form_state['values'][$field_name] as $langcode => $items) {
- if (!array_key_exists($delta, $items)) {
- continue;
- }
- $item = $items[$delta];
- if ($child){
- if(array_key_exists($child, $item) and $item[$child] != '') {
- $value = $item[$child];
- }
- }
- else {
- $value = $item['value'];
- }
- }
- return $value;
- }
- /**
- * Sets the values of the field from the $form_state.
- */
- function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
- // The form_state must have the 'values' key. If not then just return.
- if (!array_key_exists('values', $form_state)) {
- return FALSE;
- }
- // If the field name is not in the form_state['values'] then reutrn.
- if (!array_key_exists($field_name, $form_state['values'])) {
- return FALSE;
- }
- foreach ($form_state['values'][$field_name] as $langcode => $items) {
- if ($child) {
- $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
- }
- else {
- $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
- }
- }
- return TRUE;
- }
- /**
- * Implements hook_theme().
- */
- function tripal_chado_theme($existing, $type, $theme, $path) {
- return array(
- 'tripal_chado_dbxref_id_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/dbxref_id.inc',
- ),
- 'tripal_chado_dbxref_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/dbxref.inc',
- ),
- 'tripal_chado_cvterm_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/cvterm.inc',
- ),
- 'tripal_chado_kvproperty_addr_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/dbxref_id.inc',
- ),
- 'tripal_chado_date_combo' => array(
- 'render element' => 'element',
- 'file' => 'theme/tripal_chado.theme.inc',
- ),
- );
- }
- /**
- * Implements hook_add_bundle_fields().
- */
- function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
- $bundle_name = $bundle->name;
- // This array will hold details that map the bundle to tables in Chado.
- $bundle_data = array();
- // Get the cvterm that corresponds to this TripalTerm object.
- $vocab = entity_load('TripalVocab', array($term->vocab_id));
- $vocab = reset($vocab);
- $match = array(
- 'dbxref_id' => array(
- 'db_id' => array(
- 'name' => $vocab->namespace,
- ),
- 'accession' => $term->accession
- ),
- );
- $cvterm = chado_generate_var('cvterm', $match);
- // The organism table does not have a type_id so we won't ever find
- // a record for it in the tripal_cv_defaults table.
- if ($cvterm->name == 'organism') {
- $bundle_data = array(
- 'cv_id' => $cvterm->cv_id->cv_id,
- 'cvterm_id' => $cvterm->cvterm_id,
- 'data_table' => 'organism',
- 'type_table' => 'organism',
- 'field' => '',
- );
- }
- // The analysis table does not have a type_id so we won't ever find
- // a record for it in the tripalcv_defaults table.
- else if ($cvterm->name == 'analysis') {
- $bundle_data = array(
- 'cv_id' => $cvterm->cv_id->cv_id,
- 'cvterm_id' => $cvterm->cvterm_id,
- 'data_table' => 'analysis',
- 'type_table' => 'analysis',
- 'field' => '',
- );
- }
- else if ($cvterm->name == 'project') {
- $bundle_data = array(
- 'cv_id' => $cvterm->cv_id->cv_id,
- 'cvterm_id' => $cvterm->cvterm_id,
- 'data_table' => 'project',
- 'type_table' => 'project',
- 'field' => '',
- );
- }
- else {
- // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
- // TABLES.
- // Look to see if this vocabulary is used as a default for any table.
- $default = db_select('tripal_cv_defaults', 't')
- ->fields('t')
- ->condition('cv_id', $cvterm->cv_id->cv_id)
- ->execute()
- ->fetchObject();
- if ($default) {
- $bundle_data = array(
- 'cv_id' => $cvterm->cv_id->cv_id,
- 'cvterm_id' => $cvterm->cvterm_id,
- 'data_table' => $default->table_name,
- 'type_table' => $default->table_name,
- 'field' => $default->field_name,
- );
- }
- }
- // Save the mapping information so that we can reuse it when we need to
- // look things up for later for an entity
- tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
- tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
- tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
- //////////////////////////////////////////////////////////////////////////////
- // ADD FIELDS TO BUNDLE
- ////////////////////////////////////////////////////////////////////////////
- ////
- //
- // Base table fields.
- //
- // Adds the fields for the base table to the entity. Adds fields
- // for all columns including FK fields. Excludes primary key and the
- // type_id field (that's inherent in the bundle).
- tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
- ////
- //
- // Property table fields.
- //
- // Check to see if there are any property tables with FKs to this
- // base table. If so, add the fields for that type of table.
- $prop_table = $bundle_data['data_table'] . 'prop';
- if (chado_table_exists($prop_table)) {
- tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, $prop_table, $bundle_data['data_table']);
- }
- ////
- //
- // Dbxref table fields.
- //
- // Check to see if there are any dbxref tables with FKs to this
- // base table. If so, add the fields for that type of table.
- $dbxref_table = $bundle_data['data_table'] . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- tripal_chado_add_bundle_dbxref_field($entity_type, $bundle_name, $dbxref_table, $bundle_data['data_table']);
- }
- ////
- //
- // Cvterm table fields.
- //
- // Check to see if there are any cvterm tables with FKs to this
- // base table. If so, add the fields for that type of table.
- $cvterm_table = $bundle_data['data_table'] . '_cvterm';
- if (chado_table_exists($cvterm_table)) {
- tripal_chado_add_bundle_cvterm_class_adder_field($entity_type, $bundle_name, $cvterm_table, $bundle_data['data_table']);
- }
- }
- /**
- * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
- *
- * @param $entity_type
- * @param $bundle_name
- * @param $base_table
- * @param $dbxref_table
- */
- function tripal_chado_add_bundle_dbxref_field($entity_type_name, $bundle_name, $dbxref_table, $base_table) {
- // We already have a dbxref_id field.
- $field_name = $dbxref_table;
- $schema = chado_get_schema($dbxref_table);
- $pkey = $schema['primary key'][0];
- // Initialize the field array.
- $field_info = array(
- 'field_type' => 'dbxref',
- 'widget_type' => 'tripal_fields_dbxfref_widget',
- 'widget_settings' => array('display_label' => 1),
- 'description' => '',
- 'label' => 'Cross References',
- 'is_required' => 0,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'storage' => 'field_chado_storage',
- 'field_settings' => array(
- // The Chado table that this field maps to.
- 'chado_table' => $dbxref_table,
- // The column in the chado table that this field maps to.
- 'chado_column' => $pkey,
- // The base table that this field is connected to.
- 'base_table' => $base_table,
- 'semantic_web' => array(
- // The type is the term from a vocabulary that desribes this field..
- 'type' => '',
- // The namepsace for the vocabulary (e.g. 'foaf').
- 'ns' => '',
- // The URL for the namespace. It must be that the type can be
- // appended to the URL.
- 'nsurl' => '',
- ),
- ),
- );
- // If the base table has a 'dbxref_id' then change the label to
- // indicate these are secondary cross references.
- $schema = chado_get_schema($base_table);
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_info['label'] = 'Secondary Cross References';
- }
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
- }
- /**
- * Adds the fields for managing properties that are stored in a prop table.
- *
- * @param $entity_type_name
- * @param $bundle_name
- * @param $kv_table
- */
- function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table, $base_table) {
- $field_name = $kv_table;
- // Initialize the field array.
- $field_info = array(
- 'field_type' => 'kvproperty_adder',
- 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
- 'field_settings' => array(
- 'base_table' => $base_table,
- ),
- 'storage' => 'field_chado_storage',
- 'widget_settings' => array('display_label' => 1),
- 'description' => '',
- 'label' => 'Additional Properties',
- 'is_required' => 0,
- );
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
- }
- /**
- * Adds the fields for managing properties that are stored in a prop table.
- *
- * @param $entity_type_name
- * @param $bundle_name
- * @param $kv_table
- */
- function tripal_chado_add_bundle_cvterm_class_adder_field($entity_type_name, $bundle_name, $cvterm_table, $base_table) {
- // First add a generic property field so that users can add new property types.
- $field_name = $cvterm_table;
- // Initialize the field array.
- $field_info = array(
- 'field_type' => 'cvterm_class_adder',
- 'widget_type' => 'tripal_fields_cvterm_class_adder_widget',
- 'field_settings' => array(
- 'base_table' => $base_table,
- ),
- 'storage' => 'field_chado_storage',
- 'widget_settings' => array('display_label' => 1),
- 'description' => '',
- 'label' => 'Additional Annotation Types',
- 'is_required' => 0,
- );
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
- }
- /**
- * Adds the fields for the base table to the entity.
- */
- function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $bundle_data) {
- $table_name = $bundle_data['data_table'];
- $type_table = $bundle_data['type_table'];
- $type_field = $bundle_data['field'];
- // Iterate through the columns of the table and see if fields have been
- // created for each one. If not, then create them.
- $schema = chado_get_schema($table_name);
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- $field_name = $table_name . '__' . $column_name;
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field.
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
- // Get the field defaults for this column.
- $field_info = tripal_chado_get_table_column_field_default($table_name, $schema, $column_name);
- // TODO: add in a call to drupal_alter to allow other modules to change
- // the field settings.
- // Determine if the field is required.
- if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
- $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
- }
- // If we don't have a field type then we don't need to create a field.
- if (!$field_info['field_type']) {
- // If we don't have a field type but it is required and doesn't have
- // a default value then we are in trouble.
- if ($field_info['is_required'] and !array_key_exists('default', $details)) {
- throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
- array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
- }
- continue;
- }
- // If this field is a foreign key field then we will have a custom field.
- $is_fk = FALSE;
- if (array_key_exists('foreign keys', $schema)) {
- foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
- if (array_key_exists($column_name, $fk_details['columns'])) {
- $is_fk = TRUE;
- }
- }
- }
- // Add the field to the bundle.
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
- }
- }
- /**
- * Returns a $field_info array for a field based on a database column.
- *
- */
- function tripal_chado_get_table_column_field_default($table_name, $schema, $column_name) {
- $details = $schema['fields'][$column_name];
- // Create an array with information about this field.
- $field = array(
- 'field_type' => '',
- 'widget_type' => '',
- 'description' => '',
- 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
- 'is_required' => 0,
- 'storage' => 'field_chado_storage',
- 'widget_settings' => array(
- 'display_label' => 1
- ),
- 'field_settings' => array(
- // The table in Chado where this field maps to.
- 'chado_table' => $table_name,
- // The column in the Chado table that this field maps to.
- 'chado_column' => $column_name,
- 'semantic_web' => array(
- // The type is the term from a vocabulary that desribes this field..
- 'type' => '',
- // The namepsace for the vocabulary (e.g. 'foaf').
- 'ns' => '',
- // The URL for the namespace. It must be that the type can be
- // appended to the URL.
- 'nsurl' => '',
- ),
- ),
- );
- // Alter the field info array depending on the column details.
- switch($details['type']) {
- case 'char':
- $field['field_type'] = 'text';
- $field['widget_type'] = 'text_textfield';
- $field['field_settings']['max_length'] = $details['length'];
- break;
- case 'varchar':
- $field['field_type'] = 'text';
- $field['widget_type'] = 'text_textfield';
- $field['field_settings']['max_length'] = $details['length'];
- break;
- case 'text':
- $field['field_type'] = 'text';
- $field['widget_type'] = 'text_textarea';
- $field['field_settings']['max_length'] = 17179869184;
- $field['field_settings']['text_processing'] = 1;
- $field['format'] = filter_default_format();
- break;
- case 'blob':
- // not sure how to support a blob field.
- continue;
- break;
- case 'int':
- $field['field_type'] = 'number_integer';
- $field['widget_type'] = 'number';
- break;
- case 'float':
- $field['field_type'] = 'number_float';
- $field['widget_type'] = 'number';
- $field['field_settings']['precision'] = 10;
- $field['field_settings']['scale'] = 2;
- $field['field_settings']['decimal_separator'] = '.';
- break;
- case 'numeric':
- $field['field_type'] = 'number_decimal';
- $field['widget_type'] = 'number';
- break;
- case 'serial':
- // Serial fields are most likely not needed as a field.
- break;
- case 'boolean':
- $field['field_type'] = 'list_boolean';
- $field['widget_type'] = 'options_onoff';
- $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
- break;
- case 'datetime':
- // Use the Drupal Date and Date API to create the field/widget
- $field['field_type'] = 'datetime';
- $field['widget_type'] = 'date_select';
- $field['widget_settings']['increment'] = 1;
- $field['widget_settings']['tz_handling'] = 'none';
- $field['widget_settings']['collapsible'] = TRUE;
- // TODO: Add settings so that the minutes increment by 1.
- // And turn off the timezone, as the Chado field doesn't support it.
- break;
- }
- // Set some default semantic web information
- if ($column_name == 'name') {
- $field['field_settings']['semantic_web']['type'] = 'name';
- $field['field_settings']['semantic_web']['ns'] = 'foaf';
- $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
- }
- if ($column_name == 'description' or $column_name == 'definition' or
- $column_name == 'comment') {
- $field['field_settings']['semantic_web']['type'] = 'description';
- $field['field_settings']['semantic_web']['ns'] = 'hydra';
- $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
- }
- //
- // GENERIC COLUMNS
- //
- if ($field['field_settings']['chado_column'] =='organism_id') {
- $field['field_type'] = 'organism_id';
- $field['widget_type'] = 'tripal_chado_organism_select_widget';
- $field['label'] = 'Organism';
- $field['description'] = 'Select an organism.';
- }
- elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
- $field['field_type'] = 'dbxref_id';
- $field['widget_type'] = 'tripal_chado_primary_dbxref_widget';
- $field['label'] = 'Cross Reference';
- $field['description'] = 'This record can be cross referenced with a ' .
- 'record in another online database. The primary reference is for the ' .
- 'most prominent reference. At a minimum, the database and accession ' .
- 'must be provided. To remove a set reference, change the database ' .
- 'field to "Select a Database".';
- }
- elseif ($field['label'] == 'Timeaccessioned') {
- $field['label'] = 'Time Accessioned';
- $field['description'] = 'Please enter the time that this record was first added to the database.';
- }
- elseif ($field['label'] == 'Timelastmodified') {
- $field['label'] = 'Time Last Modified';
- $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
- }
- //
- // ORGANISM TABLE
- //
- elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
- $field['label'] = 'Description';
- }
- //
- // FEATURE TABLE
- //
- elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
- $field['field_type'] = 'text';
- $field['widget_type'] = 'text_textfield';
- $field['field_settings']['text_processing'] = 0;
- $field['field_settings']['semantic_web']['type'] = 'name';
- $field['field_settings']['semantic_web']['ns'] = 'foaf';
- $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
- }
- elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
- $field['field_type'] = 'md5checksum';
- $field['widget_type'] = 'tripal_chado_md5checksum_checkbox_widget';
- $field['label'] = 'MD5 Checksum';
- $field['description'] = 'Generating MD5 checksum for the sequence.';
- }
- elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
- $field['field_type'] = 'seqlen';
- $field['widget_type'] = 'tripal_chado_seqlen_hidden_widget';
- $field['label'] = 'Seqlen';
- $field['description'] = 'The length of the residues.';
- }
- elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
- $field['field_type'] = 'residues';
- $field['widget_type'] = 'tripal_chado_residues_textarea_widget';
- $field['label'] = 'Residues';
- $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
- }
- //
- // ANALYSIS TABLE
- //
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
- $field['field_settings']['semantic_web']['type'] = 'SoftwareApplication';
- $field['field_settings']['semantic_web']['ns'] = 'schema';
- $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
- $field['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
- $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
- }
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceuri') {
- $field['field_type'] = 'text';
- $field['widget_type'] = 'text_textfield';
- $field['field_settings']['text_processing'] = 0;
- $field['label'] = 'Source URL';
- $field['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
- }
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourcename') {
- $field['label'] = 'Source Name';
- $field['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
- }
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceversion') {
- $field['label'] = 'Source Version';
- $field['description'] = 'If hte source data set has a version include it here.';
- }
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'algorithm') {
- $field['label'] = 'Source Version';
- $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
- }
- elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'programversion') {
- $field['label'] = 'Program Version';
- $field['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
- }
- return $field;
- }
- /**
- * Implements hook_exclude_type_by_default()
- *
- * This hooks allows fields of a specified type that match a specified criteria
- * to be excluded by default from any table when chado_generate_var() is called.
- * Keep in mind that if fields are excluded by default they can always be
- * expanded at a later date using chado_expand_var().
- *
- * Criteria are php strings that evaluate to either TRUE or FALSE. These
- * strings are evaluated using drupal_eval() which suppresses syntax errors and
- * throws watchdog entries of type php. There are also watchdog entries of type
- * tripal stating the exact criteria evaluated. Criteria can
- * contain the following tokens:
- * - <field_name>
- * Replaced by the name of the field to be excluded
- * - <field_value>
- * Replaced by the value of the field in the current record
- * Also keep in mind that if your criteria doesn't contain the
- * >field_value< token then it will be evaluated before the query is
- * executed and if the field is excluded it won't be included in the
- * query.
- *
- * @return
- * An array of type => criteria where the type is excluded if the criteria
- * evaluates to TRUE
- *
- * @ingroup tripal
- */
- function tripal_chado_exclude_type_by_default() {
- return array('text' => 'strlen("<field_value> ") > 250');
- }
- /**
- * Implements hook_job_describe_args().
- *
- * Describes the arguements for the tripal_populate_mview job to allow for
- * greater readability in the jobs details pages.
- *
- * @param $callback
- * The callback of the current tripal job (this is the function that will be
- * executed when tripal_launch_jobs.php is run.
- * @param $args
- * An array of arguments passed in when the job was registered.
- *
- * @return
- * A more readable $args array
- *
- * @ingroup tripal
- */
- function tripal_chado_job_describe_args($callback, $args) {
- $new_args = array();
- if ($callback == 'tripal_populate_mview') {
- // get this mview details
- $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
- $results = db_query($sql, array(':mview_id' => $args[0]));
- $mview = $results->fetchObject();
- $new_args['View Name'] = $mview->name;
- }
- elseif ($callback == 'tripal_install_chado') {
- $new_args['Action'] = $args[0];
- }
- return $new_args;
- }
- /**
- * Implements hook_entity_property_info_alter().
- *
- * This is being implemented to ensure chado fields are exposed for search api indexing.
- * All fields are available for index by default but the getter function set by default
- * is not actually capable of getting the value from chado. Thus we change the getter
- * function to one that can :-).
- */
- function tripal_chado_entity_property_info_alter(&$info) {
- // Get a list of fields with the chado storage backend.
- // Loop through all of the bundles.
- if (isset($info['TripalEntity']['bundles'])) {
- foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
- // Loop through each of the fields for a given bundle.
- foreach ($bundle['properties'] as $field_name => $field_info) {
- // If the field is a chado field, then change the callback.
- // @todo check this properly.
- if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
- $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
- 'tripal_chado_entity_property_get_value';
- }
- }
- }
- }
- }
- /**
- * Provides a way for the search api to grab the value of a chado field.
- *
- * @param $entity
- * The fully-loaded entity object to be indexed.
- * @param $options
- * Options that can be ued when retrieving the value.
- * @param $field_name
- * The machine name of the field we want to retrieve.
- * @param $entity_type
- * The type of entity (ie: TripalEntity).
- *
- * @return
- * The rendered value of the field specified by $field_name.
- */
- function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
- $display = array(
- 'type' => '',
- 'label' => 'hidden',
- );
- $langcode = LANGUAGE_NONE;
- $items = field_get_items($entity_type, $entity, $field_name);
- if (count($items) == 1) {
- $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
- }
- // @todo: handle fields with multiple values.
- else {
- $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
- drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
- }
- return drupal_render($render_array);
- }
|