/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
  2. namespace common\extensions\external_repository_manager\implementation\box;
  3. use repository\RepositoryManager;
  4. use repository\ExternalInstance;
  5. use common\extensions\external_repository_manager\ExternalRepositoryManager;
  6. use common\extensions\external_repository_manager\ExternalRepositoryComponent;
  7. use common\libraries\Application;
  8. use common\libraries\Translation;
  9. use common\libraries\Redirect;
  10. use common\libraries\Utilities;
  11. class BoxExternalRepositoryManagerExternalSyncerComponent extends BoxExternalRepositoryManager
  12. {
  13. function run()
  14. {
  15. ExternalRepositoryComponent :: launch($this);
  16. }
  17. function synchronize_external_repository_object(ExternalRepositoryObject $external_object)
  18. {
  19. $synchronization_data = $external_object->get_synchronization_data();
  20. $content_object = $synchronization_data->get_content_object();
  21. $values = array();
  22. $values[ExternalInstance :: PROPERTY_ID] = $external_object->get_id();
  23. $values[ExternalInstance :: PROPERTY_TITLE] = trim(html_entity_decode(strip_tags($content_object->get_title())));
  24. $values[ExternalInstance :: PROPERTY_DESCRIPTION] = trim(html_entity_decode(strip_tags($content_object->get_description())));
  25. if ($this->get_external_repository_connector()->update_external_repository_object($values))
  26. {
  27. $external_object = $this->get_external_repository_connector()->retrieve_external_repository_object($external_object->get_id());
  28. $synchronization_data->set_content_object_timestamp($content_object->get_modification_date());
  29. $synchronization_data->set_external_repository_object_timestamp($external_object->get_modified());
  30. if ($synchronization_data->update())
  31. {
  32. $parameters = $this->get_parameters();
  33. $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_VIEW_CONTENT_OBJECTS;
  34. $parameters[RepositoryManager :: PARAM_CONTENT_OBJECT_ID] = $content_object->get_id();
  35. $this->redirect(Translation :: get('ObjectUpdated', array(
  36. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), false, $parameters, array(
  37. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY,
  38. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
  39. }
  40. else
  41. {
  42. $parameters = $this->get_parameters();
  43. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  44. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
  45. $this->redirect(Translation :: get('ObjectFailedUpdated', array(
  46. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  47. }
  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('ExternalRepository')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  56. }
  57. }
  58. }
  59. ?>