PageRenderTime 12ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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