/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/InfoTable.inc
ViewVC logotype

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/widgets/InfoTable.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Thu Jan 30 03:29:45 2003 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
Branch point for: no_vendor_tag
Initial revision

1 jonen 1.1 <?php
2    
3    
4     /**
5     *
6     * $Id: InfoTable.inc,v 1.13 2002/10/23 22:28:29 hemna Exp $
7     *
8     * This renders a table with a title
9     * optional column headers
10     * and rows
11     *
12     * @author Walter A. Boring IV
13     * @package phpHtmlLib
14     */
15    
16    
17     /**
18     * This is a widget class that can build
19     * and render data in a nicely formated table
20     * with a title, column headers and data
21     *
22     * @author Walter A. Boring IV
23     */
24     class InfoTable extends BaseWidget {
25    
26     /**
27     * this holds the column header
28     * titles.
29     */
30     var $_headers = array();
31    
32     /**
33     * this holds the default cellpadding
34     */
35     var $_cellpadding=2;
36    
37     /**
38     * This holds the default cellspacing
39     */
40     var $_cellspacing=0;
41    
42     /**
43     * The default class used for the
44     * title
45     */
46     var $_title_css_class = "title";
47    
48     /**
49     * The default alignment for the
50     * title text in the caption.
51     */
52     var $_title_text_align = "left";
53    
54     /**
55     * Flag to tell the class to render
56     * the vertical cell border
57     */
58     var $_show_vertical_cellborder = TRUE;
59    
60    
61    
62     /**
63     * The constructor
64     *
65     * @param string - the title
66     * @param string - the width of the table
67     * @param string - the alignment
68     */
69     function InfoTable( $title, $width="100%", $align=NULL ) {
70     $this->set_title($title);
71     $this->set_width($width);
72     $this->set_align($align);
73     }
74    
75     /**
76     * This function renders the object.
77     *
78     * @param int - the indentation level for
79     * the container.
80     * @param int - the output debug flag to
81     * maintain compatibility w/ the API.
82     *
83     * @return string the raw html output.
84     */
85     function render($indent_level=1, $output_debug=0) {
86     $table = html_table( $this->get_width(), 0,
87     $this->get_cellspacing(),
88     $this->get_cellpadding(),
89     $this->get_align());
90     $table->set_class( "infotable" );
91     $table->add( $this->_build_title() );
92    
93     $row = $this->_build_header();
94     if ($row != NULL) {
95     $table->add_row( $row );
96     }
97    
98     //now go thru the rows of data
99     //and add them
100     foreach( $this->data as $row ) {
101     $tr = new TRtag;
102     $cnt = count( $row );
103     foreach( $row as $index => $data ) {
104     $td = $this->_build_td("", "", $index+1, $cnt );
105     $td->add( $data );
106     $tr->add( $td );
107     }
108     $table->add_row( $tr );
109     }
110    
111     return $table->render($indent_level, $output_debug);
112     }
113    
114    
115    
116    
117     /*****************/
118     /* Public APIs */
119     /*****************/
120    
121     /**
122     * This function is used to set the column
123     * header text for each column
124     *
125     * @param string - the title for the column
126     * @param string - the alignment of the title
127     */
128     function add_column_header( $title, $width, $align="center") {
129     $this->_headers[] = array("title" => $title,
130     "width" => $width,
131     "align" => $align);
132     }
133    
134     /**
135     * This function is used to add a row to the table
136     *
137     * @param mixed - n number of items to push
138     */
139     function add_row() {
140     $num_args = func_num_args();
141     $arr = array();
142     for ($i=0;$i<$num_args;$i++) {
143     $arr[] = func_get_arg($i);
144     }
145     $this->data[] = $arr;
146     }
147    
148    
149     /**
150     * This sets the cellpadding attribute
151     * for this object.
152     *
153     * @param int - the cellpadding value
154     */
155     function set_cellpadding( $pad=0 ) {
156     $this->_cellpadding = $pad;
157     }
158    
159     /**
160     * This gets the current value of the
161     * cellpadding
162     *
163     * @return int - the current cellpadding
164     */
165     function get_cellpadding() {
166     return $this->_cellpadding;
167     }
168    
169     /**
170     * This sets the cellspacing attribute
171     * for this object.
172     *
173     * @param int - the cellspacing value
174     */
175     function set_cellspacing( $spacing=0 ) {
176     $this->_cellspacing = $spacing;
177     }
178    
179     /**
180     * This gets the current value of the
181     * cellspacing
182     *
183     * @return int - the current cellspacing
184     */
185     function get_cellspacing() {
186     return $this->_cellspacing;
187     }
188    
189     /**
190     * this function lets you change the
191     * text alignment of the text in the title
192     *
193     * @param string - the alignment.
194     */
195     function set_title_text_align( $align="left" ) {
196     $this->_title_text_align = $align;
197     }
198    
199     /**
200     * this function lets gets the
201     * default css class for the title
202     *
203     * @return string - the css class to use
204     */
205     function get_title_text_align( ) {
206     return $this->_title_text_align;
207     }
208    
209     /**
210     * this function sets the flag to tell
211     * the object to render (or not) the
212     * vertical cell borders
213     *
214     * @param boolean
215     */
216     function set_vertical_cellborder( $flag=TRUE ) {
217     $this->_show_vertical_cellborder = $flag;
218     }
219    
220     /**
221     * this function lets gets the
222     * default css class for the title
223     *
224     * @return string - the css class to use
225     */
226     function get_vertical_cellborder( ) {
227     return $this->_show_vertical_cellborder;
228     }
229    
230    
231    
232     /******************/
233     /* Private APIs */
234     /******************/
235    
236    
237     /**
238     * This function builds the title
239     * container
240     *
241     * @return CAPTIONtag object
242     */
243     function _build_title() {
244     $caption = new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";",
245     "class" => "title"),
246     $this->title );
247     return $caption;
248     }
249    
250     /**
251     * This function builds the table header
252     *
253     * @return TRtag object
254     */
255     function _build_header() {
256     $tr = new TRtag;
257    
258     $cnt = count( $this->_headers );
259     if ($cnt > 0) {
260     $cur_col = 1;
261     foreach( $this->_headers as $header ) {
262     $td = $this->_build_td( $header["width"], $header["align"], $cur_col, $cnt);
263     if ($cur_col == $cnt) {
264     $class = "headerlast";
265     } else {
266     $class = "header";
267     }
268     $td->set_class( $class );
269     $td->push( $header["title"] );
270     $tr->push( $td );
271     $cur_col++;
272     }
273     return $tr;
274     } else {
275     return NULL;
276     }
277     }
278    
279     /**
280     * this function builds a TD tag with the border styles
281     * set appropriatly
282     *
283     * @param int - the width
284     * @param string - the alignment
285     * @param int - the current col #
286     * @param int - the max cols
287     * @return TDtag object.
288     */
289     function _build_td( $width="", $align="", $col_num, $total_cols ) {
290     //first we have to build the style string
291     $style = "";
292    
293     if ($width != "") {
294     $style = "width:";
295     if (substr($width, -1) != "%") {
296     $style .= $width."px;";
297     } else {
298     $style .= $width.";";
299     }
300     }
301    
302     if ($align != "") {
303     //add the alignment
304     $style .= "text-align:".$align.";";
305     }
306    
307     //add some padding
308     $style .= "padding-left:5px;padding-right:5px;";
309    
310     //now determine the bordering
311     if ($col_num != $total_cols &&
312     $this->get_vertical_cellborder()) {
313     $class = "contentvertical";
314     } else {
315     $class = "contentnovertical";
316     }
317    
318     $attributes = array("class" => $class);
319     return new TDtag( $attributes );
320     }
321     }
322    
323     /**
324     * This class defines the css used by the
325     * FooterNav Object.
326     *
327     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
328     * @package phpHtmlLib
329     */
330     class InfoTableCSS extends CSSBuilder {
331    
332     function user_setup() {
333     $this->add_entry(".infotable", NULL,
334     array("margin" => "0px 0px 0px 0px",
335     "font-family" => "arial, helvetica, sans-serif",
336     "font-size" => "10pt",
337     "border-left" => "1px solid #999999",
338     "border-right" => "1px solid #999999",
339     "border-bottom" => "1px solid #999999") );
340    
341     $this->add_entry(".infotable", "caption.title",
342     array("font-size" => "10pt",
343     "font-weight" => "bold",
344     "padding" => "2px 5px 2px 5px",
345     "color" => "#FFFFFF",
346     "background-color" => "#999999"));
347    
348     $this->add_entry(".infotable", "td.header",
349     array("font-weight" => "bold",
350     "border-top" => "1px solid #999999",
351     "border-right" => "1px solid #999999"));
352    
353     $this->add_entry(".infotable", "td.headerlast",
354     array("font-weight" => "bold",
355     "border-top" => "1px solid #999999"));
356    
357     $this->add_entry(".infotable", "td.contentnovertical",
358     array("border-top" => "1px solid #999999"));
359    
360     $this->add_entry(".infotable", "td.contentvertical",
361     array("border-top" => "1px solid #999999",
362     "border-right" => "1px solid #999999"));
363     }
364     }
365     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed