PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/php/component/external_syncer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-box-dev/
PHP | 68 lines | 59 code | 9 blank | 0 comment | 2 complexity | e1407fa186a247165205502565bc30b6 MD5 | raw file
 1<?php
 2namespace common\extensions\external_repository_manager\implementation\box;
 3
 4use repository\RepositoryManager;
 5use repository\ExternalInstance;
 6
 7use common\extensions\external_repository_manager\ExternalRepositoryManager;
 8use common\extensions\external_repository_manager\ExternalRepositoryComponent;
 9
10use common\libraries\Application;
11use common\libraries\Translation;
12use common\libraries\Redirect;
13use common\libraries\Utilities;
14
15class BoxExternalRepositoryManagerExternalSyncerComponent extends BoxExternalRepositoryManager
16{
17
18    function run()
19    {
20        ExternalRepositoryComponent :: launch($this);
21    }
22
23    function synchronize_external_repository_object(ExternalRepositoryObject $external_object)
24    {
25        $synchronization_data = $external_object->get_synchronization_data();
26        $content_object = $synchronization_data->get_content_object();
27        
28        $values = array();
29        $values[ExternalInstance :: PROPERTY_ID] = $external_object->get_id();
30        $values[ExternalInstance :: PROPERTY_TITLE] = trim(html_entity_decode(strip_tags($content_object->get_title())));
31        $values[ExternalInstance :: PROPERTY_DESCRIPTION] = trim(html_entity_decode(strip_tags($content_object->get_description())));
32        
33        if ($this->get_external_repository_connector()->update_external_repository_object($values))
34        {
35            $external_object = $this->get_external_repository_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_repository_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('ObjectFailedUpdated', array(
64                    'OBJECT' => Translation :: get('ExternalRepository')), Utilities :: COMMON_LIBRARIES), true, $parameters);
65        }
66    }
67}
68?>