PageRenderTime 21ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/php/box_external_repository_manager.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-box-dev/
PHP | 183 lines | 92 code | 23 blank | 68 comment | 2 complexity | ef668c44338e9e3a2c5dc48842807bbc MD5 | raw file
  1<?php
  2namespace common\extensions\external_repository_manager\implementation\box;
  3
  4use common\libraries\Translation;
  5use common\libraries\Request;
  6use common\libraries\Path;
  7use common\libraries\ActionBarSearchForm;
  8use repository\content_object\document\Document;
  9use common\extensions\external_repository_manager\ExternalRepositoryManager;
 10use common\extensions\external_repository_manager\ExternalRepositoryObject;
 11use common\extensions\external_repository_manager\ExternalRepositoryObjectRenderer;
 12use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay;
 13
 14use repository\ExternalSetting;
 15
 16class BoxExternalRepositoryManager extends ExternalRepositoryManager
 17{
 18    const REPOSITORY_TYPE = 'box';
 19    
 20    const PARAM_FEED_TYPE = 'feed';
 21    const PARAM_FEED_IDENTIFIER = 'identifier';
 22    
 23    const FEED_TYPE_GENERAL = 1;
 24
 25    /**
 26     * @param Application $application
 27     */
 28    function __construct($external_repository, $application)
 29    {
 30        parent :: __construct($external_repository, $application);
 31        $this->set_parameter(self :: PARAM_FEED_TYPE, Request :: get(self :: PARAM_FEED_TYPE));
 32    }
 33
 34    /* (non-PHPdoc)
 35     * @see application/common/external_repository_manager/ExternalRepositoryManager#get_application_component_path()
 36     */
 37    function get_application_component_path()
 38    {
 39        return Path :: get_common_extensions_path() . 'external_repository_manager/implementation/box/php/component/';
 40    }
 41
 42    /* (non-PHPdoc)
 43     * @see application/common/external_repository_manager/ExternalRepositoryManager#validate_settings()
 44     */
 45    function validate_settings($external_repository)
 46    {
 47        //    	$key = ExternalRepositorySetting :: get('key');
 48        //        $secret = ExternalRepositorySetting :: get('secret');
 49        //
 50        //        if (! $key || ! $secret)
 51        //        {
 52        //            return false;
 53        //        }
 54        return true;
 55    }
 56
 57    /* (non-PHPdoc)
 58     * @see application/common/external_repository_manager/ExternalRepositoryManager#support_sorting_direction()
 59     */
 60    function support_sorting_direction()
 61    {
 62        return true;
 63    }
 64
 65    /**
 66     * @param ExternalRepositoryObject $object
 67     * @return string
 68     */
 69    function get_external_repository_object_viewing_url(ExternalRepositoryObject $object)
 70    {
 71        $parameters = array();
 72        $parameters[self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = self :: ACTION_VIEW_EXTERNAL_REPOSITORY;
 73        $parameters[self :: PARAM_EXTERNAL_REPOSITORY_ID] = $object->get_id();
 74        
 75        return $this->get_url($parameters);
 76    }
 77
 78    /* (non-PHPdoc)
 79     * @see application/common/external_repository_manager/ExternalRepositoryManager#get_menu_items()
 80     */
 81    function get_menu_items()
 82    {
 83        $menu_items = array();
 84        
 85        $general = array();
 86        $general['title'] = Translation :: get('Box.net');
 87        $general['url'] = $this->get_url(array(self :: PARAM_FEED_TYPE => self :: FEED_TYPE_GENERAL), array(
 88                ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY));
 89        $general['class'] = 'home';
 90        $menu_items[] = $general;
 91        
 92        $folders = $this->get_external_repository_manager_connector()->retrieve_folders($this->get_url(array(
 93                self :: PARAM_FOLDER => '__PLACEHOLDER__')));
 94        $menu_items = array_merge($menu_items, $folders);
 95        return $menu_items;
 96    }
 97
 98    /* (non-PHPdoc)
 99     * @see application/common/external_repository_manager/ExternalRepositoryManager#is_ready_to_be_used()
100     */
101    function is_ready_to_be_used()
102    {
103        return false;
104    }
105
106    /* (non-PHPdoc)
107     * @see application/common/external_repository_manager/ExternalRepositoryManager#get_external_repository_actions()
108     */
109    function get_external_repository_actions()
110    {
111        $actions = array(self :: ACTION_BROWSE_EXTERNAL_REPOSITORY, self :: ACTION_UPLOAD_EXTERNAL_REPOSITORY, 
112                self :: ACTION_EXPORT_EXTERNAL_REPOSITORY);
113        
114        $is_platform = $this->get_user()->is_platform_admin() && (count(ExternalSetting :: get_all($this->get_external_repository()->get_id())) > 0);
115        
116        if ($is_platform)
117        {
118            $actions[] = self :: ACTION_CONFIGURE_EXTERNAL_REPOSITORY;
119        }
120        return $actions;
121    }
122
123    /* (non-PHPdoc)
124     * @see application/common/external_repository_manager/ExternalRepositoryManager#get_available_renderers()
125     */
126    function get_available_renderers()
127    {
128        return array(ExternalRepositoryObjectRenderer :: TYPE_TABLE);
129    }
130
131    /* (non-PHPdoc)
132     * @see application/common/external_repository_manager/ExternalRepositoryManager#get_content_object_type_conditions()
133     */
134    function get_content_object_type_conditions()
135    {
136        /*$file_types = Document :: get_file_types();
137        $image_conditions = array();
138        foreach ($file_types as $image_type)
139        {
140            $file_conditions[] = new PatternMatchCondition(Document :: PROPERTY_FILENAME, '*.' . $file_type, Document :: get_type_name());
141        }
142        return new OrCondition($image_conditions);*/
143    }
144
145    /**
146     * @return string
147     */
148    function get_repository_type()
149    {
150        return self :: REPOSITORY_TYPE;
151    }
152
153    /**
154     * Helper function for the SubManager class,
155     * pending access to class constants via variables in PHP 5.3
156     * e.g. $name = $class :: DEFAULT_ACTION
157     *
158     * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
159     * Instead use:
160     * - self :: DEFAULT_ACTION in the context of this class
161     * - YourSubManager :: DEFAULT_ACTION in all other application classes
162     */
163    static function get_default_action()
164    {
165        return self :: DEFAULT_ACTION;
166    }
167
168    /**
169     * Helper function for the SubManager class,
170     * pending access to class constants via variables in PHP 5.3
171     * e.g. $name = $class :: PARAM_ACTION
172     *
173     * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
174     * Instead use:
175     * - self :: PARAM_ACTION in the context of this class
176     * - YourSubManager :: PARAM_ACTION in all other application classes
177     */
178    static function get_action_parameter()
179    {
180        return self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION;
181    }
182}
183?>