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