]> dev.renevier.net Git - syj.git/blob - application/forms/decorator/TableDescription.php
version 0.1
[syj.git] / application / forms / decorator / TableDescription.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 require_once 'Zend/Form/Decorator/Description.php';
6 require_once 'Zend/Form/Decorator/HtmlTag.php';
7
8 /*
9  * wraps description content in a <td> tag then in a <tr> tag
10  */
11 class Syj_Form_Decorator_TableDescription extends Zend_Form_Decorator_Description
12 {
13
14     public function getClass()
15     {
16         $class = $this->getOption('class');
17         if (null === $class) {
18             $class = 'message';
19             $this->setOption('class', $class);
20         }
21
22         return $class;
23     }
24
25     public function render($content)
26     {
27         $element = $this->getElement();
28         $view    = $element->getView();
29         if (null === $view) {
30             return $content;
31         }
32
33         $description = $element->getDescription();
34         $description = trim($description);
35
36         if (!empty($description) && (null !== ($translator = $element->getTranslator()))) {
37             $description = $translator->translate($description);
38         }
39
40         if (empty($description)) {
41             return $content;
42         }
43
44         $separator = $this->getSeparator();
45         $placement = $this->getPlacement();
46         $class     = $this->getClass();
47         $escape    = $this->getEscape();
48
49         $options   = $this->getOptions();
50
51         if ($escape) {
52             $description = $view->escape($description);
53         }
54
55         $decorator = new Zend_Form_Decorator_HtmlTag(array('tag' => 'div',
56                             'id'  => $this->getElement()->getName() . '-desc',
57                             'class' => $class));
58         $description = $decorator->render($description);
59         $decorator = new Zend_Form_Decorator_HtmlTag(array('tag' => 'td'));
60         $description = $decorator->render($description);
61         $description = '<td>&nbsp;</td>' . $description;
62         $decorator = new Zend_Form_Decorator_HtmlTag(array('tag' => 'tr'));
63         $description = $decorator->render($description);
64
65         switch ($placement) {
66             case self::PREPEND:
67                 return $description . $separator . $content;
68             case self::APPEND:
69             default:
70                 return $content . $separator . $description;
71         }
72     }
73
74 }