/[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.4 - (hide annotations)
Thu May 6 16:27:42 2004 UTC (20 years, 3 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +31 -8 lines
 updated all to v2.4.1 - Apr 01, 2004

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

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