Advertisement
turist_ua

Application_Form_Photogallery

Jan 15th, 2012
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.89 KB | None | 0 0
  1. <?php
  2.  
  3. class Application_Form_Photogallery extends Application_Form_Base
  4. {
  5.     private $_options = array(
  6.         'type' => 'add',
  7.         'photo_file' => null,
  8.         'last_dep_id'=> null
  9.     );
  10.  
  11.     public function setUserOptions($opt_list)
  12.     {
  13.         if ($opt_list instanceof Zend_Config) {
  14.             $opt_list = $opt_list->toArray();
  15.         } elseif (!is_array($opt_list)) {
  16.  
  17.             throw new Zend_Application_Exception('Invalid options argument provided');
  18.         }
  19.  
  20.         foreach ($opt_list as $k => $v) {
  21.             if (array_key_exists($k, $this->_options)) {
  22.                  $this->_options[$k] = $v;
  23.             }
  24.         }
  25.         return $this;
  26.     }
  27.  
  28.     public function __construct($opt_list)
  29.     {
  30.         //var_dump($opt_list);
  31.         $this->setUserOptions($opt_list);
  32.         $this->init();
  33.     }
  34.  
  35.     public function init()
  36.     {
  37.         //var_dump($opt_list);
  38.         //$this->setUserOptions($opt_list);
  39.  
  40.         $this->setName('form_photogallery_photo');
  41.         $this->setAttrib('enctype', 'multipart/form-data');
  42.  
  43.         $pgdeps = new Application_Model_PhotogalleryDeps();
  44.         $deps = $pgdeps->getAllPhotogalleryDeps();
  45.  
  46.         $values = array();
  47.         foreach ($deps as $key=>$value)
  48.         {
  49.             $values[$value['dep_id']] = $value['name'];
  50.         }
  51.  
  52.         $pdep = new Zend_Form_Element_Select('dep_id');
  53.         $pdep->setLabel('Галерея')
  54.                 ->addMultiOptions($values);
  55.  
  56.         $preview = new Zend_Form_Element_Textarea('preview');
  57.         $preview->setLabel('Описание к фото')
  58.                 ->setAttrib('id', 'preview_editor')
  59.                 ->addFilter('StringTrim');
  60.  
  61.         $photo = new Zend_Form_Element_File('photo');
  62.         $photo->setLabel('Фото')
  63.                 ->addFilter(new Turist_Filter_File_SetUniqueName(array( 'nameLength' => 10 )))
  64.                 ->addFilter(new Turist_Filter_File_ImageResize(
  65.                             array(
  66.                                 array(
  67.                                 'targetDir' => PUBLIC_PATH . '/userfiles/images/full',
  68.                                 'newSize' => "800*533",
  69.                                 'type'    => 'proportional'
  70.                                 ),
  71.                                 array(
  72.                                 'targetDir' => PUBLIC_PATH . '/userfiles/images/thumb',
  73.                                 'newSize' => "80*80",
  74.                                 'type'    => 'thumb'
  75.                                 )
  76.                             )
  77.                             ));
  78.                 //->setDestination(PUBLIC_PATH . '/userfiles/images');
  79.                 //->addFilter('Rename', 'new.jpg');
  80.  
  81.         $pos = new Zend_Form_Element_Text('pos');
  82.         $pos->setLabel('Порядок сортировки')
  83.              ->addFilter('StringTrim')
  84.              ->addFilter('StripTags')
  85.              ->setValue('0');
  86.  
  87.         $slideshow = new Zend_Form_Element_Checkbox('slideshow');
  88.         $slideshow->setLabel('В слайдшоу на главной')
  89.              ->setCheckedValue('on')
  90.              ->setUncheckedValue('');
  91.  
  92.  
  93.         $submit = new Zend_Form_Element_Submit('submit');
  94.         $submit->setLabel('Отправить');
  95.  
  96.         $this->addElements(array($pdep, $preview, $photo, $pos, $slideshow, $submit));
  97.  
  98.         parent::init();
  99.  
  100.         if ($this->_options['type'] == 'edit' && !is_null($this->_options['photo_file'])) {
  101.             $photo->setDescription($this->_options['photo_file']);
  102.             $photo->setDecorators(array(
  103.              array('ViewScript', array('viewScript' => 'decorators/file.phtml')),
  104.              'File',
  105.              'Errors',
  106.              array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
  107.              array('Label', array('tag' => 'td')),
  108.              array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
  109.          ));
  110.         } else {
  111.             $photo->setDecorators(array(
  112.                  'File',
  113.                  'Errors',
  114.                  array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
  115.                  array('Label', array('tag' => 'td')),
  116.                  array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
  117.              ));
  118.         }
  119.  
  120.         // для content подключаем отдельный декоратор
  121.         $preview->setDecorators(array(new Application_Form_Decorators_Ckeditor()));
  122.  
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement