PageRenderTime 17ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/importer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-box-dev/
PHP | 73 lines | 64 code | 9 blank | 0 comment | 4 complexity | e9e15125f38bde1fd82cf232350ce9ff MD5 | raw file
 1<?php
 2namespace common\extensions\external_repository_manager\implementation\box;
 3
 4use common\libraries\Utilities;
 5use common\libraries\Translation;
 6use common\libraries\StringUtilities;
 7use common\libraries\PlatformSetting;
 8use common\libraries\Filesystem;
 9use common\libraries\Application;
10
11use repository\RepositoryManager;
12use repository\ContentObject;
13use repository\ExternalSync;
14use repository\content_object\document\Document;
15
16use common\extensions\external_repository_manager\ExternalRepositoryManager;
17use common\extensions\external_repository_manager\ExternalRepositoryComponent;
18
19class BoxExternalRepositoryManagerImporterComponent extends BoxExternalRepositoryManager
20{
21
22    function run()
23    {
24        ExternalRepositoryComponent :: launch($this);
25    }
26
27    function import_external_repository_object($external_object)
28    {
29        if ($external_object->is_importable())
30        {
31            $file = ContentObject :: factory(Document :: get_type_name());
32            $file->set_title($external_object->get_title());
33            
34            if (PlatformSetting :: get('description_required', 'repository') && StringUtilities :: is_null_or_empty($external_object->get_description()))
35            {
36                $file->set_description('-');
37            }
38            else
39            {
40                $file->set_description($external_object->get_description());
41            }
42            
43            $file->set_owner_id($this->get_user_id());
44            $file->set_filename(Filesystem :: create_safe_name($external_object->get_title()));
45            $file->set_in_memory_file($external_object->get_content_data($external_object->get_id()));
46            if ($file->create())
47            {
48                ExternalSync :: quicksave($file, $external_object, $this->get_external_repository()->get_id());
49                $parameters = $this->get_parameters();
50                $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_BROWSE_CONTENT_OBJECTS;
51                $this->redirect(Translation :: get('ObjectImported', null, Utilities :: COMMON_LIBRARIES), false, $parameters, array(
52                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY, 
53                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
54            }
55            else
56            {
57                $parameters = $this->get_parameters();
58                $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
59                $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
60                $this->redirect(Translation :: get('ObjectFailedImported', null, Utilities :: COMMON_LIBRARIES), true, $parameters);
61            }
62        }
63        else
64        {
65            $parameters = $this->get_parameters();
66            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
67            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
68            $this->redirect(null, false, $parameters);
69        }
70    
71    }
72}
73?>