/[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.2 by jonen, Sat Feb 22 21:08:23 2003 UTC revision 1.4 by jonen, Thu May 6 16:27:42 2004 UTC
# Line 22  Line 22 
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              if ((count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") ||              $table->add_row( $row );
101                                                               is_a($row[0], "TDtag"))) {          }
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                  $table->add_row( $row[0] );                  $table->add_row( $row[0] );
109              } else {              } else {
110                  $tr = new TRtag;                  $tr = new TRtag;
111                  $cnt = count( $row );                  $cnt = count( $row );
112                  foreach( $row as $index => $data ) {                                  foreach( $row as $index => $data ) {
113                      $td = $this->_build_td("", "", $index+1, $cnt );                      $td = $this->_build_td("", "", $index+1, $cnt );
114                      $td->add( $data );                      $td->add( $data );
115                      $tr->add( $td );                      $tr->add( $td );
116                  }                  }
117                  $table->add_row( $tr );                  $table->add_row( $tr );
118              }              }
119                  }          }
120                  return $table->render($indent_level, $output_debug);          return $table->render($indent_level, $output_debug);
121          }      }
122    
123    
124    
125    
126          /*****************/      /*****************/
127          /*  Public APIs  */      /*  Public APIs  */
128          /*****************/      /*****************/
129    
130          /**      /**
131           * This function is used to set the column       * This function is used to set the column
132           * header text for each column       * header text for each column
133           *       *
134           * @param string - the title for the column       * @param string - the title for the column
135           * @param string - the alignment of the title       * @param string - the alignment of the title
136           */       */
137          function add_column_header( $title, $width, $align="center") {      function add_column_header( $title, $width, $align="center") {
138                  $this->_headers[] = array("title" => $title,          $this->_headers[] = array("title" => $title,
139                                                                    "width" => $width,                                    "width" => $width,
140                                                                    "align" => $align);                                    "align" => $align);
141          }      }
142    
143          /**      /**
144           * This function is used to add a row to the table       * This function is used to add a row to the table
145           *       *
146           * @param mixed - n number of items to push       * @param mixed - n number of items to push
147           */       */
148          function add_row() {      function add_row() {
149                  $num_args = func_num_args();          $num_args = func_num_args();
150                  $arr = array();          $arr = array();
151                  for ($i=0;$i<$num_args;$i++) {          for ( $i=0;$i<$num_args;$i++ ) {
152                          $arr[] = func_get_arg($i);              $arr[] = func_get_arg($i);
153                  }          }
154                  $this->data[] = $arr;          $this->data[] = $arr;
155          }      }
156    
157    
158          /**      /**
159           * This sets the cellpadding attribute       * This sets the cellpadding attribute
160           * for this object.       * for this object.
161           *       *
162           * @param int - the cellpadding value       * @param int - the cellpadding value
163           */       */
164          function set_cellpadding( $pad=0 ) {      function set_cellpadding( $pad=0 ) {
165                  $this->_cellpadding = $pad;          $this->_cellpadding = $pad;
166          }      }
167    
168          /**      /**
169           * This gets the current value of the       * This gets the current value of the
170           * cellpadding       * cellpadding
171           *       *
172           * @return int - the current cellpadding       * @return int - the current cellpadding
173           */       */
174          function get_cellpadding() {      function get_cellpadding() {
175                  return $this->_cellpadding;          return $this->_cellpadding;
176          }      }
177    
178          /**      /**
179           * This sets the cellspacing attribute       * This sets the cellspacing attribute
180           * for this object.       * for this object.
181           *       *
182           * @param int - the cellspacing value       * @param int - the cellspacing value
183           */       */
184          function set_cellspacing( $spacing=0 ) {      function set_cellspacing( $spacing=0 ) {
185                  $this->_cellspacing = $spacing;          $this->_cellspacing = $spacing;
186          }      }
187    
188          /**      /**
189           * This gets the current value of the       * This gets the current value of the
190           * cellspacing       * cellspacing
191           *       *
192           * @return int - the current cellspacing       * @return int - the current cellspacing
193           */       */
194          function get_cellspacing() {      function get_cellspacing() {
195                  return $this->_cellspacing;          return $this->_cellspacing;
196          }      }
197    
198          /**      /**
199           * this function lets you change the       * this function lets you change the
200           * text alignment of the text in the title       * text alignment of the text in the title
201           *       *
202           * @param string - the alignment.       * @param string - the alignment.
203           */       */
204          function set_title_text_align( $align="left" ) {      function set_title_text_align( $align="left" ) {
205                  $this->_title_text_align = $align;          $this->_title_text_align = $align;
206          }      }
207    
208          /**      /**
209           * this function lets gets the       * this function lets gets the
210           * default css class for the title       * default css class for the title
211           *       *
212           * @return string - the css class to use       * @return string - the css class to use
213           */       */
214          function get_title_text_align( ) {      function get_title_text_align( ) {
215                  return $this->_title_text_align;          return $this->_title_text_align;
216          }      }
217    
218          /**      /**
219           * this function sets the flag to tell       * this function sets the flag to tell
220           * the object to render (or not) the       * the object to render (or not) the
221           * vertical cell borders       * vertical cell borders
222           *       *
223           * @param boolean       * @param boolean
224           */       */
225          function set_vertical_cellborder( $flag=TRUE ) {      function set_vertical_cellborder( $flag=TRUE ) {
226                  $this->_show_vertical_cellborder = $flag;          $this->_show_vertical_cellborder = $flag;
227          }      }
228    
229          /**      /**
230           * this function lets gets the       * this function lets gets the
231           * default css class for the title       * default css class for the title
232           *       *
233           * @return string - the css class to use       * @return string - the css class to use
234           */       */
235          function get_vertical_cellborder( ) {      function get_vertical_cellborder( ) {
236                  return $this->_show_vertical_cellborder;          return $this->_show_vertical_cellborder;
237          }      }
238            
239    
240        /**
241          /******************/       * This method is used to set the flag to
242          /*  Private APIs  */       * allow showing of the internal borders or not.
243          /******************/       *
244         * @param boolean
245         * @return none
246          /**       */
247           * This function builds the title      function set_show_cellborders( $flag=true ) {
248           * container          $this->_show_cellborders = $flag;
249           *      }
250           * @return CAPTIONtag object      
251           */  
252          function _build_title() {  
253            $caption =  new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";",  
254                                                                                  "class" => "title"),      /******************/
255                                                                    $this->title );      /*  Private APIs  */
256            return $caption;      /******************/
257          }  
258    
259          /**      /**
260           * This function builds the table header       * This function builds the title
261           *       * container
262           * @return TRtag object       *
263           */       * @return CAPTIONtag object
264          function _build_header() {       */
265                  $tr = new TRtag;      function _build_title() {
266            $caption =  new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";",
267                  $cnt = count( $this->_headers );                                            "class" => "title"),
268                  if ($cnt > 0) {                                      $this->title );
269                          $cur_col = 1;          return $caption;
270                          foreach( $this->_headers as $header ) {      }
271                                  $td = $this->_build_td( $header["width"], $header["align"], $cur_col, $cnt);  
272                                  if ($cur_col == $cnt) {      /**
273                                          $class = "headerlast";                     * This function builds the table header
274                                  } else {       *
275                                          $class = "header";       * @return TRtag object
276                                  }       */
277                                  $td->set_class( $class );      function _build_header() {
278                                  $td->push( $header["title"] );          $tr = new TRtag;
279                                  $tr->push( $td );  
280                                  $cur_col++;          $cnt = count( $this->_headers );
281                          }          if ( $cnt > 0 ) {
282                          return $tr;              $cur_col = 1;
283                  } else {              foreach( $this->_headers as $header ) {
284                          return NULL;                  $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           * this function builds a TD tag with the border styles                  }
290           * set appropriatly                  $td->set_class( $class );
291           *                  $td->push( $header["title"] );
292           * @param int - the width                  $tr->push( $td );
293           * @param string - the alignment                  $cur_col++;
294           * @param int - the current col #              }
295           * @param int - the max cols                  return $tr;
296           * @return TDtag object.          } else {
297           */              return NULL;
298          function _build_td( $width="", $align="", $col_num, $total_cols ) {          }
299                  //first we have to build the style string      }
300                  $style = "";  
301        /**
302                  if ($width != "") {       * this function builds a TD tag with the border styles
303                          $style = "width:";       * set appropriatly
304                          if (substr($width, -1) != "%") {       *
305                                  $style .= $width."px;";           * @param int - the width
306                          } else {       * @param string - the alignment
307                                  $style .= $width.";";       * @param int - the current col #
308                          }       * @param int - the max cols        
309                  }       * @return TDtag object.
310         */
311                  if ($align != "") {      function _build_td( $width="", $align="", $col_num, $total_cols ) {
312                          //add the alignment          //first we have to build the style string
313                          $style .= "text-align:".$align.";";          $style = "";
314                  }  
315                    if ( $width != "" ) {
316                  //add some padding              $style = "width:";
317                  $style .= "padding-left:5px;padding-right:5px;";              if ( substr($width, -1) != "%" ) {
318                    $style .= $width."px;";    
319                } else {
320                    $style .= $width.";";
321                }
322            }
323    
324                  //now determine the bordering          if ( $align != "" ) {
325                  if ($col_num != $total_cols &&              //add the alignment
326                          $this->get_vertical_cellborder()) {              $style .= "text-align:".$align.";";
327                          $class = "contentvertical";          }
328                  } else {  
329                          $class = "contentnovertical";          //add some padding
330                  }                                $style .= "padding-left:5px;padding-right:5px;";
331    
332                  $attributes = array("class" => $class);          //now determine the bordering
333                  return new TDtag( $attributes );          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            return new TDtag( $attributes );
346        }
347  }  }
348    
349  /**  /**
# Line 332  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.2  
changed lines
  Added in v.1.4

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