123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?php
- function tripal_chado_field_info() {
- $info = array();
- $field_types = tripal_get_field_types('tripal_chado');
- foreach ($field_types as $field_type) {
- $info[$field_type] = $field_type::fieldInfo();
- }
- return $info;
- }
- function tripal_chado_field_create_info($entity_type, $bundle) {
-
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
-
- $details = array(
- 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
- 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
- 'chado_table' => $mapped_table->chado_table,
- 'chado_type_table' => $mapped_table->chado_table,
- 'chado_type_column' => $mapped_table->chado_field,
- );
- $base_fields = tripal_chado_field_create_base('create_info', $entity_type, $bundle, $details);
- $custom_fields = tripal_chado_field_create_info_custom($entity_type, $bundle, $details);
- return array_merge($base_fields, $custom_fields);
- }
- function tripal_chado_field_create_info_custom($entity_type, $bundle, $details) {
- $info = array();
- $fields = tripal_get_fields('tripal_chado', $entity_type, $bundle, $details);
- foreach ($fields as $field) {
- $field_name = $field->getFieldName();
- if ($field->canAttach()) {
- $info[$field_name] = $field->createInfo();
- }
- }
- return $info;
- }
- function tripal_chado_field_create_base($step, $entity_type, $bundle, $details) {
- $fields = array();
-
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
-
-
- $schema = chado_get_schema($table_name);
- if (!$schema) {
- return $fields;
- }
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- $field_name = $table_name . '__' . $column_name;
-
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
-
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
-
- $field_info = array();
- if ($step == 'create_info') {
- $field_info = tripal_chado_field_create_info_base_defaults($field_name,
- $table_name, $schema, $column_name);
- }
- if ($step == 'create_instance_info') {
- $field_info = tripal_chado_field_create_instance_info_base_defaults($bundle->name,
- $field_name, $table_name, $schema, $column_name);
- }
-
-
-
- $fields[$field_name] = $field_info;
- }
- return $fields;
- }
- function tripal_chado_field_create_info_base_defaults($field_name, $table_name,
- $schema, $column_name) {
- $details = $schema['fields'][$column_name];
-
- $field = array(
- 'field_name' => $field_name,
- 'type' => '',
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => $column_name,
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, $column_name),
- ),
- );
-
- switch($details['type']) {
- case 'char':
- $field['type'] = 'text';
- $field['settings']['max_length'] = $details['length'];
- break;
- case 'varchar':
- $field['type'] = 'text';
- $field['settings']['max_length'] = $details['length'];
- break;
- case 'text':
- $field['type'] = 'text';
- $field['settings']['max_length'] = 17179869184;
- $field['settings']['text_processing'] = 1;
- break;
- case 'blob':
-
- continue;
- break;
- case 'int':
- $field['type'] = 'number_integer';
- break;
- case 'float':
- $field['type'] = 'number_float';
- $field['settings']['precision'] = 10;
- $field['settings']['scale'] = 2;
- $field['settings']['decimal_separator'] = '.';
- break;
- case 'numeric':
- $field['type'] = 'number_decimal';
- break;
- case 'serial':
-
- break;
- case 'boolean':
- $field['type'] = 'list_boolean';
- $field['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
- break;
- case 'datetime':
-
- $field['type'] = 'datetime';
- break;
- }
-
- if ($column_name == 'uniquename') {
- $field['settings']['text_processing'] = 0;
- }
-
-
-
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $field['type'] = 'text';
- $field['settings']['text_processing'] = 0;
- }
-
-
-
- elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $field['type'] = 'text';
- $field['settings']['text_processing'] = 0;
- }
- return $field;
- }
- function tripal_chado_field_create_instance_info($entity_type, $bundle) {
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
-
- $details = array(
- 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
- 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
- 'chado_table' => $mapped_table->chado_table,
- 'chado_type_table' => $mapped_table->chado_table,
- 'chado_type_column' => $mapped_table->chado_field,
- );
- $base_fields = tripal_chado_field_create_base('create_instance_info', $entity_type, $bundle, $details);
- $custom_fields = tripal_chado_field_create_instance_info_custom($entity_type, $bundle, $details);
- return array_merge($base_fields, $custom_fields);
- }
- function tripal_chado_field_create_instance_info_base_defaults($bundle_name,
- $field_name, $table_name, $schema, $column_name) {
- $details = $schema['fields'][$column_name];
- $field = array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle_name,
- 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'settings' => array(),
- ),
- ),
- );
-
- if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
- $field_info['required'] = TRUE;
- }
-
- switch($details['type']) {
- case 'char':
- $field['widget']['type'] = 'text_textfield';
- break;
- case 'varchar':
- $field['widget']['type'] = 'text_textfield';
- break;
- case 'text':
- $field['widget']['type'] = 'text_textarea';
- $field['widget']['settings']['format'] = filter_default_format();
- break;
- case 'blob':
-
- continue;
- break;
- case 'int':
- $field['widget']['type'] = 'number';
- break;
- case 'float':
- $field['widget']['type'] = 'number';
- break;
- case 'numeric':
- $field['widget']['type'] = 'number';
- break;
- case 'serial':
-
- break;
- case 'boolean':
- $field['widget']['type'] = 'options_onoff';
- break;
- case 'datetime':
- $field['widget']['type'] = 'date_select';
- $field['widget']['settings']['increment'] = 1;
- $field['widget']['settings']['tz_handling'] = 'none';
- $field['widget']['settings']['collapsible'] = TRUE;
-
-
- break;
- }
-
- if ($column_name == 'uniquename') {
- $field['label'] = 'Identifier';
- $field['widget_type'] = 'text_textfield';
- }
- 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.';
- }
-
-
-
- elseif ($table_name == 'organism' and $column_name == 'comment') {
- $field['label'] = 'Description';
- }
-
-
-
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $field['widget_type'] = 'text_textfield';
- }
-
-
-
- elseif ($table_name == 'analysis' and $column_name == 'program') {
- $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 ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $field['widget_type'] = 'text_textfield';
- $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 ($table_name == 'analysis' and $column_name == '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 ($table_name == 'analysis' and $column_name == 'sourceversion') {
- $field['label'] = 'Source Version';
- $field['description'] = 'If hte source data set has a version include it here.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
- $field['label'] = 'Source Version';
- $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
- }
- elseif ($table_name == 'analysis' and $column_name == '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.';
- }
-
-
-
- elseif ($table_name == 'project' and $column_name == 'description') {
- $field['label'] = 'Short Description';
- }
- return $field;
- }
- function tripal_chado_field_create_instance_info_custom($entity_type, $bundle, $details) {
- $info = array();
- $fields = tripal_get_fields('tripal_chado', $entity_type, $bundle, $details);
- foreach ($fields as $field) {
- $field_name = $field->getFieldName();
- if ($field->canAttach()) {
- $info[$field_name] = $field->createInstanceInfo();
- }
- }
- return $info;
- }
- function tripal_chado_field_widget_info() {
- $info = array();
- $field_types = tripal_get_field_types('tripal_chado');
- foreach ($field_types as $field_type) {
- $info += $field_type::widgetInfo();
- }
- return $info;
- }
- function tripal_chado_field_formatter_info() {
- $info = array();
- $field_types = tripal_get_field_types('tripal_chado');
- foreach ($field_types as $field_type) {
- $info += $field_type::formatterInfo();
- }
- return $info;
- }
- function tripal_chado_field_settings_form($field, $instance, $has_data) {
- $form = array();
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $form = $field_type::settingsForm($field, $instance, $has_data);
- }
- return $form;
- }
- function tripal_chado_field_formatter_settings_summary($field, $instance, $view_mode) {
- $summary = '';
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $form = $field_type::formatterSettingsSummary($field, $instance, $view_mode);
- }
- return $summary;
- }
- function tripal_chado_field_formatter_settings_form($field, $instance,
- $view_mode, $form, &$form_state) {
- $form = array();
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $form = $field_type::formatterSettingsForm(field, $instance, $view_mode, $form, $form_state);
- }
- return $form;
- }
- function tripal_chado_field_formatter_view($entity_type, $entity, $field,
- $instance, $langcode, $items, $display) {
- $element = array();
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $field_type::formatterView($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
- }
- return $element;
- }
- function tripal_chado_field_widget_form(&$form, &$form_state, $field,
- $instance, $langcode, $items, $delta, $element) {
- $widget = $element;
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $field_type::widgetForm($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
- }
- return $widget;
- }
- 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);
- if (!$schema) {
- return;
- }
-
-
-
- if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
-
- $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
- $element['#date_items']['value'] = $element['#default_value']['value'];
- }
-
-
-
- if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
- $element['#theme_wrappers'] = array('tripal_chado_date_combo');
- }
- }
- }
- }
- function tripal_chado_field_validate($entity_type, $entity, $field, $instance,
- $langcode, $items, &$errors) {
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $field_obj = new $field_type($entity_type, $entity->bundle);
- $form = $field_obj::widgetFormValidate($entity_type, $entity, $field, $instance,
- $langcode, $items, $errors);
- }
- }
- function tripal_chado_field_submit($entity_type, $entity, $field, $instance,
- $langcode, &$items, $form, &$form_state) {
- $field_type = $field['type'];
- module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
- if (class_exists($field_type)) {
- $field_obj = new $field_type($entity_type, $entity->bundle);
- $form = $field_obj::widgetFormSubmit($entity_type, $entity, $field, $instance,
- $langcode, $items, $errors);
- }
- }
- function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
-
-
- $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]);
- }
- }
- }
- function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
-
-
- $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]);
- }
- }
- }
- function tripal_chado_field_is_empty($item, $field) {
-
- if (!array_key_exists('value', $item)) {
- return TRUE;
- }
-
-
- foreach ($item as $form_field_name => $value) {
- if (isset($value) and $value != NULL and $value != '') {
- return FALSE;
- }
- }
-
- return TRUE;
- }
|