PageRenderTime 28ms CodeModel.GetById 9ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/privileges_viewer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-bitbucket-dev/
PHP | 124 lines | 105 code | 19 blank | 0 comment | 6 complexity | 51e82bb0309fe84188642e1c05ecb41e MD5 | raw file
  1<?php
  2namespace common\extensions\external_repository_manager\implementation\bitbucket;
  3
  4use common\libraries\Request;
  5use common\libraries\ToolbarItem;
  6use common\libraries\Translation;
  7use common\libraries\Theme;
  8use common\libraries\SortableTableFromArray;
  9use common\libraries\ActionBarRenderer;
 10use common\libraries\Path;
 11
 12use common\extensions\external_repository_manager\ExternalRepositoryManager;
 13use common\extensions\external_repository_manager\ExternalRepositoryComponent;
 14
 15require_once dirname(__FILE__) . '/../forms/privilege_granting_form.class.php';
 16
 17class BitbucketExternalRepositoryManagerPrivilegesViewerComponent extends BitbucketExternalRepositoryManager
 18{
 19    private $repository;
 20
 21    function run()
 22    {
 23        $id = Request :: get(ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID);
 24        if ($id)
 25        {
 26            $this->repository = $this->retrieve_external_repository_object($id);
 27            
 28            $parameters = $this->get_parameters();
 29            $parameters[self :: PARAM_EXTERNAL_REPOSITORY_ID] = $id;
 30            $privilege_form = new PriviligeGrantingForm($this->get_url($parameters), $this);
 31            
 32            if ($privilege_form->validate())
 33            {
 34                $success = $privilege_form->grant_privilege();
 35                $message = $success ? Translation :: get('GrantPrivilegeCreated') : Translation :: get('GrantPrivilegeNotCreated');
 36                
 37                $this->redirect($message, ! $success, $parameters);
 38            }
 39            
 40            $this->display_header();
 41            echo ('<h3>' . $this->repository->get_title() . '</h3>');
 42            echo ($this->get_action_bar($id)->as_html());
 43            $privilege_form->display();
 44            
 45            $privileges = $this->repository->get_privileges();
 46            $privileges_groups = $this->repository->get_groups_privileges();
 47            if (count($privileges) > 0 || count($privileges_groups) > 0)
 48            {
 49                if (count($privileges) > 0)
 50                {
 51                    $data = array();
 52                    foreach ($privileges as $privilege)
 53                    {
 54                        $row = array();
 55                        $row[] = $privilege->get_username();
 56                        $row[] = $privilege->get_privilege();
 57                        $row[] = $privilege->get_first_name();
 58                        $row[] = $privilege->get_last_name();
 59                        $actions = array();
 60                        $toolbar_item = new ToolbarItem(Translation :: get('Delete'), Theme :: get_common_image_path() . 'action_delete.png', $this->get_external_repository_privilege_revoking_url($id, $privilege->get_username()), ToolbarItem :: DISPLAY_ICON);
 61                        $actions[] = $toolbar_item->as_html();
 62                        $row[] = implode(' ', $actions);
 63                        $data[] = $row;
 64                    }
 65                    
 66                    $table = new SortableTableFromArray($data);
 67                    $table->set_header(0, Translation :: get('Username'));
 68                    $table->set_header(1, Translation :: get('Privilege'));
 69                    $table->set_header(2, Translation :: get('FirstName'));
 70                    $table->set_header(3, Translation :: get('LastName'));
 71                    $table->set_header(4, '');
 72                    
 73                    echo ($table->as_html());
 74                }
 75                if (count($privileges_groups) > 0)
 76                {
 77                    $data = array();
 78                    foreach ($privileges_groups as $privilege)
 79                    {
 80                        $row = array();
 81                        $row[] = $privilege->get_name();
 82                        $row[] = $privilege->get_privilege();
 83                        $actions = array();
 84                        $toolbar_item = new ToolbarItem(Translation :: get('Delete'), Theme :: get_common_image_path() . 'action_delete.png', $this->get_external_repository_group_privilege_revoking_url($id, $privilege->get_owner_username() . '/' . $privilege->get_group()), ToolbarItem :: DISPLAY_ICON);
 85                        $actions[] = $toolbar_item->as_html();
 86                        $row[] = implode(' ', $actions);
 87                        $data[] = $row;
 88                    }
 89                    
 90                    $table = new SortableTableFromArray($data);
 91                    $table->set_header(0, Translation :: get('Group'));
 92                    $table->set_header(1, Translation :: get('Privilege'));
 93                    $table->set_header(2, '');
 94                    
 95                    echo ($table->as_html());
 96                }
 97            }
 98            else
 99            {
100                $this->display_warning_message(Translation :: get('NoPrivileges'));
101            }
102            $this->display_footer();
103        }
104        else
105        {
106        
107        }
108    }
109
110    function get_repository()
111    {
112        return $this->repository;
113    }
114
115    function get_action_bar($id)
116    {
117        $action_bar = new ActionBarRenderer(ActionBarRenderer :: TYPE_HORIZONTAL);
118        
119        $action_bar->add_common_action(new ToolbarItem(Translation :: get('RevokeAll'), Theme :: get_image_path() . 'action_revoke.png', $this->get_external_repository_privilege_revoking_url($id), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
120        
121        return $action_bar;
122    }
123}
124?>