ProductForm.class.php 5.69 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

/**
 * Product form.
 *
 * @package    sf
 * @subpackage form
 * @author     Atma
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ProductForm extends BaseProductForm
{
    public function configure()
    {
        $this->embedI18n(array('ru', 'en'));
        $this->useFields(array('ru', 'en', 'cats_list', 'product_img', 'sort', 'alias', 'the_weight', 'supplier_id', 'supplier_price', 'is_detail', 'is_main', 'show_main', 'free_shipping', 'certificate', 'tags_list'));

        $this->widgetSchema['tags_list'] = new sfWidgetFormDoctrineChoice(array('label' => 'Теги', 'multiple' => true, 'model' => 'Tag', 'expanded' => true));
        $is_detail_attr = array('onclick' => "$(this).is(':checked') ? $('.a_form_product').addClass('a_form_product_is_detail') : $('.a_form_product').removeClass('a_form_product_is_detail');");
        if($this->isNew() || $this->getObject()->getIsDetail()){
            $is_detail_attr['checked'] = 'checked';
        }
        $this->widgetSchema['is_detail'] = new sfWidgetFormInput(array('type' => 'checkbox', 'label' => 'Подробный просмотр'), $is_detail_attr);
        $this->widgetSchema['is_main'] = new sfWidgetFormInputCheckbox(array('label' => 'Отображать в баннере'), array("required" => true));
        $this->widgetSchema['show_main'] = new sfWidgetFormInputCheckbox(array('label' => 'Показывать на главной'), array("required" => true));
        $this->widgetSchema['free_shipping'] = new sfWidgetFormInputCheckbox(array('label' => 'Бесплатная доставка'), array());
        $this->validatorSchema['free_shipping']  = new sfValidatorBoolean(array('required' => false));
        $this->widgetSchema['alias'] = new sfWidgetFormInputText(array('label' => 'Алиас', ), array("class" => "translateField", "size" => 32, "maxlength" => 255));
        $this->validatorSchema['alias'] = new sfValidatorString(array('max_length' => 500, 'only_english' => true, 'required' => false));
        $this->widgetSchema['the_weight'] = new sfWidgetFormInputText(array('label' => 'Вес ведра (если указано ведро)', ), array("size" => 5, "maxlength" => 10));

        $this->widgetSchema['certificate'] = new sfWidgetFormInputFileUpload(array('label' => 'Сертификат', 'script' => '/uploader'), array('required' => false));
        /*
        $choices = array();
        $choices_dirty = Doctrine_Query::create()
            ->from('Cat c')
            ->where('(SELECT COUNT(*) FROM cat w WHERE w.parent_id = c.id) = 0')
            ->leftJoin('c.Translation t')
            ->fetchArray();
        foreach ($choices_dirty as $item) {
            $ru = $item['Translation']['ru']['available'] == 0 ? 'нет русской версии' : $item['Translation']['ru']['title'];
            $en = $item['Translation']['en']['available'] == 0 ? 'нет английской версии' : $item['Translation']['en']['title'];
            $choices[$item['id']] = $ru . ' | ' . $en;
        }
        $this->widgetSchema['cats_list'] = new sfWidgetFormChoice(array(
            "choices" => $choices,
            'label' => 'Категория'
        ));
        */
        $parentId = sfContext::getInstance()->getRequest()->getParameter('parentId');
        if($parentId){
            $parentId = str_replace('cat_', '', $parentId);
        }
        if($parentId){
            $this->widgetSchema['cats_list'] = new sfWidgetFormChoice(array('choices' => array($parentId => $parentId)));
        }else{
            $this->widgetSchema['cats_list'] = new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Cat', 'expanded' => true));
        }

        $this->widgetSchema['product_img'] = new sfWidgetFormInputFileUpload(array(
            'label' => 'Изображения',
            'allowedFileTypes' => 'image/png,image/jpeg',
            'script' => '/uploader?key=product',
            'multiple' => true
        ), array('required' => true));
        $this->validatorSchema['product_img'] = new sfValidatorString(array('required' => true));
        $this->widgetSchema['ru']['title'] = new sfWidgetFormInputText(array("label" => "Название"), array("size" => 64, "maxlength" => 255, "required" => true));
        $this->widgetSchema['en']['title'] = new sfWidgetFormInputText(array("label" => "Название"), array("size" => 64, "maxlength" => 255, "required" => true));
        $this->validatorSchema['ru']['title'] = new sfValidatorString(array('max_length' => 1000));
        $this->validatorSchema['en']['title'] = new sfValidatorString(array('max_length' => 1000));

        $this->widgetSchema['ru']['description'] = new sfWidgetFormTextarea(array("label" => "Описание"), array("class" => "rich", "rows" => 5, "cols" => 70));
        $this->widgetSchema['en']['description'] = new sfWidgetFormTextarea(array("label" => "Описание"), array("class" => "rich", "rows" => 5, "cols" => 70));
        $this->widgetSchema['ru']['chemical_composition'] = new sfWidgetFormTextarea(array("label" => "Химический состав"), array("class" => "rich", "rows" => 5, "cols" => 70));
        $this->widgetSchema['en']['chemical_composition'] = new sfWidgetFormTextarea(array("label" => "Химический состав"), array("class" => "rich", "rows" => 5, "cols" => 70));
        $this->widgetSchema['supplier_id'] = new sfWidgetFormDoctrineChoice(array('label' => 'Поставщик', 'model' => $this->getRelatedModelName('Suppliers'), 'method' => 'getOrgName', 'add_empty' => true), array());
        $this->widgetSchema['supplier_price'] = new sfWidgetFormInputText(array('label' => 'Цена поставщика'), array("size" => 8, "maxlength" => 8));
    }
}