MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
minputgrid.class
Ir para a documentação deste ficheiro.
1<?php
2
7{
8 public $colWidth;
9
13 public function __construct( $name, $label='', $colWidth = 0, $value = array() )
14 {
15 parent::__construct( $name, $value, $label );
16
17 $this->colWidth = $colWidth;
18 }
19}
20
21
26{
27 public $cols; // array of column definitions
28 protected $numRows; // the number of rows
29 public $numCols; // the number of cols
30 public $aValue; // array com os valores dos campos
34 public function __construct( $name, $label = '', $rows = 0 )
35 {
36 $this->numRows = $rows;
37 $this->numCols = 0;
38
39 parent::__construct( $name, array(), $label );
40 }
41
45 public function getRowCount()
46 {
47 return $this->numRows;
48 }
49
53 public function setRowCount( $rows )
54 {
55 $this->numRows = $rows;
56 }
57
61 public function addColumn( $label, $name, $colWidth = 0, $value = '' )
62 {
63 for ( $i = 0; $i < $this->numRows; $i++ )
64 {
65 $this->setFieldValue( $i + 1, $this->numCols + 1, $value );
66 }
67
68 $this->cols[$this->numCols++] = new MInputGridColumn( $label, $name, $colWidth, $value );
69 }
70
74 public function generateInner()
75 {
76 $t = array();
77
78 $t[0][0] = '';
79
80 for ( $i = 0; $i < $this->numRows; $i++ )
81 {
82 $t[$i + 1][0] = $this->painter->span( new Span( '', ($i + 1) . ":&nbsp;", MControl::CLASS_CAPTION ) );
83 }
84
85 foreach ( $this->cols as $col => $column )
86 {
87 $t[0][$col + 1] = $this->painter->span( new Span('', $column->label, MControl::CLASS_CAPTION) );
88
89 for ( $i = 0; $i < $this->numRows; $i++ )
90 {
91 if ( is_object( $column->value ) )
92 {
93 $text = clone($column->value);
94 }
95 else
96 {
97 $text = new TextField( "{$this->name}[$i][$col]", $this->aValue[$i][$col], '', $column->colWidth );
98 }
99 $text->setAttribute('rowNumber', "$i");
100 $t[$i + 1][$col + 1] = $text->generate();
101 }
102 }
103
104 $table = new MTable( $t, array(), array(), array() );
105
106 $this->inner = $table->getRender( 'table' );
107 }
108
112 public function setValue( $value )
113 {
114 if ( is_array( $value ) && ( count($this->cols) > 0 ) )
115 {
116 foreach ( $this->cols as $col => $column )
117 {
118 for ( $i = 0; $i < $this->numRows; $i++ )
119 {
120 if ( $value[$i][$col] != NULL )
121 {
122 $this->setFieldValue( $i + 1, $col + 1, $value[$i][$col] );
123 }
124 }
125 }
126 }
127 }
128
132 public function getValue()
133 {
134 return $this->aValue;
135 }
136
140 public function getFieldValue( $row, $col, $default = '' )
141 {
142 $value = $this->aValue[$row - 1][$col - 1];
143
144 return isset( $value ) ? $value : $default;
145 }
146
150 public function setFieldValue( $row, $col, $value )
151 {
152 $this->aValue[$row - 1][$col - 1] = $value;
153 }
154
158 public function getRow( $row )
159 {
160 return $this->aValue[$row - 1];
161 }
162
163}
164
165?>
const CLASS_CAPTION
Definição mcontrol.class:46
__construct( $name, $label='', $colWidth=0, $value=array())
getRow( $row)
__construct( $name, $label='', $rows=0)
setRowCount( $rows)
addColumn( $label, $name, $colWidth=0, $value='')
setValue( $value)
getFieldValue( $row, $col, $default='')
setFieldValue( $row, $col, $value)