/[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.1.1 by jonen, Thu Jan 30 03:29:45 2003 UTC revision 1.4 by jonen, Thu May 6 16:27:42 2004 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          /**       * Show any internal borders?
62           * The constructor       */
63           *      var $_show_cellborders = TRUE;
64           * @param string - the title  
65           * @param string - the width of the table  
66           * @param string - the alignment  
67           */      /**
68          function InfoTable( $title, $width="100%", $align=NULL ) {       * The constructor
69                  $this->set_title($title);       *
70                  $this->set_width($width);       * @param string - the title
71                  $this->set_align($align);       * @param string - the width of the table
72          }       * @param string - the alignment
73         */
74          /**      function InfoTable( $title, $width="100%", $align=NULL ) {
75           * This function renders the object.          $this->set_title($title);
76           *          $this->set_width($width);
77           * @param int - the indentation level for          $this->set_align($align);
78           *              the container.      }
79           * @param int - the output debug flag to  
80           *              maintain compatibility w/ the API.      /**
81           *       * This function renders the object.
82           * @return string the raw html output.       *
83           */       * @param int - the indentation level for
84          function render($indent_level=1, $output_debug=0) {       *              the container.
85                  $table = html_table( $this->get_width(), 0,       * @param int - the output debug flag to
86                                                           $this->get_cellspacing(),       *              maintain compatibility w/ the API.
87                                                           $this->get_cellpadding(),       *
88                                                           $this->get_align());       * @return string the raw html output.
89                  $table->set_class( "infotable" );       */
90                  $table->add( $this->_build_title() );      function render($indent_level=1, $output_debug=0) {
91            $table = html_table( $this->get_width(), 0,
92                  $row = $this->_build_header();                               $this->get_cellspacing(),
93                  if ($row != NULL) {                               $this->get_cellpadding(),
94                      $table->add_row( $row );                               $this->get_align());
95                  }          $table->set_class( "infotable" );
96            $table->add( $this->_build_title() );
97                  //now go thru the rows of data  
98                  //and add them          $row = $this->_build_header();
99                  foreach( $this->data as $row ) {          if ( $row != NULL ) {
100                          $tr = new TRtag;              $table->add_row( $row );
101                          $cnt = count( $row );          }
102                          foreach( $row as $index => $data ) {                              
103                                  $td = $this->_build_td("", "", $index+1, $cnt );          //now go thru the rows of data
104                                  $td->add( $data );          //and add them
105                                  $tr->add( $td );          foreach( $this->data as $row ) {
106                          }              if ( (count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") ||
107                          $table->add_row( $tr );                                                                                        is_a($row[0], "TDtag")) ) {
108                  }                  $table->add_row( $row[0] );
109                } else {
110                  return $table->render($indent_level, $output_debug);                  $tr = new TRtag;
111          }                  $cnt = count( $row );
112                    foreach( $row as $index => $data ) {
113                        $td = $this->_build_td("", "", $index+1, $cnt );
114                        $td->add( $data );
115                        $tr->add( $td );
116          /*****************/                  }
117          /*  Public APIs  */                  $table->add_row( $tr );
118          /*****************/              }
119            }
120          /**          return $table->render($indent_level, $output_debug);
121           * This function is used to set the column      }
122           * header text for each column  
123           *  
124           * @param string - the title for the column  
125           * @param string - the alignment of the title  
126           */      /*****************/
127          function add_column_header( $title, $width, $align="center") {      /*  Public APIs  */
128                  $this->_headers[] = array("title" => $title,      /*****************/
129                                                                    "width" => $width,  
130                                                                    "align" => $align);      /**
131          }       * This function is used to set the column
132         * header text for each column
133          /**       *
134           * This function is used to add a row to the table       * @param string - the title for the column
135           *       * @param string - the alignment of the title
136           * @param mixed - n number of items to push       */
137           */      function add_column_header( $title, $width, $align="center") {
138          function add_row() {          $this->_headers[] = array("title" => $title,
139                  $num_args = func_num_args();                                    "width" => $width,
140                  $arr = array();                                    "align" => $align);
141                  for ($i=0;$i<$num_args;$i++) {      }
142                          $arr[] = func_get_arg($i);  
143                  }      /**
144                  $this->data[] = $arr;       * 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           * This sets the cellpadding attribute          $num_args = func_num_args();
150           * for this object.          $arr = array();
151           *          for ( $i=0;$i<$num_args;$i++ ) {
152           * @param int - the cellpadding value              $arr[] = func_get_arg($i);
153           */          }
154          function set_cellpadding( $pad=0 ) {          $this->data[] = $arr;
155                  $this->_cellpadding = $pad;      }
156          }  
157    
158          /**      /**
159           * This gets the current value of the       * This sets the cellpadding attribute
160           * cellpadding       * for this object.
161           *       *
162           * @return int - the current cellpadding       * @param int - the cellpadding value
163           */       */
164          function get_cellpadding() {      function set_cellpadding( $pad=0 ) {
165                  return $this->_cellpadding;          $this->_cellpadding = $pad;
166          }      }
167    
168          /**      /**
169           * This sets the cellspacing attribute       * This gets the current value of the
170           * for this object.       * cellpadding
171           *       *
172           * @param int - the cellspacing value       * @return int - the current cellpadding
173           */       */
174          function set_cellspacing( $spacing=0 ) {      function get_cellpadding() {
175                  $this->_cellspacing = $spacing;          return $this->_cellpadding;
176          }      }
177    
178          /**      /**
179           * This gets the current value of the       * This sets the cellspacing attribute
180           * cellspacing       * for this object.
181           *       *
182           * @return int - the current cellspacing       * @param int - the cellspacing value
183           */       */
184          function get_cellspacing() {      function set_cellspacing( $spacing=0 ) {
185                  return $this->_cellspacing;          $this->_cellspacing = $spacing;
186          }      }
187    
188          /**      /**
189           * this function lets you change the       * This gets the current value of the
190           * text alignment of the text in the title       * cellspacing
191           *       *
192           * @param string - the alignment.       * @return int - the current cellspacing
193           */       */
194          function set_title_text_align( $align="left" ) {      function get_cellspacing() {
195                  $this->_title_text_align = $align;          return $this->_cellspacing;
196          }      }
197    
198          /**      /**
199           * this function lets gets the       * this function lets you change the
200           * default css class for the title       * text alignment of the text in the title
201           *       *
202           * @return string - the css class to use       * @param string - the alignment.
203           */       */
204          function get_title_text_align( ) {      function set_title_text_align( $align="left" ) {
205                  return $this->_title_text_align;          $this->_title_text_align = $align;
206          }      }
207    
208          /**      /**
209           * this function sets the flag to tell       * this function lets gets the
210           * the object to render (or not) the       * default css class for the title
211           * vertical cell borders       *
212           *       * @return string - the css class to use
213           * @param boolean       */
214           */      function get_title_text_align( ) {
215          function set_vertical_cellborder( $flag=TRUE ) {          return $this->_title_text_align;
216                  $this->_show_vertical_cellborder = $flag;      }
217          }  
218        /**
219          /**       * this function sets the flag to tell
220           * this function lets gets the       * the object to render (or not) the
221           * default css class for the title       * vertical cell borders
222           *       *
223           * @return string - the css class to use       * @param boolean
224           */       */
225          function get_vertical_cellborder( ) {      function set_vertical_cellborder( $flag=TRUE ) {
226                  return $this->_show_vertical_cellborder;          $this->_show_vertical_cellborder = $flag;
227          }      }
228            
229        /**
230         * this function lets gets the
231          /******************/       * default css class for the title
232          /*  Private APIs  */       *
233          /******************/       * @return string - the css class to use
234         */
235        function get_vertical_cellborder( ) {
236          /**          return $this->_show_vertical_cellborder;
237           * This function builds the title      }
238           * container  
239           *  
240           * @return CAPTIONtag object      /**
241           */       * This method is used to set the flag to
242          function _build_title() {       * allow showing of the internal borders or not.
243            $caption =  new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";",       *
244                                                                                  "class" => "title"),       * @param boolean
245                                                                    $this->title );       * @return none
246            return $caption;       */
247          }      function set_show_cellborders( $flag=true ) {
248            $this->_show_cellborders = $flag;
249          /**      }
250           * This function builds the table header      
251           *  
252           * @return TRtag object  
253           */  
254          function _build_header() {      /******************/
255                  $tr = new TRtag;      /*  Private APIs  */
256        /******************/
257                  $cnt = count( $this->_headers );  
258                  if ($cnt > 0) {  
259                          $cur_col = 1;      /**
260                          foreach( $this->_headers as $header ) {       * This function builds the title
261                                  $td = $this->_build_td( $header["width"], $header["align"], $cur_col, $cnt);       * container
262                                  if ($cur_col == $cnt) {       *
263                                          $class = "headerlast";                     * @return CAPTIONtag object
264                                  } else {       */
265                                          $class = "header";      function _build_title() {
266                                  }          $caption =  new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";",
267                                  $td->set_class( $class );                                            "class" => "title"),
268                                  $td->push( $header["title"] );                                      $this->title );
269                                  $tr->push( $td );          return $caption;
270                                  $cur_col++;      }
271                          }  
272                          return $tr;      /**
273                  } else {       * This function builds the table header
274                          return NULL;       *
275                  }       * @return TRtag object
276          }       */
277        function _build_header() {
278          /**          $tr = new TRtag;
279           * this function builds a TD tag with the border styles  
280           * set appropriatly          $cnt = count( $this->_headers );
281           *          if ( $cnt > 0 ) {
282           * @param int - the width              $cur_col = 1;
283           * @param string - the alignment              foreach( $this->_headers as $header ) {
284           * @param int - the current col #                  $td = $this->_build_td( $header["width"], $header["align"], $cur_col, $cnt);
285           * @param int - the max cols                      if ( $cur_col == $cnt ) {
286           * @return TDtag object.                      $class = "headerlast";              
287           */                  } else {
288          function _build_td( $width="", $align="", $col_num, $total_cols ) {                      $class = "header";
289                  //first we have to build the style string                  }
290                  $style = "";                  $td->set_class( $class );
291                    $td->push( $header["title"] );
292                  if ($width != "") {                  $tr->push( $td );
293                          $style = "width:";                  $cur_col++;
294                          if (substr($width, -1) != "%") {              }
295                                  $style .= $width."px;";                  return $tr;
296                          } else {          } else {
297                                  $style .= $width.";";              return NULL;
298                          }          }
299                  }      }
300    
301                  if ($align != "") {      /**
302                          //add the alignment       * this function builds a TD tag with the border styles
303                          $style .= "text-align:".$align.";";       * 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            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            } else {
342                $attributes = array();
343            }      
344                    
345                  //add some padding          return new TDtag( $attributes );
346                  $style .= "padding-left:5px;padding-right:5px;";      }
   
                 //now determine the bordering  
                 if ($col_num != $total_cols &&  
                         $this->get_vertical_cellborder()) {  
                         $class = "contentvertical";  
                 } else {  
                         $class = "contentnovertical";  
                 }                        
   
                 $attributes = array("class" => $class);  
                 return new TDtag( $attributes );  
         }  
347  }  }
348    
349  /**  /**
# Line 329  class InfoTable extends BaseWidget { Line 355  class InfoTable extends BaseWidget {
355   */   */
356  class InfoTableCSS extends CSSBuilder {  class InfoTableCSS extends CSSBuilder {
357    
358          function user_setup() {      function user_setup() {
359                  $this->add_entry(".infotable", NULL,          $this->add_entry(".infotable", NULL,
360                                                   array("margin" => "0px 0px 0px 0px",                           array("margin" => "0px 0px 0px 0px",
361                                                             "font-family" => "arial, helvetica, sans-serif",                                 "font-family" => "arial, helvetica, sans-serif",
362                                                             "font-size" => "10pt",                                 "font-size" => "10pt",
363                                                             "border-left" => "1px solid #999999",                                 "border-left" => "1px solid #999999",
364                                                             "border-right" => "1px solid #999999",                                 "border-right" => "1px solid #999999",
365                                                             "border-bottom" => "1px solid #999999") );                                 "border-bottom" => "1px solid #999999") );
366    
367                  $this->add_entry(".infotable", "caption.title",          $this->add_entry(".infotable", "caption.title",
368                                                   array("font-size" => "10pt",                           array("font-size" => "10pt",
369                                                             "font-weight" => "bold",                                 "font-weight" => "bold",
370                                                             "padding" => "2px 5px 2px 5px",                                 "padding" => "2px 5px 2px 5px",
371                                                             "color" => "#FFFFFF",                                 "color" => "#FFFFFF",
372                                                             "background-color" => "#999999"));                                 "background-color" => "#999999",
373                                   "border-top" => "1px solid #999999",
374                                   "border-left" => "1px solid #999999",
375                                   "border-right" => "1px solid #999999"));
376    
377                  $this->add_entry(".infotable", "td.header",          $this->add_entry(".infotable", "td.header",
378                                                   array("font-weight" => "bold",                           array("font-weight" => "bold",
379                                 "border-top" => "1px solid #999999",                                 "border-top" => "1px solid #999999",
380                                                             "border-right" => "1px solid #999999"));                                 "border-right" => "1px solid #999999"));
381    
382                  $this->add_entry(".infotable", "td.headerlast",          $this->add_entry(".infotable", "td.headerlast",
383                                                   array("font-weight" => "bold",                           array("font-weight" => "bold",
384                                 "border-top" => "1px solid #999999"));                                 "border-top" => "1px solid #999999"));
385    
386                  $this->add_entry(".infotable", "td.contentnovertical",          $this->add_entry(".infotable", "td.contentnovertical",
387                                                   array("border-top" => "1px solid #999999"));                           array("border-top" => "1px solid #999999"));
388    
389                  $this->add_entry(".infotable", "td.contentvertical",          $this->add_entry(".infotable", "td.contentvertical",
390                                                   array("border-top" => "1px solid #999999",                           array("border-top" => "1px solid #999999",
391                                                             "border-right" => "1px solid #999999"));                                 "border-right" => "1px solid #999999"));
392          }            }  
393  }  }
394  ?>  ?>

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.4

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