PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/internal_syncer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 82 lines | 73 code | 9 blank | 0 comment | 5 complexity | f987f0a930b663f0bd0918605ccec104 MD5 | raw file
 1<?php
 2namespace common\extensions\external_repository_manager\implementation\photobucket;
 3
 4use common\libraries\Application;
 5
 6use common\libraries\Utilities;
 7use common\libraries\Redirect;
 8use common\libraries\Translation;
 9use common\libraries\PlatformSetting;
10use common\libraries\StringUtilities;
11
12use repository\RepositoryManager;
13use common\extensions\external_repository_manager\ExternalRepositoryObject;
14use common\extensions\external_repository_manager\ExternalRepositoryComponent;
15use common\extensions\external_repository_manager\ExternalRepositoryManager;
16
17class PhotobucketExternalRepositoryManagerInternalSyncerComponent extends PhotobucketExternalRepositoryManager
18{
19
20    function run()
21    {
22        $syncer = ExternalRepositoryComponent :: factory(ExternalRepositoryComponent :: INTERNAL_SYNCER_COMPONENT, $this);
23        $syncer->run();
24    }
25
26    function synchronize_internal_repository_object(ExternalRepositoryObject $external_object)
27    {
28        $synchronization_data = $external_object->get_synchronization_data();
29        $content_object = $synchronization_data->get_content_object();
30        
31        if (StringUtilities :: is_null_or_empty($external_object->get_title()))
32        {
33            $content_object->set_title($external_object->get_id() . '.jpg');
34        }
35        else
36        {
37            $content_object->set_title($external_object->get_title());
38        }
39        
40        if (PlatformSetting :: get('description_required', 'repository') && StringUtilities :: is_null_or_empty($external_object->get_description()))
41        {
42            $content_object->set_description('-');
43        }
44        else
45        {
46            $content_object->set_description($external_object->get_description());
47        }
48        
49        if ($content_object->update())
50        {
51            $synchronization_data->set_content_object_timestamp($content_object->get_modification_date());
52            $synchronization_data->set_external_object_timestamp($external_object->get_modified());
53            if ($synchronization_data->update())
54            {
55                $parameters = $this->get_parameters();
56                $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_VIEW_CONTENT_OBJECTS;
57                $parameters[RepositoryManager :: PARAM_CONTENT_OBJECT_ID] = $content_object->get_id();
58                $this->redirect(Translation :: get('ObjectUpdated', array(
59                        'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), false, $parameters, array(
60                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY, 
61                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
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(Translation :: get('ObjectFailedUpdated', array(
69                        'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
70            }
71        }
72        else
73        {
74            $parameters = $this->get_parameters();
75            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
76            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
77            $this->redirect(Translation :: get('ObjectFailedUpdated', array(
78                    'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
79        }
80    }
81}
82?>