9109df377a1ad55101bb644a38a1746eeaff105a
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Mail / Html / Element / Container.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Patrick Broens (patrick@patrickbroens.nl)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Abstract class for the form element containers (FORM and FIELDSET) view
27 *
28 * @author Patrick Broens <patrick@patrickbroens.nl>
29 * @package TYPO3
30 * @subpackage form
31 */
32 class tx_form_View_Mail_Html_Element_Container extends tx_form_View_Mail_Html_Element_Abstract {
33
34 /**
35 * Default layout of the container
36 *
37 * @var string
38 */
39 protected $containerWrap = '
40 <tbody>
41 <elements />
42 </tbody>
43 ';
44
45 /**
46 * Constructor
47 *
48 * @param object $model Model for this element
49 * @return void
50 */
51 public function __construct($model) {
52 parent::__construct($model);
53 }
54
55 /**
56 * Get the child objects
57 * and render them as document fragment
58 *
59 * @param DOMDocument $dom DOMDocument
60 * @return DOMDocumentFragment
61 */
62 public function getChildElements(DOMDocument $dom) {
63 $modelChildren = $this->model->getElements();
64 $documentFragment = NULL;
65 foreach ($modelChildren as $key => $modelChild) {
66 $child = $this->createChildElementFromModel($modelChild);
67
68 if ($child) {
69 if ($child->noWrap() === TRUE) {
70 $childNode = $child->render();
71 } else {
72 $childNode = $child->render('elementWrap');
73 }
74 if ($childNode) {
75 $importedNode = $dom->importNode($childNode, TRUE);
76 if (!$documentFragment) {
77 $documentFragment = $dom->createDocumentFragment();
78 }
79 $documentFragment->appendChild($importedNode);
80 }
81 }
82 }
83 return $documentFragment;
84 }
85
86 /**
87 * Create child object from the classname of the model
88 *
89 * @param object $modelChild The childs model
90 * @return object
91 */
92 public function createChildElementFromModel($modelChild) {
93 $childElement = NULL;
94
95 $class = tx_form_Common::getInstance()->getLastPartOfClassName($modelChild);
96 $className = 'tx_form_View_Mail_Html_Element_' . ucfirst($class);
97
98 if (class_exists($className)) {
99 $childElement = t3lib_div::makeInstance($className, $modelChild);
100 }
101
102 return $childElement;
103 }
104 }
105 ?>