/php/bitbucket_external_repository_object_display.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-bitbucket-dev/ · PHP · 117 lines · 99 code · 16 blank · 2 comment · 4 complexity · 3f2fce88a3e3c5981713313218ff772b MD5 · raw file

  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\bitbucket;
  3. use common\libraries;
  4. use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay;
  5. use common\libraries\Theme;
  6. use common\libraries\Translation;
  7. use common\libraries\SortableTableFromArray;
  8. use common\libraries\DatetimeUtilities;
  9. use common\libraries\ToolbarItem;
  10. use common\libraries\Filesystem;
  11. use common\libraries\Path;
  12. class BitbucketExternalRepositoryObjectDisplay extends ExternalRepositoryObjectDisplay
  13. {
  14. function get_display_properties()
  15. {
  16. $object = $this->get_object();
  17. $properties = parent :: get_display_properties();
  18. $properties[Translation :: get('Branches')] = implode(', ', $object->get_branches());
  19. if ($object->get_download_link())
  20. {
  21. $toolbar_item = new ToolbarItem(Translation :: get('Download'), Theme :: get_image_path() . 'action_download.png', $object->get_download_link(), ToolbarItem :: DISPLAY_ICON);
  22. $properties[Translation :: get('Download')] = $toolbar_item->as_html();
  23. }
  24. return $properties;
  25. }
  26. function get_preview($is_thumbnail = false)
  27. {
  28. $object = $this->get_object();
  29. if ($object->get_logo())
  30. {
  31. $class = ($is_thumbnail ? 'thumbnail' : 'with_border');
  32. $html = array();
  33. $html[] = '<img class="' . $class . '" src="' . $object->get_logo() . '" />';
  34. return implode("\n", $html);
  35. }
  36. else
  37. {
  38. return parent :: get_preview($is_thumbnail);
  39. }
  40. }
  41. function as_html()
  42. {
  43. $html = array();
  44. $html[] = parent :: as_html();
  45. $object = $this->get_object();
  46. //tags
  47. $tags = $object->get_tags();
  48. if ($tags)
  49. {
  50. $data = array();
  51. foreach ($tags as $tag)
  52. {
  53. $row = array();
  54. $row[] = $tag->get_name();
  55. $row[] = $tag->get_author();
  56. $row[] = DatetimeUtilities :: format_locale_date(null, $tag->get_time());
  57. $row[] = $tag->get_branch();
  58. $toolbar_item = new ToolbarItem(Translation :: get('Download'), Theme :: get_image_path() . 'action_download.png', $tag->get_download_link(), ToolbarItem :: DISPLAY_ICON);
  59. $row[] = $toolbar_item->as_html();
  60. $data[] = $row;
  61. }
  62. $table = new SortableTableFromArray($data);
  63. $table->set_header(0, Translation :: get('Name'));
  64. $table->set_header(1, Translation :: get('Author'));
  65. $table->set_header(2, Translation :: get('Time'));
  66. $table->set_header(3, Translation :: get('Branch'));
  67. $table->set_header(4, Translation :: get('Download'));
  68. $html[] = '<h3>' . Translation :: get('Tags') . '</h3>';
  69. $html[] = $table->as_html();
  70. }
  71. //changesets
  72. $changesets = $object->get_changesets();
  73. if ($changesets)
  74. {
  75. $data = array();
  76. foreach ($changesets as $changeset)
  77. {
  78. $row = array();
  79. $row[] = $changeset->get_revision();
  80. $row[] = $changeset->get_author();
  81. $row[] = $changeset->get_message();
  82. $row[] = DatetimeUtilities :: format_locale_date(null, $changeset->get_time());
  83. $row[] = $changeset->get_branch();
  84. $toolbar_item = new ToolbarItem(Translation :: get('Download'), Theme :: get_image_path() . 'action_download.png', $changeset->get_download_link(), ToolbarItem :: DISPLAY_ICON);
  85. $row[] = $toolbar_item->as_html();
  86. $data[] = $row;
  87. }
  88. $table = new SortableTableFromArray($data);
  89. $table->set_header(0, Translation :: get('Revision'));
  90. $table->set_header(1, Translation :: get('Author'));
  91. $table->set_header(2, Translation :: get('Message'));
  92. $table->set_header(3, Translation :: get('Time'));
  93. $table->set_header(4, Translation :: get('Branch'));
  94. $table->set_header(5, Translation :: get('Download'));
  95. $html[] = '<h3>' . Translation :: get('Changesets') . '</h3>';
  96. $html[] = $table->as_html();
  97. }
  98. return implode("\n", $html);
  99. }
  100. }
  101. ?>