PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/groups_viewer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-bitbucket-dev/
PHP | 92 lines | 76 code | 16 blank | 0 comment | 3 complexity | 797b2bd958b614286b49512ce9d551da MD5 | raw file
 1<?php
 2namespace common\extensions\external_repository_manager\implementation\bitbucket;
 3
 4use repository;
 5
 6use common\libraries\Request;
 7use common\libraries\ToolbarItem;
 8use common\libraries\Translation;
 9use common\libraries\Theme;
10use common\libraries\SortableTableFromArray;
11use common\libraries\ActionBarRenderer;
12
13use common\extensions\external_repository_manager\ExternalRepositoryManager;
14use common\extensions\external_repository_manager\ExternalRepositoryComponent;
15
16use repository\ExternalSetting;
17
18class BitbucketExternalRepositoryManagerGroupsViewerComponent extends BitbucketExternalRepositoryManager
19{
20    private $bitbucket;
21
22    function run()
23    {
24        $this->display_header();
25        
26        echo ($this->get_action_bar()->as_html());
27        
28        $groups = $this->get_external_repository_manager_connector()->retrieve_groups(ExternalSetting :: get('username', $this->get_external_repository()->get_id()));
29        if ($groups)
30        {
31            $list_groups = array();
32            foreach ($groups as $group)
33            {
34                $group_row = array();
35                $group_row[] = $group->get_name();
36                $group_row[] = $group->get_permission();
37                
38                $member_row = array();
39                foreach ($group->get_members() as $member)
40                {
41                    $member_row[] = '<option>';
42                    if (! $member->first_name || ! $member->last_name)
43                    {
44                        $member_row[] = $member->username;
45                    }
46                    else
47                    {
48                        $member_row[] = $member->first_name;
49                        $member_row[] = ' ' . $member->last_name;
50                        $member_row[] = ' (' . $member->username . ')';
51                    }
52                    $member_row[] = '</option>';
53                }
54                
55                $group_row[] = '<select>' . implode('', $member_row) . '</select>';
56                $actions = array();
57                
58                $toolbar_item = new ToolbarItem(Translation :: get('Delete'), Theme :: get_common_image_path() . 'action_delete.png', $this->get_external_repository_group_deleting_url($group->get_id()), ToolbarItem :: DISPLAY_ICON);
59                $actions[] = $toolbar_item->as_html();
60                $toolbar_item = new ToolbarItem(Translation :: get('AddUser'), Theme :: get_image_path() . 'action_add_user.png', $this->get_external_repository_adding_user_url($group->get_id()), ToolbarItem :: DISPLAY_ICON);
61                $actions[] = $toolbar_item->as_html();
62                $toolbar_item = new ToolbarItem(Translation :: get('DeleteUser'), Theme :: get_image_path() . 'action_delete_user.png', $this->get_external_repository_deleting_user_url($group->get_id()), ToolbarItem :: DISPLAY_ICON);
63                $actions[] = $toolbar_item->as_html();
64                $group_row[] = implode(' ', $actions);
65                $list_groups[] = $group_row;
66            }
67            
68            $table = new SortableTableFromArray($list_groups);
69            $table->set_header(0, Translation :: get('Name'));
70            $table->set_header(1, Translation :: get('Permission'));
71            $table->set_header(2, Translation :: get('Members'));
72            $table->set_header(3, '');
73            
74            echo ($table->as_html());
75        }
76        else
77        {
78            $this->display_warning_message(Translation :: get('NoGroups'));
79        }
80        $this->display_footer();
81    }
82
83    function get_action_bar()
84    {
85        $action_bar = new ActionBarRenderer(ActionBarRenderer :: TYPE_HORIZONTAL);
86        
87        $action_bar->add_common_action(new ToolbarItem(Translation :: get('CreateGroup'), Theme :: get_image_path() . 'action_create.png', $this->get_external_repository_group_creating_url(), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
88        
89        return $action_bar;
90    }
91}
92?>