PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/php/forms/google_docs_external_repository_manager_form.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-google-docs-dev/
PHP | 147 lines | 111 code | 32 blank | 4 comment | 8 complexity | e351b4bc546e3ec4018f2cd747712c6a MD5 | raw file
  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\google_docs;
  3. use common\libraries\Translation;
  4. use common\libraries\Utilities;
  5. use common\libraries\StringUtilities;
  6. use common\libraries\FormValidator;
  7. use common\libraries\Request;
  8. use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay;
  9. /**
  10. * $Id: google_docs_external_repository_manager_form.class.php 224 2009-11-13 14:40:30Z kariboe $
  11. * @package
  12. */
  13. class GoogleDocsExternalRepositoryManagerForm extends FormValidator
  14. {
  15. const TYPE_CREATE = 1;
  16. const TYPE_EDIT = 2;
  17. const TYPE_NEWFOLDER = 3;
  18. const PREVIEW = 'preview';
  19. const FILE = 'file';
  20. private $application;
  21. private $form_type;
  22. private $external_repository_object;
  23. function __construct($form_type, $action, $application)
  24. {
  25. parent :: __construct(Utilities :: get_classname_from_object($this, true), 'post', $action);
  26. $this->application = $application;
  27. $this->form_type = $form_type;
  28. if ($this->form_type == self :: TYPE_EDIT)
  29. {
  30. $this->build_editing_form();
  31. }
  32. elseif ($this->form_type == self :: TYPE_CREATE)
  33. {
  34. $this->build_creation_form();
  35. }
  36. elseif ($this->form_type == self :: TYPE_NEWFOLDER)
  37. {
  38. $this->build_newfolder_form();
  39. }
  40. $this->setDefaults();
  41. }
  42. public function set_external_repository_object(DropboxExternalRepositoryObject $external_repository_object)
  43. {
  44. $this->external_repository_object = $external_repository_object;
  45. $defaults[GoogleDocsExternalRepositoryObject :: PROPERTY_ID] = $external_repository_object->get_id();
  46. $display = ExternalRepositoryObjectDisplay :: factory($external_repository_object);
  47. $defaults[self :: PREVIEW] = $display->get_preview();
  48. parent :: setDefaults($defaults);
  49. }
  50. function build_basic_form()
  51. {
  52. if ($this->form_type == self :: TYPE_EDIT)
  53. {
  54. $this->add_information_message('google_docs_api_move', null, Translation :: get('GoogleDocsAPIMoveImpossible'));
  55. }
  56. }
  57. function build_editing_form()
  58. {
  59. $this->addElement('static', self :: PREVIEW);
  60. $this->build_basic_form();
  61. $this->addElement('hidden', GoogleDocsExternalRepositoryObject :: PROPERTY_ID);
  62. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('Edit', null, Utilities :: COMMON_LIBRARIES), array(
  63. 'class' => 'positive update'));
  64. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset', null, Utilities :: COMMON_LIBRARIES), array(
  65. 'class' => 'normal empty'));
  66. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  67. }
  68. function update_file()
  69. {
  70. return $this->application->get_external_repository_manager_connector()->update_external_repository_object($this->exportValues());
  71. }
  72. function upload_file()
  73. {
  74. if (StringUtilities :: has_value(($_FILES[self :: FILE]['name'])))
  75. {
  76. return $this->application->get_external_repository_manager_connector()->create_external_repository_object($_FILES[self :: FILE]);
  77. }
  78. else
  79. {
  80. return null;
  81. }
  82. }
  83. function build_creation_form()
  84. {
  85. $this->build_basic_form();
  86. $this->addElement('file', self :: FILE, Translation :: get('FileName'));
  87. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('Create'), array(
  88. 'class' => 'positive'));
  89. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset'), array(
  90. 'class' => 'normal empty'));
  91. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  92. }
  93. function build_newfolder_form()
  94. {
  95. $this->addElement('text', 'foldername', 'Name of new folder', array('size' => '50'));
  96. $this->addRule('foldername', Translation :: get('ThisFieldIsRequired', null, Utilities :: COMMON_LIBRARIES), 'required');
  97. $this->addElement('hidden', 'folder');
  98. $this->setDefaults(array('folder' => Request :: get('folder')));
  99. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('Create'), array(
  100. 'class' => 'positive'));
  101. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset'), array(
  102. 'class' => 'normal empty'));
  103. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  104. }
  105. function create_folder($folder)
  106. {
  107. if (! is_null($_POST['foldername']))
  108. {
  109. return $this->application->get_external_repository_manager_connector()->create_external_repository_folder($_POST['foldername'], $_POST['folder']);
  110. }
  111. else
  112. return null;
  113. }
  114. }
  115. ?>