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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

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