tripal_core.extensions.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. function tripal_core_extensions_form($form, &$form_state = NULL) {
  3. // Get the RSS feed XML from the tripa.info website.
  4. $content = file_get_contents("http://tripal.info/rss/extensions.xml");
  5. $xml = new SimpleXmlElement($content);
  6. $namespace = "http://tripal.info/rss/extensions/";
  7. // Parse the items into an array indexed by category and compatible versions.
  8. $items = array();
  9. foreach ($xml->channel->item as $item) {
  10. $category = (string) $item->category;
  11. // In order to get fields in the 'tripal_extension' name space we must
  12. // pass in the $namespace to the children function. We first get the
  13. // Tripal versions, then the chado versions and organize the elements
  14. // accordintly.
  15. $tvs = preg_split('/, /', (string) $item->children($namespace)->tripal_version);
  16. foreach($tvs as $tv) {
  17. $cvs = preg_split('/, /', (string) $item->children($namespace)->chado_version);
  18. foreach($cvs as $cv) {
  19. // Index the items by category, tripal version and chado version
  20. $items[$tv][$cv][$category][] = $item;
  21. }
  22. }
  23. }
  24. // Get the Chado version and convert to the expected format
  25. $chado_version = chado_get_version(TRUE);
  26. $chado_version = preg_replace('/^(\d\.\d).*$/', "v$1x", $chado_version);
  27. // Get the Tripal version. This is the version set in the tripal_core.info
  28. $info = system_get_info('module', 'tripal_core');
  29. $tripal_version = $info['version'];
  30. $tripal_version = preg_replace('/^.*?-(\d\.\d+).*$/', "v$1", $tripal_version);
  31. $form['type_select'] = array(
  32. '#type' => 'select',
  33. '#options' => array(
  34. 'Bulk Loader Templates' => 'Bulk Loader Templates',
  35. 'Materialized View' => 'Materialized View',
  36. 'Extension Module' => 'Extension Module',
  37. ),
  38. '#default_value' => 'Extension Module',
  39. );
  40. // Iterate through the compatible extensions
  41. foreach ($items[$tripal_version][$chado_version] as $category => $items) {
  42. foreach ($items as $item) {
  43. $guid = (string) $item->guid;
  44. $markup = '';
  45. $markup .= "<h3>" . (string) $item->title . "</h3>";
  46. $markup .= "<p>" . $category . "</p>";
  47. $markup .= "<p>" . (string) $item->description . "</p>";
  48. $form[$category][$guid] = array(
  49. '#type' => 'item',
  50. '#markup' => $markup,
  51. );
  52. switch ($category) {
  53. case 'Bulk Loader Template':
  54. $form[$category][$guid]['add'] = array(
  55. '#type' => 'submit',
  56. '#title' => 'Import'
  57. );
  58. break;
  59. case 'Materialized View':
  60. break;
  61. case 'Extension Module':
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. }
  68. return $form;
  69. }
  70. function tripal_core_extensions_form_validate($form, &$form_state) {
  71. }
  72. function tripal_core_extensions_form_submit($form, &$form_state) {
  73. }