tripal_chado.project.api.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Provides API functions specificially for managing project
  5. * records in Chado.
  6. */
  7. /**
  8. * @defgroup tripal_project_api Chado Project
  9. * @ingroup tripal_chado_api
  10. * @{
  11. * Provides API functions specificially for managing project
  12. * records in Chado. The project table of Chado is used for storing a variety
  13. * of data types besides just projects from a project collection. Examples of
  14. * other records commonly stored in the project table are germplasm and
  15. * individuals from a breeding population.
  16. * @}
  17. */
  18. /**
  19. * Used for autocomplete in forms for identifying projects
  20. *
  21. * @param $string
  22. * The string to search for.
  23. *
  24. * @return
  25. * A json array of terms that begin with the provided string.
  26. *
  27. * @ingroup tripal_project_api
  28. */
  29. function chado_autocomplete_project($string = '') {
  30. $items = array();
  31. $sql = "
  32. SELECT
  33. B.project_id as id, B.name
  34. FROM {project} B
  35. WHERE lower(B.name) like lower(:str)
  36. ORDER by B.name
  37. LIMIT 25 OFFSET 0
  38. ";
  39. $records = chado_query($sql, array(':str' => $string . '%'));
  40. while ($r = $records->fetchObject()) {
  41. $key = "$r->name [id: $r->id]";
  42. $items[$key] = "$r->name";
  43. }
  44. drupal_json_output($items);
  45. }