]> dev.renevier.net Git - syj.git/blob - application/forms/TableAbstract.php
version 0.1
[syj.git] / application / forms / TableAbstract.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 abstract class Syj_Form_TableAbstract extends Zend_Form
6 {
7     protected $_elementDecorators = array(
8                           'ViewHelper',
9                           array(array('td' => 'HtmlTag'), array('tag' => 'td', 'style' => 'width: 100%' )),
10                           array('label', array('tag' => 'td')),
11                           array(array('tr' => 'HtmlTag'), array('tag' => 'tr')),
12                           array('TableDescription'));
13
14     protected $_decorators = array(
15                             'FormErrors' => array('decorator' => 'FormErrors', 'options' => null),
16                             'FormElements' => array('decorator' => 'FormElements', 'options' => null),
17                             'Form' => array('decorator' => 'Form', 'options' => null),
18                             );
19
20     protected $_displaygroupDecorators = array(
21                 'FormElements',
22                 array('HtmlTag', array('tag' => 'table')));
23
24     protected $_defaultClassName = "form-table-elem";
25
26     public function __construct($options = null) {
27         $this->addPrefixPath('Syj_Form_Decorator', APPLICATION_PATH . '/forms/decorator/', 'decorator');
28         parent::__construct($options);
29     }
30
31     protected function setMainElements(array $elements) {
32         $this->setElements($elements);
33         $this->addDisplayGroup(array_map(function ($elem) { return $elem[1]; }, $elements), 'data');
34         $this->setDisplayGroupDecorators($this->_displaygroupDecorators);
35
36         return $this;
37     }
38
39     public function addElement($element, $name = null, $options = null)
40     {
41         $res = parent::addElement($element, $name, $options);
42         if ($element instanceof Zend_Form_Element) {
43             $name = $element->getName();
44         }
45         $element = $this->_elements[$name];
46         if ($element instanceof Zend_Form_Element_Text or $element instanceof Zend_Form_Element_Password) {
47             if ($this->getAttrib('class') === null) {
48                 $element->setAttrib('class', $this->_defaultClassName);
49             }
50         } else if ($element instanceof Zend_Form_Element_Submit) {
51             $element->setDecorators(array(
52                         'ViewHelper',
53                         array('Description', array('tag' => '')),
54                         array('HtmlTag', array('tag' => 'p', 'class' => 'center')),
55                         ));
56         }
57         return $res;
58     }
59 }