123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- function chado_autocomplete_stock($string = '') {
- $items = array();
- $sql = "
- SELECT
- B.stock_id as id, B.uniquename, B.name,
- O.genus, O,species,
- CVT.name as type
- FROM {stock} B
- INNER JOIN {organism} O ON O.organism_id = B.organism_id
- INNER JOIN {cvterm} CVT ON CVT.cvterm_id = B.type_id
- WHERE lower(B.uniquename) like lower(:str) OR lower(B.name) like lower(:str)
- ORDER by B.name
- LIMIT 25 OFFSET 0
- ";
- $records = chado_query($sql, array(':str' => $string . '%'));
- while ($r = $records->fetchObject()) {
- $key = "$r->name [id: $r->id]";
- $items[$key] = "$r->name ($r->uniquename, $r->type, $r->genus $r->species)";
- }
- drupal_json_output($items);
- }
- function chado_get_stock($identifiers, $options = array()) {
-
- if (!isset($options['include_fk'])) {
-
- $options['include_fk'] = array('type_id' => TRUE, 'dbxref_id' => TRUE);
- }
-
- if (!is_array($identifiers)) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: The identifier passed in is expected to be an array with the key
- matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
- elseif (empty($identifiers)) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
- is expected to be an array with the key matching a column name in the stock table
- (ie: stock_id or name). You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
-
-
- if (isset($identifiers['property'])) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $stock = chado_get_record_with_property(
- array('table' => 'stock', 'base_records' => $identifiers),
- array('type_name' => $property),
- $options
- );
- }
-
-
- else {
-
- $stock = chado_generate_var(
- 'stock',
- $identifiers,
- $options
- );
- }
-
- if (is_array($stock)) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: The identifiers you passed in were not unique. You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
-
- elseif ($stock === FALSE) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
- you passed in. You should check that your identifiers are correct, as well as, look
- for a chado_generate_var error for additional clues. You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
-
- else {
- return $stock;
- }
- }
- function chado_get_multiple_stocks($identifiers, $options = array()) {
-
- if (!isset($options['include_fk'])) {
-
- $options['include_fk'] = array('type_id' => TRUE, 'dbxref_id' => TRUE);
- }
-
- if (!is_array($identifiers)) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: The identifier passed in is expected to be an array with the key
- matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
- elseif (empty($identifiers)) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
- is expected to be an array with the key matching a column name in the stock table
- (ie: stock_id or name). You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
-
-
- if (isset($identifiers['property'])) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $stock = chado_get_record_with_property(
- array('table' => 'stock', 'base_records' => $identifiers),
- array('type_name' => $property),
- $options
- );
- }
-
-
- else {
-
- $stock = chado_generate_var(
- 'stock',
- $identifiers,
- $options
- );
- }
-
- if ($stock === FALSE) {
- tripal_report_error(
- 'tripal_stock_api',
- TRIPAL_ERROR,
- "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
- you passed in. You should check that your identifiers are correct, as well as, look
- for a chado_generate_var error for additional clues. You passed in %identifier.",
- array(
- '%identifier'=> print_r($identifiers, TRUE)
- )
- );
- }
-
- else {
- return $stock;
- }
- }
|