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

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