PageRenderTime 46ms CodeModel.GetById 41ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/php/component/external_syncer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 68 lines | 59 code | 9 blank | 0 comment | 2 complexity | ff24360dcbd741acc7924d6599194e01 MD5 | raw file
 1<?php
 2namespace common\extensions\external_repository_manager\implementation\photobucket;
 3
 4use common\extensions\external_repository_manager\ExternalRepositoryComponent;
 5use common\extensions\external_repository_manager\ExternalRepositoryManager;
 6use common\extensions\external_repository_manager\ExternalRepositoryObject;
 7
 8use common\libraries\Application;
 9use common\libraries\Translation;
10use common\libraries\Utilities;
11
12use repository\RepositoryManager;
13
14class PhotobucketExternalRepositoryManagerExternalSyncerComponent extends PhotobucketExternalRepositoryManager
15{
16
17    function run()
18    {
19        ExternalRepositoryComponent :: launch($this);
20    }
21
22    function synchronize_external_repository_object(ExternalRepositoryObject $external_object)
23    {
24        $synchronization_data = $external_object->get_synchronization_data();
25        $content_object = $synchronization_data->get_content_object();
26        
27        $values = array();
28        $values[ExternalRepositoryObject :: PROPERTY_ID] = $external_object->get_id();
29        $values[ExternalRepositoryObject :: PROPERTY_TITLE] = trim(html_entity_decode(strip_tags($content_object->get_title())));
30        $values[ExternalRepositoryObject :: PROPERTY_DESCRIPTION] = trim(html_entity_decode(strip_tags($content_object->get_description())));
31        $values[PhotobucketExternalRepositoryObject :: PROPERTY_TAGS] = $external_object->get_tags_string(false);
32        
33        if ($this->get_external_repository_manager_connector()->update_external_repository_object($values))
34        {
35            $external_object = $this->get_external_repository_manager_connector()->retrieve_external_repository_object($external_object->get_id());
36            
37            $synchronization_data->set_content_object_timestamp($content_object->get_modification_date());
38            $synchronization_data->set_external_object_timestamp($external_object->get_modified());
39            if ($synchronization_data->update())
40            {
41                $parameters = $this->get_parameters();
42                $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_VIEW_CONTENT_OBJECTS;
43                $parameters[RepositoryManager :: PARAM_CONTENT_OBJECT_ID] = $content_object->get_id();
44                $this->redirect(Translation :: get('ObjectUpdated', array(
45                        'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), false, $parameters, array(
46                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY, 
47                        ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
48            }
49            else
50            {
51                $parameters = $this->get_parameters();
52                $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
53                $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
54                $this->redirect(Translation :: get('ObjectFailedUpdated', array(
55                        'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
56            }
57        }
58        else
59        {
60            $parameters = $this->get_parameters();
61            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
62            $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
63            $this->redirect(Translation :: get(get('ObjectFailedUpdated', array(
64                    'OBJECT' => Translation :: get('ExternalRepository')), Utilities :: COMMON_LIBRARIES)), true, $parameters);
65        }
66    }
67}
68?>