developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #1499: jFormsBuilderBase.class.php

File jFormsBuilderBase.class.php, 3.6 KB (added by flav, 7 years ago)
Line 
1<?php
2/**
3* @package     jelix
4* @subpackage  forms
5* @author      Laurent Jouanneau
6* @contributor Loic Mathaud, Dominique Papin
7* @copyright   2006-2007 Laurent Jouanneau, 2007 Dominique Papin
8* @copyright   2007 Loic Mathaud
9* @link        http://www.jelix.org
10* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
11*/
12
13/**
14 * base class of all builder form classes generated by the jform compiler.
15 *
16 * a builder form class is a class which help to generate a form for the output
17 * (html form for example)
18 * @package     jelix
19 * @subpackage  forms
20 */
21abstract class jFormsBuilderBase {
22    /**
23     * a form object
24     * @var jFormsBase
25     */
26    protected $_form;
27
28    /**
29     * the action selector
30     * @var string
31     */
32    protected $_action;
33
34    /**
35     * params for the action
36     * @var array
37     */
38    protected $_actionParams = array();
39
40    /**
41     * form name
42     */
43    protected $_name;
44
45    protected $_endt = '/>';
46    /**
47     * @param jFormsBase $form a form object
48     */
49    public function __construct($form){
50        $this->_form = $form;
51    }
52
53    /**
54     * @param string $action action selector where form will be submit
55     * @param array $actionParams  parameters for the action
56     */
57    public function setAction( $action, $actionParams){
58        $this->_action = $action;
59        $this->_actionParams = $actionParams;
60        $this->_name = jFormsBuilderBase::generateFormName($this->_form->getSelector());
61        if(jApp::coord()->response!= null && jApp::coord()->response->getType() == 'html'){
62            $this->_endt = (jApp::coord()->response->isXhtml()?'/>':'>');
63        }
64    }
65
66    public function getName(){ return  $this->_name; }
67
68    /**
69     * called during the meta content processing in templates
70     * This method should set things on the response, like adding
71     * css styles, javascript links etc.
72     * @param jTpl $tpl the template object
73     */
74    abstract public function outputMetaContent($tpl);
75
76    /**
77     * output the header content of the form
78     * @param array $params some parameters, depending of the type of builder
79     */
80    abstract public function outputHeader($params);
81
82    /**
83     * output the footer content of the form
84     */
85    abstract public function outputFooter();
86
87    /**
88     * displays all the form.
89     * @since 1.1
90     */
91    abstract public function outputAllControls();
92
93    /**
94     * displays some controls.
95     * @param array $ctrls can have controls or names of controls.
96     * @param boolean $getReset : output resret control or not.
97     * @param array $getSubmits can have controls or names of controls (output all submit controls if set true).
98     * @since 1.4
99     */
100    abstract public function outputControls($ctrls, $getReset = true, $getSubmits = true);
101
102    /**
103     * displays the content corresponding of the given control
104     * @param jFormsControl $ctrl the control to display
105     * @param array $attributes  attribute to add on the generated code (html attributes for example)
106     */
107    abstract public function outputControl($ctrl, $attributes=array());
108
109    /**
110     * displays the label corresponding of the given control
111     * @param jFormsControl $ctrl the control to display
112     */
113    abstract public function outputControlLabel($ctrl);
114
115    /**
116     * generates a name for the form
117     */
118    protected static function generateFormName($sel){
119        static $forms = array();
120        $name = 'jforms_'.str_replace('~','_',$sel);
121        if (isset($forms[$sel])) {
122            return $name.(++$forms[$sel]);
123        } else 
124            $forms[$sel] = 0;
125        return $name;
126    }
127}