CatForm.class.php 2.73 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
<?php

/**
 * Cat form.
 *
 * @package    sf
 * @subpackage form
 * @author     Atma
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CatForm extends BaseCatForm
{
    public function configure()
    {
        $this->embedI18n(array('ru', 'en'));
        $this->useFields(array('ru', 'en', 'photo', 'parent_id', 'sort', 'is_filter', 'is_main', 'alias'));

        $parentId = sfContext::getInstance()->getRequest()->getParameter('parentId');
        if ($parentId) {
            $parentId = str_replace('cat_', '', $parentId);
            if ($parentId) {
                $this->setDefault('parent_id', $parentId);
            }
        }
        $this->widgetSchema['is_filter'] = new sfWidgetFormInput(array('type' => 'checkbox', 'label' => 'Фильтр'), ($this->isNew() || $this->getObject()->getIsFilter() ? array('checked' => 'checked') : array()));
        $this->widgetSchema['is_main'] = new sfWidgetFormInputCheckbox(array('label' => 'Отображать в баннере'), array("required" => true));

        $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['ru']['title'] = new sfWidgetFormInputText(array(), array("size" => 64, "maxlength" => 1000, "required" => true));
        $this->widgetSchema['en']['title'] = new sfWidgetFormInputText(array(), array("size" => 64, "maxlength" => 1000, "required" => true));

        $this->widgetSchema['ru']['title']->setLabel('Название');
        $this->widgetSchema['en']['title']->setLabel('Название');

        $otherCat = Doctrine_Query::create()
            ->from("Cat c")
            ->innerJoin("c.Translation t")
            ->where("(SELECT COUNT(*) FROM CatProduct cp WHERE cp.cat_id = c.id) = 0")
            ->andWhere('c.id != ' . $this->getObject()->getId())
            ->execute();

        $this->widgetSchema['photo'] = new sfWidgetFormInputFileUpload(array(
            'label' => 'Изображение',
            'allowedFileTypes' => 'image/png,image/jpeg',
            'script' => '/uploader?key=cat'
        ), array('required' => true));

        $catList = array(
            null => '—'
        );

        if ($otherCat) {
            foreach ($otherCat as $cat) {
                $catList[$cat->getId()] = $cat->getTitle();
            }
        }

        $this->widgetSchema['parent_id'] = new sfWidgetFormChoice(array(
            'choices' => $catList
        ));
        $this->widgetSchema['parent_id'] = new sfWidgetFormInputHidden();
    }
}