operation__phylotree_vis_formatter.inc

File

tripal_chado/includes/TripalFields/operation__phylotree_vis/operation__phylotree_vis_formatter.inc
View source
  1. <?php
  2. class operation__phylotree_vis_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Phylogenetic tree visualisation';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('operation__phylotree_vis');
  7. /**
  8. * @see TripalFieldFormatter::view()
  9. */
  10. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  11. global $user;
  12. if (count($items) > 0) {
  13. if (user_access('administrator')) {
  14. $message = t('Site administrators: You can customize the look of phylogenetic trees at the !menu page.',
  15. array('!menu' => l('Phylogeny and Taxonomy', 'admin/tripal/storage/chado/phylogeny')));
  16. $admin_message = tripal_set_message($message, TRIPAL_INFO, array('return_html' => TRUE));
  17. $element[0]['admin_message'] = array(
  18. '#type' => 'markup',
  19. '#markup' => $admin_message,
  20. );
  21. }
  22. $phylotree = $entity->chado_record;
  23. $node = new stdClass();
  24. $node->phylotree = $phylotree;
  25. $phylotree = chado_expand_var($phylotree,'field','phylotree.comment');
  26. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.phylotree');
  27. tripal_phylogeny_prepare_tree_viewer($phylotree);
  28. if ($phylotree->has_nodes) {
  29. $element[0]['comment'] = array(
  30. '#type' => 'markup',
  31. '#markup' => 'Click a species to view its species page.',
  32. );
  33. $ajax_loader = url(drupal_get_path('module', 'tripal') . '/theme/images/ajax-loader.gif');
  34. $element[0]['phylogram'] = array(
  35. '#type' => 'markup',
  36. '#markup' => '
  37. <div id="phylogram">
  38. <img src="' . $ajax_loader . '" class="phylogram-ajax-loader"/>
  39. </div>
  40. '
  41. );
  42. }
  43. }
  44. }
  45. }