PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/importer.class.php

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