Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
25.00% covered (danger)
25.00%
6 / 24
CRAP
21.43% covered (danger)
21.43%
39 / 182
TDisplayControl
0.00% covered (danger)
0.00%
0 / 1
25.00% covered (danger)
25.00%
6 / 24
3343.53
21.43% covered (danger)
21.43%
39 / 182
 __construct
0.00% covered (danger)
0.00%
0 / 1
6
95.83% covered (success)
95.83%
23 / 24
 show
0.00% covered (danger)
0.00%
0 / 1
1640
0.00% covered (danger)
0.00%
0 / 112
 getField
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getLabel
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getNewLine
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setNewLine
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setVerticalAlign
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
2 / 2
 getVerticalAlign
0.00% covered (danger)
0.00%
0 / 1
3.14
75.00% covered (success)
75.00%
3 / 4
 getColumn1
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getColumn2
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getRow1
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getRow2
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setNoWrapLabel
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getNoWrapLabel
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setNoWrapField
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getNoWrapField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 getLabelAbove
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setLabelAbove
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setOnlineDoc
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
3 / 3
 getOnlineDoc
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setLabelCellWidth
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setFieldCellWidth
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getLabelCellWidth
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
 getFieldCellWidth
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42/**
43* Classe para criar a disposição do rotulo e do input
44* utilizando TABLE para definir o layout rotulo em cima ou na frente do campo
45*/
46class TDisplayControl extends TTable
47{
48    private $label;
49    private $field;
50    private $labelAbove;
51    private $noWrapLabel;
52    private $noWrapField;
53    private $newLine;
54    private $verticalAlign;
55    // Está é a estrutura padrão de saida do display control, 1 ou 2 linhas com 1 ou 2 colunas dependendo do labelAbove
56    private $row1;
57    private $row2; // no caso do label em cima
58    private $column1;
59    private $column2;
60    private $column3; // no caso do label em cima
61    private $onlineDoc;
62    private $labelCellWidth;
63    private $fieldCellWidth;
64
65    /**
66    * Cria a estrutura (table) de exibição do rotulo e do campo no formulário
67    *
68    * @param mixed $strLabel
69    * @param mixed $objField
70    * @param mixed $boolLabelAbove
71    * @param mixed $boolNewLine
72    * @param mixed $boolNoWrapLabel
73    * @param mixed $strVerticalAlign
74    * @param mixed $boolOnlineDoc
75    * @param mixed $boolOnlineDocReadOnly
76    * @param mixed $boolNoWrapField
77    *
78    * @return TDisplayControl
79    */
80    public function __construct( $strLabel = null, $objField = null, $boolLabelAbove = null, $boolNewLine = null, $boolNoWrapLabel = null, $strVerticalAlign = null, $boolOnlineDoc = null, $boolOnlineDocReadOnly = null, $boolNoWrapField = null )
81    {
82        if ( !$objField )
83        {
84            return null;
85        }
86        parent::__construct( $objField->getId() . '_area' );
87        $this->setClass( 'fwField' );
88        $this->setProperty( 'border', '0' );
89        $this->setProperty( 'cellspacing', '0' );
90        $this->setProperty( 'cellpadding', '0' );
91        $this->setVerticalAlign( $strVerticalAlign );
92        $this->setCss( 'background-color', 'transparent' );
93        $this->setCss( 'display', 'inline' );
94
95        $this->setNoWrapLabel( $boolNoWrapLabel );
96        $this->setNoWrapField( $boolNoWrapField );
97        $this->setOnlineDoc( $boolOnlineDoc, $boolOnlineDocReadOnly );
98
99        $this->field = $objField;
100
101        if ( isset( $strLabel ) && !is_null( $strLabel ) )
102        {
103            $this->label = new TLabel( $objField->getId() . '_label', $strLabel );
104            $this->label->clearCss();
105        }
106        $this->labelAbove = $boolLabelAbove === true ? true : false;
107        $this->newLine = $boolNewLine === false ? false : true;
108
109        // criar os objetos da estrura
110        $this->row1 = $this->addRow();
111        $this->column1 = $this->row1->addCell();
112        $this->column2 = $this->row1->addCell();
113        $this->column2->setCss( 'vertical-align', $this->getVerticalAlign() );
114    }
115
116    //---------------------------------------------------------------------------
117    function show( $print = true )
118    {
119        $label = null;
120        $labelClean = null;
121
122        if ( $this->label )
123        {
124            $labelClean = $this->label->getValue();
125            $idLabel = $this->label->getId();
126            $labelValue = '<span id="' . $idLabel . '">' . $labelClean . '</span>';
127            $this->label->setId( $idLabel . '_area' );
128            $this->label->setValue( $labelValue );
129            if ( $this->field->getRequired() )
130            {
131                $this->label->setProperty( 'needed', 'true' );
132
133                if ( defined( 'REQUIRED_FIELD_MARK' ) )
134                {
135                    if( ! trim( $labelClean ) == ''  )
136                    {
137                       $this->label->setValue( $this->label->getValue() . '<span id="' . $this->field->getId() . '_label_required" style="cursor:pointer;" tooltip="true" class="fwFieldRequired" title="Campo obrigatório">' . REQUIRED_FIELD_MARK . '</span>' );
138                    }
139                }
140                else
141                {
142                    $this->label->setClass( $this->label->getClass() . ' fwFieldRequired', false );
143                }
144            }
145            else
146            {
147                // adicionar a tag para ser utilizada para funcao js fwSetRequired()
148                $this->label->setValue( $this->label->getValue() . '<span id="' . $this->field->getId() . '_label_required" style="cursor:pointer;" tooltip="true" class="fwFieldRequired" title=""></span>' );
149            }
150            $label = trim( preg_replace( '/:/', '', $labelClean ) );
151        }
152        $btnTooltip = '';
153
154        if ( method_exists( $this->field, 'getTooltip' ) )
155        {
156            if ( $tt = $this->field->getTooltip() )
157            {
158                $btnTooltip = new TButton( 'btn_tooltip_' . $this->field->getId(), 'tooltip', null, 'void(0)', null, $tt->getImage(), null, $tt->getTooltip() );
159                $btnTooltip->setProperty( 'tooltip', 'true' );
160            }
161        }
162        $btnDocumentation = '';
163
164        if ( $this->getOnlineDoc() )
165        {
166            $btnDocumentation = new TButton( 'btn_documentation_' . $this->field->getId(), 'Manual', null, 'fwShowOnlineDocumentation("' . $this->removeIllegalChars( $_REQUEST[ 'modulo' ] ) . '","' . $this->field->getId() . '","' . $label . '")', null, 'ajudaonline.gif', null, 'Clique aqui para exibir o texto de ajuda!' );
167            $btnDocumentation = preg_replace( '/' . chr( 10 ) . '/', '', $btnDocumentation->show( false ) );
168        }
169
170        if ( $this->labelAbove )
171        {
172            $this->row2 = $this->addRow();
173            $this->column3 = $this->row2->addCell();
174            $this->column3->setProperty( 'nowrap', 'true' );
175            $this->column1->setId( 'td_label_' . $this->field->getId() );
176            $this->column3->setId( 'td_field_' . $this->field->getId() );
177            $this->row1->setId( 'tr_label_' . $this->field->getId() );
178            $this->row2->setId( 'tr_field_' . $this->field->getId() );
179
180            if ( !$this->label )
181            {
182                // criar um label vazio para manter o linhamento
183                $this->label = new TLabel( $this->field->getId() . '_label', '&nbsp;' );
184                $this->label->clearCss();
185            }
186            $this->label->setCss( 'width', '100%' );
187            $this->column1->add( $this->label );
188            $this->column3->add( $this->field );
189            $this->column3->setCss( 'padding-bottom', '3px' );
190
191            if ( $this->field->getCss( 'margin-left' ) )
192            {
193                $this->setCss( 'margin-left', $this->field->getCss( 'margin-left' ) );
194                $this->field->setCss( 'margin-left', null );
195            }
196
197            if ( $btnTooltip )
198            {
199                $this->column3->add( $btnTooltip );
200            }
201
202            if ( $btnDocumentation )
203            {
204                $this->label->setValue( $btnDocumentation . $this->label->getValue() );
205            }
206            $btnTooltipLabel=null;
207            if ( method_exists( $this->label, 'getTooltip' ) )
208            {
209                if ( $tt = $this->label->getTooltip() )
210                {
211                    $btnTooltipLabel = new TButton( 'btn_tooltip_' . $this->field->getId().'_label', 'tooltip', null, 'void(0)', null, $tt->getImage(), null, $tt->getTooltip() );
212                    $btnTooltipLabel->setProperty( 'tooltip', 'true' );
213                    $this->label->setValue( $this->label->getValue().$btnTooltipLabel->show(false) );
214                }
215            }
216            $this->row1->clearChildren();
217            $this->row1->add( $this->column1 );
218        }
219        else
220        {
221            $this->column1->setId( 'td_label_' . $this->field->getId() );
222            $this->column2->setId( 'td_field_' . $this->field->getId() );
223
224            if ( $this->getNoWrapField() )
225            {
226                $this->column2->setProperty( 'nowrap', 'nowrap' );
227            }
228            $this->row1->setId( 'tr_field_' . $this->field->getId() );
229
230            if ( $btnDocumentation && isset( $this->label ) )
231            {
232                $this->label->setValue( $btnDocumentation . $this->label->getValue() );
233            }
234            $btnTooltipLabel=null;
235            if ( !empty($this->label) && method_exists( $this->label, 'getTooltip' ) )
236            {
237                if ( $tt = $this->label->getTooltip() )
238                {
239                    $btnTooltipLabel = new TButton( 'btn_tooltip_' . $this->field->getId().'_label', 'tooltip', null, 'void(0)', null, $tt->getImage(), null, $tt->getTooltip() );
240                    $btnTooltipLabel->setProperty( 'tooltip', 'true' );
241                    $this->label->setValue( $this->label->getValue().$btnTooltipLabel->show(false) );
242                }
243            }
244            if ( $this->label )
245            {
246                if ( $this->label->getValue() == '' )
247                {
248                    $this->label->setValue( '&nbsp;' );
249                }
250                $this->column1->add( $this->label );
251            }
252            else
253            {
254                $this->row1->clearChildren();
255                $this->row1->add( $this->column2 );
256            }
257            $this->column2->add( $this->field );
258
259            if ( $btnTooltip )
260            {
261                $this->column2->add( $btnTooltip );
262            }
263
264            if ( $this->field->getCss( 'margin-left' ) )
265            {
266                $this->setCss( 'margin-left', $this->field->getCss( 'margin-left' ) );
267                $this->field->setCss( 'margin-left', null );
268            }
269        }
270
271        if ( $this->field->getCss( 'top' ) )
272        {
273            $this->setCss( 'position', 'absolute' );
274            $this->setCss( 'top', $this->field->getCss( 'top' ) );
275            $this->field->setCss( 'top', null );
276            $this->field->setCss( 'position', 'relative' );
277        }
278
279        if ( $this->field->getCss( 'left' ) )
280        {
281            $this->setCss( 'position', 'absolute' );
282            $this->setCss( 'left', $this->field->getCss( 'left' ) );
283            $this->field->setCss( 'left', null );
284            $this->field->setCss( 'position', 'relative' );
285        }
286
287        if ( $this->column2 )
288        {
289            if ( $this->getNoWrapField() === true )
290            {
291                $this->column2->setProperty( 'nowrap', 'true' );
292            }
293
294            if ( $this->getFieldCellWidth() )
295            {
296                if ( $this->getFieldCellWidth() != '0px' )
297                {
298                    $this->column2->setCss( 'width', $this->getFieldCellWidth() );
299                }
300            }
301            $this->column2->setCss( 'vertical-align', $this->getVerticalAlign() );
302        }
303
304        if ( $this->column1 )
305        {
306            if ( $this->getLabelCellWidth() )
307            {
308                if( !is_null( $labelClean ) && trim($labelClean) != '')
309                {
310                    $this->column1->setCss( 'width', $this->getLabelCellWidth() );
311                }
312            }
313        }
314
315        if ( $this->column3 )
316        {
317            if ( $this->getNoWrapField() )
318            {
319                $this->column3->setProperty( 'nowrap', 'true' );
320            }
321
322            if ( $this->getFieldCellWidth() )
323            {
324                $this->column3->setCss( 'width', $this->getFieldCellWidth() );
325            }
326        }
327
328        if ( method_exists( $this->field, 'getVisible' ) )
329        {
330            // esconder a linha se o campo estiver invisível
331            if ( !$this->field->getVisible() )
332            {
333                $this->setCss( 'display', 'none' );
334                $this->field->setVisible( true );
335                $this->field->setCss( 'display', null );
336            }
337        }
338        return parent::show( $print );
339    }
340
341    //---------------------------------------------------------------------------------------------
342    public function getField()
343    {
344        return $this->field;
345    }
346
347    //------------------------------------------------------------------------------------------
348    public function getLabel()
349    {
350        return $this->label;
351    }
352
353    //------------------------------------------------------------------------------------------
354    public function getNewLine()
355    {
356        return $this->newLine;
357    }
358
359    //------------------------------------------------------------------------------------------
360    public function setNewLine( $boolNewValue )
361    {
362        $this->newLine = $boolNewValue;
363    }
364
365    //-------------------------------------------------------------------------------------------
366    public function setVerticalAlign( $strNewValue = null )
367    {
368        $this->verticalAlign = ( is_null( $strNewValue ) ? 'middle' : $strNewValue );
369    }
370
371    //-------------------------------------------------------------------------------------------
372    public function getVerticalAlign()
373    {
374        if ( is_null( $this->verticalAlign ) )
375        {
376            $va = $this->getField()->getCss( 'vertical-align' );
377        }
378        else
379        {
380            $va = $this->verticalAlign;
381        }
382        return strtolower( ( is_null( $va ) ? 'middle' : $va ) );
383    }
384    /**
385    * Retorna o objeto coluna caso seja necessário fazer algum tratamento
386    * como no caso do pageControl que tem que alterar o css para a aba ocupar a largura do form
387    *
388    */
389    public function getColumn1()
390    {
391        return $this->column1;
392    }
393
394    //--------------------------------------------------------------------------------------------
395    public function getColumn2()
396    {
397        if ( $this->labelAbove )
398        {
399            return $this->column3;
400        }
401        return $this->column2;
402    }
403
404    public function getRow1()
405    {
406        return $this->row1;
407    }
408
409    //--------------------------------------------------------------------------------------------
410    public function getRow2()
411    {
412        return $this->row2;
413    }
414
415    //---------------------------------------------------------------------------
416    /**
417    * Define se o conteudo da coluna da tebela onde o rótulo será exibido,
418    * pode ocorrer quebra de linha quando o seu conteúdo for muito longo.
419    *
420    * @param bool $boolNewValue
421    */
422    public function setNoWrapLabel( $boolNewValue = null )
423    {
424        $boolNewValue = is_null( $boolNewValue ) ? false : $boolNewValue;
425        $this->noWrapLabel = $boolNewValue;
426    }
427
428    //---------------------------------------------------------------------------
429    public function getNoWrapLabel()
430    {
431        return $this->noWrapLabel;
432    }
433
434    //---------------------------------------------------------------------------
435    /**
436    * Define se o conteudo da coluna da tebela onde o campo será exibido,
437    * pode ocorrer quebra de linha quando o campo tiver alguma imagem, botão ou texto
438    * sendo exibido na sua frente
439    *
440    * @param bool $boolNewValue
441    */
442    public function setNoWrapField( $boolNewValue = null )
443    {
444        // padrão é false, para não afetar as linhas da classe TGrid
445        $boolNewValue = is_null( $boolNewValue ) ? false : $boolNewValue;
446        $this->noWrapField = $boolNewValue;
447    }
448
449    //---------------------------------------------------------------------------
450    public function getNoWrapField()
451    {
452        return is_null( $this->noWrapField ) ? true : $this->noWrapField;
453    }
454
455    //----------------------------------------------------------------------------
456    public function getLabelAbove()
457    {
458        return $this->labelAbove;
459    }
460
461    public function setLabelAbove( $boolNewValue = null )
462    {
463        $this->labelAbove = $boolNewValue;
464    }
465    /**
466    * Habilita/Desabilita o botão para edição online da documentação do campo
467    *
468    * @param boolean $boolNewValue
469    */
470    public function setOnlineDoc( $boolEnabled = null, $boolReadOnly = null )
471    {
472        $this->onlineDoc = is_null( $boolEnabled ) ? false : $boolEnabled;
473        $this->onlineDocReadOnly = is_null( $boolReadOnly ) ? false : $boolReadOnly;
474    }
475
476    public function getOnlineDoc()
477    {
478        return ( $this->onlineDoc === true ? true : false );
479    }
480    /**
481    * Define a largura da celula da tabela que exibirá o rótulo do campo
482    *
483    * @param mixed $strWidth
484    */
485    public function setLabelCellWidth( $strWidth = null )
486    {
487        $this->labelCellWidth = $strWidth;
488    }
489
490    /**
491    * Define a largura da celula da tabela que exibirá o campo
492    *
493    * @param mixed $strWidth
494    */
495    public function setFieldCellWidth( $strWidth = null )
496    {
497        $this->fieldCellWidth = $strWidth;
498    }
499    /**
500    * Recupera a largura da celula da tabela que exibirá o rótulo do campo
501    *
502    * @param mixed $strWidth
503    */
504    public function getLabelCellWidth()
505    {
506        if ( is_numeric( $this->labelCellWidth ) )
507        {
508            if ( $this->labelCellWidth > 0 )
509            {
510                return $this->labelCellWidth . 'px';
511            }
512            else
513            {
514                return null;
515            }
516        }
517        return $this->labelCellWidth;
518    }
519    /**
520    * Recupera a largura da celula da tabela que exibirá o campo
521    *
522    * @param mixed $strWidth
523    */
524    public function getFieldCellWidth()
525    {
526        if ( is_numeric( $this->fieldCellWidth ) )
527        {
528            if ( $this->fieldCellWidth > 0 )
529            {
530                return $this->fieldCellWidth . 'px';
531            }
532            else
533            {
534                return null;
535            }
536        }
537        return $this->fieldCellWidth;
538    }
539}
540
541//-----------------------------------------------
542/*
543$teste = new TDisplayControl('Nome:',new TEdit('nom_pessoa','Luis Eugênio',30),false);
544*/
545?>