/php/box_external_repository_manager.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-box-dev/ · PHP · 183 lines · 92 code · 23 blank · 68 comment · 2 complexity · ef668c44338e9e3a2c5dc48842807bbc MD5 · raw file

  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\box;
  3. use common\libraries\Translation;
  4. use common\libraries\Request;
  5. use common\libraries\Path;
  6. use common\libraries\ActionBarSearchForm;
  7. use repository\content_object\document\Document;
  8. use common\extensions\external_repository_manager\ExternalRepositoryManager;
  9. use common\extensions\external_repository_manager\ExternalRepositoryObject;
  10. use common\extensions\external_repository_manager\ExternalRepositoryObjectRenderer;
  11. use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay;
  12. use repository\ExternalSetting;
  13. class BoxExternalRepositoryManager extends ExternalRepositoryManager
  14. {
  15. const REPOSITORY_TYPE = 'box';
  16. const PARAM_FEED_TYPE = 'feed';
  17. const PARAM_FEED_IDENTIFIER = 'identifier';
  18. const FEED_TYPE_GENERAL = 1;
  19. /**
  20. * @param Application $application
  21. */
  22. function __construct($external_repository, $application)
  23. {
  24. parent :: __construct($external_repository, $application);
  25. $this->set_parameter(self :: PARAM_FEED_TYPE, Request :: get(self :: PARAM_FEED_TYPE));
  26. }
  27. /* (non-PHPdoc)
  28. * @see application/common/external_repository_manager/ExternalRepositoryManager#get_application_component_path()
  29. */
  30. function get_application_component_path()
  31. {
  32. return Path :: get_common_extensions_path() . 'external_repository_manager/implementation/box/php/component/';
  33. }
  34. /* (non-PHPdoc)
  35. * @see application/common/external_repository_manager/ExternalRepositoryManager#validate_settings()
  36. */
  37. function validate_settings($external_repository)
  38. {
  39. // $key = ExternalRepositorySetting :: get('key');
  40. // $secret = ExternalRepositorySetting :: get('secret');
  41. //
  42. // if (! $key || ! $secret)
  43. // {
  44. // return false;
  45. // }
  46. return true;
  47. }
  48. /* (non-PHPdoc)
  49. * @see application/common/external_repository_manager/ExternalRepositoryManager#support_sorting_direction()
  50. */
  51. function support_sorting_direction()
  52. {
  53. return true;
  54. }
  55. /**
  56. * @param ExternalRepositoryObject $object
  57. * @return string
  58. */
  59. function get_external_repository_object_viewing_url(ExternalRepositoryObject $object)
  60. {
  61. $parameters = array();
  62. $parameters[self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = self :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  63. $parameters[self :: PARAM_EXTERNAL_REPOSITORY_ID] = $object->get_id();
  64. return $this->get_url($parameters);
  65. }
  66. /* (non-PHPdoc)
  67. * @see application/common/external_repository_manager/ExternalRepositoryManager#get_menu_items()
  68. */
  69. function get_menu_items()
  70. {
  71. $menu_items = array();
  72. $general = array();
  73. $general['title'] = Translation :: get('Box.net');
  74. $general['url'] = $this->get_url(array(self :: PARAM_FEED_TYPE => self :: FEED_TYPE_GENERAL), array(
  75. ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY));
  76. $general['class'] = 'home';
  77. $menu_items[] = $general;
  78. $folders = $this->get_external_repository_manager_connector()->retrieve_folders($this->get_url(array(
  79. self :: PARAM_FOLDER => '__PLACEHOLDER__')));
  80. $menu_items = array_merge($menu_items, $folders);
  81. return $menu_items;
  82. }
  83. /* (non-PHPdoc)
  84. * @see application/common/external_repository_manager/ExternalRepositoryManager#is_ready_to_be_used()
  85. */
  86. function is_ready_to_be_used()
  87. {
  88. return false;
  89. }
  90. /* (non-PHPdoc)
  91. * @see application/common/external_repository_manager/ExternalRepositoryManager#get_external_repository_actions()
  92. */
  93. function get_external_repository_actions()
  94. {
  95. $actions = array(self :: ACTION_BROWSE_EXTERNAL_REPOSITORY, self :: ACTION_UPLOAD_EXTERNAL_REPOSITORY,
  96. self :: ACTION_EXPORT_EXTERNAL_REPOSITORY);
  97. $is_platform = $this->get_user()->is_platform_admin() && (count(ExternalSetting :: get_all($this->get_external_repository()->get_id())) > 0);
  98. if ($is_platform)
  99. {
  100. $actions[] = self :: ACTION_CONFIGURE_EXTERNAL_REPOSITORY;
  101. }
  102. return $actions;
  103. }
  104. /* (non-PHPdoc)
  105. * @see application/common/external_repository_manager/ExternalRepositoryManager#get_available_renderers()
  106. */
  107. function get_available_renderers()
  108. {
  109. return array(ExternalRepositoryObjectRenderer :: TYPE_TABLE);
  110. }
  111. /* (non-PHPdoc)
  112. * @see application/common/external_repository_manager/ExternalRepositoryManager#get_content_object_type_conditions()
  113. */
  114. function get_content_object_type_conditions()
  115. {
  116. /*$file_types = Document :: get_file_types();
  117. $image_conditions = array();
  118. foreach ($file_types as $image_type)
  119. {
  120. $file_conditions[] = new PatternMatchCondition(Document :: PROPERTY_FILENAME, '*.' . $file_type, Document :: get_type_name());
  121. }
  122. return new OrCondition($image_conditions);*/
  123. }
  124. /**
  125. * @return string
  126. */
  127. function get_repository_type()
  128. {
  129. return self :: REPOSITORY_TYPE;
  130. }
  131. /**
  132. * Helper function for the SubManager class,
  133. * pending access to class constants via variables in PHP 5.3
  134. * e.g. $name = $class :: DEFAULT_ACTION
  135. *
  136. * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
  137. * Instead use:
  138. * - self :: DEFAULT_ACTION in the context of this class
  139. * - YourSubManager :: DEFAULT_ACTION in all other application classes
  140. */
  141. static function get_default_action()
  142. {
  143. return self :: DEFAULT_ACTION;
  144. }
  145. /**
  146. * Helper function for the SubManager class,
  147. * pending access to class constants via variables in PHP 5.3
  148. * e.g. $name = $class :: PARAM_ACTION
  149. *
  150. * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
  151. * Instead use:
  152. * - self :: PARAM_ACTION in the context of this class
  153. * - YourSubManager :: PARAM_ACTION in all other application classes
  154. */
  155. static function get_action_parameter()
  156. {
  157. return self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION;
  158. }
  159. }
  160. ?>