Tripal
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController Class Reference
Inheritance diagram for Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController:
Inheritance graph
[legend]
Collaboration diagram for Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController:
Collaboration graph
[legend]

Public Member Functions

 handleGenericAutocomplete (Request $request, string $base_table, string $column_name, string $type_column, string $property_table, int $match_limit=10, int $type_id=0,)
 

Static Public Member Functions

static getDefaultOptions ()
 
static getQuery (string $string, array $options)
 
static getPkeyId (string $value)
 

Protected Attributes

bool $include_pkey = TRUE
 
string $match_operator = 'CONTAINS'
 

Static Protected Attributes

static array $default_options = []
 

Detailed Description

Controller, Chado Generic Autocomplete.

Member Function Documentation

◆ getDefaultOptions()

static Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController::getDefaultOptions ( )
static

Retrieves the default options used by the form element methods.

Returns
array The default values for the options used in the various form methods. Keys match those defined for the ::getFormElement() $options paramater.

◆ getPkeyId()

static Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController::getPkeyId ( string  $value)
static

Fetch the pkey id number from an autocomplete value.

Assumes the primary key value is present at the end of the string in curved brackets.

Parameters
string$valueA value from an autocomplete with the ID in parentheses at the end, earlier parentheses are ignored, e.g. "Some (Big) Analysis (12)".
Returns
int Primary key ID number of the record, or 0 if an unparsable $value was passed, which can happen if the user did not let the autocomplete supply a value, (e.g. 12).

Reimplemented in Drupal\tripal_chado\Controller\ChadoOrganismAutocompleteController.

◆ getQuery()

static Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController::getQuery ( string  $string,
array  $options 
)
static

Returns a database query ready to execute.

This allows the same query to be used for both autocomplete and select.

Parameters
string$stringThe string to be autocompleted, used to limit the query. The string "%" has the special meaning of return all records.
array$optionsThe following keys are used:
  • base_table (string): Chado base table name (required; e.g. pub).
  • column_name (string): Name of chado column to be returned (e.g. title).
  • pkey_id (string): The primary key of the base table, defaults to base_table + "_id" (e.g. pub_id)
  • type_column (string): If the base table has a type column, holds the column name. This is usually "type_id". Use a single character placeholder if absent (e.g. "-").
  • property_table (string): the name of the property table name associated with this base table. If the type is stored in the base table then use same name as base table here. (e.g. pubprop)
  • property_type_column (string): type column in property table, defaults to "type_id". This is only used if the property_table is not the same as the base table.
  • type_id (int): Used to restrict records to those of a specific type. Set to 0 in order to not restrict to a specific type. Define in autocomplete route parameter e.g. ['type_id' => 0].
  • match_operator (string): Either 'CONTAINS' (default) or 'STARTS_WITH'.
  • match_limit (int): Desired number of autocomplete matching names to suggest, default 10. If zero, there is no limit.
Returns
?\Drupal\pgsql\Driver\Database\pgsql\Select A database query object

Reimplemented in Drupal\tripal_chado\Controller\ChadoOrganismAutocompleteController, and Drupal\tripal_chado\Controller\ChadoOrganismFormElementController.

◆ handleGenericAutocomplete()

Drupal\tripal_chado\Controller\ChadoGenericAutocompleteController::handleGenericAutocomplete ( Request  $request,
string  $base_table,
string  $column_name,
string  $type_column,
string  $property_table,
int  $match_limit = 10,
int  $type_id = 0 
)

Generic Chado autocomplete method.

NOTE: This is suitable to use for any chado table where the returned value is from a single column.

For simplicity, this autocomplete assumes that the primary key of the base table is the base table name + '_id', and that the type columnn is named 'type_id'.

To support columns without a unique constraint, the returned autocomplete value includes the primary key numeric value in parentheses at the end, e.g. "Impressive Publication (42)".

Parameters
\Symfony\Component\HttpFoundation\Request$requestRepresents the current HTTP request.
string$base_tableChado base table name.
string$column_nameName of chado base column in the specified table to be returned.
string$type_columnIf the base table has a type column, the column name. This is usually "type_id". Use a single character placeholder if absent.
string$property_tableProperty table name, use same name as base table if not needed.
int$match_limitDesired number of matching names to suggest. See ::getDefaultOptions() for the default value. If set to zero, then autocomplete is disabled. Define in autocomplete route parameter e.g. ['match_limit' => 15].
int$type_idRestricts the results returned to a specific type. This must be a value present in the $type_column and also present in the chado cvterm table. Set to 0 in order to not restrict to a specific type. Define in autocomplete route parameter e.g. ['type_id' => 0].
Returns
Symfony\Component\HttpFoundation\JsonResponse Matching table results in an array where the value of the $column_name column is both the key and the value. If $type_id is provided, the type name is added to the end of the key/value surrounded by square brackets. If the include_pkey property is TRUE then the primary key value is appended to the end of both the key and value surrounded by curved brackets, e.g. 'ftbA-1 [gene] (42)'.

The documentation for this class was generated from the following file: