PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/php/forms/photobucket_external_repository_manager_form.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 130 lines | 96 code | 30 blank | 4 comment | 4 complexity | d47f50add597645444f54e2d7db40d19 MD5 | raw file
  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\photobucket;
  3. use common\libraries\Translation;
  4. use common\libraries\Utilities;
  5. use common\libraries\StringUtilities;
  6. use common\libraries\FormValidator;
  7. use common\extensions\external_repository_manager\ExternalRepositoryObject;
  8. use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay;
  9. /**
  10. * $Id: photobucket_external_repository_manager_form.class.php 224 2009-11-13 14:40:30Z kariboe $
  11. * @package
  12. */
  13. class PhotobucketExternalRepositoryManagerForm extends FormValidator
  14. {
  15. const TYPE_CREATE = 1;
  16. const TYPE_EDIT = 2;
  17. const PREVIEW = 'preview';
  18. const FILE = 'file';
  19. private $application;
  20. private $form_type;
  21. private $external_repository_object;
  22. function __construct($form_type, $action, $application)
  23. {
  24. parent :: __construct(Utilities :: get_classname_from_object($this, true), 'post', $action);
  25. $this->application = $application;
  26. $this->form_type = $form_type;
  27. if ($this->form_type == self :: TYPE_EDIT)
  28. {
  29. $this->build_editing_form();
  30. }
  31. elseif ($this->form_type == self :: TYPE_CREATE)
  32. {
  33. $this->build_creation_form();
  34. }
  35. $this->setDefaults();
  36. }
  37. public function set_external_repository_object(PhotobucketExternalRepositoryObject $external_repository_object)
  38. {
  39. $this->external_repository_object = $external_repository_object;
  40. $defaults[PhotobucketExternalRepositoryObject :: PROPERTY_ID] = $external_repository_object->get_id();
  41. $defaults[PhotobucketExternalRepositoryObject :: PROPERTY_TITLE] = $external_repository_object->get_title();
  42. $defaults[PhotobucketExternalRepositoryObject :: PROPERTY_DESCRIPTION] = $external_repository_object->get_description();
  43. $defaults[PhotobucketExternalRepositoryObject :: PROPERTY_TAGS] = $external_repository_object->get_tags_string(false);
  44. $display = ExternalRepositoryObjectDisplay :: factory($external_repository_object);
  45. $defaults[self :: PREVIEW] = $display->get_preview();
  46. parent :: setDefaults($defaults);
  47. }
  48. public function get_tags()
  49. {
  50. $external_repository_object = $this->external_repository_object;
  51. return implode(",", $external_repository_object->get_tags());
  52. }
  53. function build_basic_form()
  54. {
  55. $this->addElement('text', PhotobucketExternalRepositoryObject :: PROPERTY_TITLE, Translation :: get('Title', null, Utilities :: COMMON_LIBRARIES), array(
  56. "size" => "50"));
  57. $this->addRule(PhotobucketExternalRepositoryObject :: PROPERTY_TITLE, Translation :: get('ThisFieldIsRequired', null, Utilities :: COMMON_LIBRARIES), 'required');
  58. $this->addElement('textarea', PhotobucketExternalRepositoryObject :: PROPERTY_TAGS, Translation :: get('Tags'), array(
  59. "rows" => "2", "cols" => "80"));
  60. $this->addElement('textarea', PhotobucketExternalRepositoryObject :: PROPERTY_DESCRIPTION, Translation :: get('Description', null, Utilities :: COMMON_LIBRARIES), array(
  61. "rows" => "7", "cols" => "80"));
  62. }
  63. function build_editing_form()
  64. {
  65. $this->addElement('static', self :: PREVIEW);
  66. $this->build_basic_form();
  67. $this->addElement('hidden', PhotobucketExternalRepositoryObject :: PROPERTY_ID);
  68. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('Edit', null, Utilities :: COMMON_LIBRARIES), array(
  69. 'class' => 'positive update'));
  70. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset', null, Utilities :: COMMON_LIBRARIES), array(
  71. 'class' => 'normal empty'));
  72. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  73. }
  74. function update_photo()
  75. {
  76. return $this->application->get_external_repository_manager_connector()->update_external_repository_object($this->exportValues());
  77. }
  78. function upload_photo()
  79. {
  80. if (StringUtilities :: has_value(($_FILES[self :: FILE]['name'])))
  81. {
  82. return $this->application->get_external_repository_manager_connector()->create_external_repository_object($this->exportValues(), $_FILES[self :: FILE]);
  83. }
  84. else
  85. {
  86. return false;
  87. }
  88. }
  89. function build_creation_form()
  90. {
  91. $this->build_basic_form();
  92. $this->addElement('file', self :: FILE, Translation :: get('FileName'));
  93. $buttons[] = $this->createElement('style_submit_button', 'submit', Translation :: get('Create', null, Utilities :: COMMON_LIBRARIES), array(
  94. 'class' => 'positive'));
  95. $buttons[] = $this->createElement('style_reset_button', 'reset', Translation :: get('Reset', null, Utilities :: COMMON_LIBRARIES), array(
  96. 'class' => 'normal empty'));
  97. $this->addGroup($buttons, 'buttons', null, '&nbsp;', false);
  98. }
  99. }
  100. ?>