| [ Index ] |
PHP Cross Reference of MyBB 1.6.7 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: class_table.php 5297 2010-12-28 22:01:14Z Tomm $ 10 */ 11 12 /** 13 * Generate a data grid/table. 14 */ 15 class DefaultTable 16 { 17 /** 18 * @var array Array of cells for the current row. 19 */ 20 private $_cells = array(); 21 22 /** 23 * @var array Array of rows for the current table. 24 */ 25 private $_rows = array(); 26 27 /** 28 * @var array Array of headers for the current table. 29 */ 30 private $_headers = array(); 31 32 /** 33 * Construct an individual cell for this table. 34 * 35 * @param string The HTML content for this cell. 36 * @param array Array of extra information about this cell (class, id, colspan, rowspan, width) 37 */ 38 function construct_cell($data, $extra=array()) 39 { 40 $this->_cells[] = array("data" => $data, "extra" => $extra); 41 } 42 43 /** 44 * Construct a row from the earlier defined constructed cells for the table. 45 * 46 * @param array Array of extra information about this row (class, id) 47 */ 48 function construct_row($extra = array()) 49 { 50 $i = 1; 51 // We construct individual cells here 52 foreach($this->_cells as $key => $cell) 53 { 54 $cells .= "\t\t\t<td"; 55 if($key == 0) 56 { 57 $cell['extra']['class'] .= " first"; 58 } 59 elseif(!$this->_cells[$key+1]) 60 { 61 $cell['extra']['class'] .= " last"; 62 } 63 if($i == 2) 64 { 65 $cell['extra']['class'] .= " alt_col"; 66 $i = 0; 67 } 68 $i++; 69 if($cell['extra']['class']) 70 { 71 $cells .= " class=\"".trim($cell['extra']['class'])."\""; 72 } 73 if($cell['extra']['style']) 74 { 75 $cells .= " style=\"".$cell['extra']['style']."\""; 76 } 77 if($cell['extra']['id']) 78 { 79 $cells .= $cell['extra']['id']; 80 } 81 if(isset($cell['extra']['colspan']) && $cell['extra']['colspan'] > 1) 82 { 83 $cells .= " colspan=\"".$cell['extra']['colspan']."\""; 84 } 85 if(isset($cell['extra']['rowspan']) && $cell['extra']['rowspan'] > 1) 86 { 87 $cells .= " rowspan=\"".$cell['extra']['rowspan']."\""; 88 } 89 if($cell['extra']['width']) 90 { 91 $cells .= " width=\"".$cell['extra']['width']."\""; 92 } 93 $cells .= ">"; 94 $cells .= $cell['data']; 95 $cells .= "</td>\n"; 96 } 97 $data['cells'] = $cells; 98 $data['extra'] = $extra; 99 $this->_rows[] = $data; 100 101 $this->_cells = array(); 102 } 103 104 /** 105 * return the cells of a row for the table based row. 106 * 107 * @param string The id of the row you want to give it. 108 * @param boolean Whether or not to return or echo the resultant contents. 109 * @return string The output of the row cells (optional). 110 */ 111 function output_row_cells($row_id, $return=false) 112 { 113 $row = $this->_rows[$row_id]['cells']; 114 115 if(!$return) 116 { 117 echo $row; 118 } 119 else 120 { 121 return $row; 122 } 123 } 124 125 /** 126 * Count the number of rows in the table. Useful for displaying a 'no rows' message. 127 * 128 * @return int The number of rows in the table. 129 */ 130 function num_rows() 131 { 132 return count($this->_rows); 133 } 134 135 /** 136 * Construct a header cell for this table. 137 * 138 * @param string The HTML content for this header cell. 139 * @param array Array of extra information for this header cell (class, style, colspan, width) 140 */ 141 function construct_header($data, $extra=array()) 142 { 143 $this->_headers[] = array("data" => $data, "extra" => $extra); 144 } 145 146 /** 147 * Output this table to the browser. 148 * 149 * @param string The heading for this table. 150 * @param int The border width for this table. 151 * @param string The class for this table. 152 * @param boolean Whether or not to return or echo the resultant contents. 153 * @return string The output of the row cells (optional). 154 */ 155 function output($heading="", $border=1, $class="general", $return=false) 156 { 157 if($return == true) 158 { 159 return $this->construct_html($heading, $border, $class); 160 } 161 else 162 { 163 echo $this->construct_html($heading, $border, $class); 164 } 165 } 166 167 /** 168 * Fetch the built HTML for this table. 169 * 170 * @param string The heading for this table. 171 * @param int The border width for this table. 172 * @param string The class for this table. 173 * @param string The id for this table. 174 * @return string The built HTML. 175 */ 176 function construct_html($heading="", $border=1, $class=null, $table_id="") 177 { 178 if($border == 1) 179 { 180 $table .= "<div class=\"border_wrapper\">\n"; 181 if($heading != "") 182 { 183 $table .= " <div class=\"title\">".$heading."</div>\n"; 184 } 185 } 186 $table .= "<table"; 187 if(!is_null($class)) 188 { 189 if(!$class) 190 { 191 $class = "general"; 192 } 193 $table .= " class=\"".$class."\""; 194 } 195 if($table_id != "") 196 { 197 $table .= " id=\"".$table_id."\""; 198 } 199 $table .= " cellspacing=\"0\">\n"; 200 if($this->_headers) 201 { 202 $table .= "\t<thead>\n"; 203 $table .= "\t\t<tr>\n"; 204 foreach($this->_headers as $key => $data) 205 { 206 $table .= "\t\t\t<th"; 207 if($key == 0) 208 { 209 $data['extra']['class'] .= " first"; 210 } 211 elseif(!$this->_headers[$key+1]) 212 { 213 $data['extra']['class'] .= " last"; 214 } 215 if($data['extra']['class']) 216 { 217 $table .= " class=\"".$data['extra']['class']."\""; 218 } 219 if($data['extra']['style']) 220 { 221 $table .= " style=\"".$data['extra']['style']."\""; 222 } 223 if($data['extra']['width']) 224 { 225 $table .= " width=\"".$data['extra']['width']."\""; 226 } 227 if(isset($data['extra']['colspan']) && $data['extra']['colspan'] > 1) 228 { 229 $table .= " colspan=\"".$data['extra']['colspan']."\""; 230 } 231 $table .= ">".$data['data']."</th>\n"; 232 } 233 $table .= "\t\t</tr>\n"; 234 $table .= "\t</thead>\n"; 235 } 236 $table .= "\t<tbody>\n"; 237 $i = 1; 238 foreach($this->_rows as $key => $table_row) 239 { 240 $table .= "\t\t<tr"; 241 if($table_row['extra']['id']) 242 { 243 $table .= " id=\"{$table_row['extra']['id']}\""; 244 } 245 if($key == 0) 246 { 247 $table_row['extra']['class'] .= " first"; 248 } 249 else if(!$this->_rows[$key+1]) 250 { 251 $table_row['extra']['class'] .= " last"; 252 } 253 if($i == 2 && !isset($table_row['extra']['no_alt_row'])) 254 { 255 $table_row['extra']['class'] .= " alt_row"; 256 $i = 0; 257 } 258 $i++; 259 if($table_row['extra']['class']) 260 { 261 $table .= " class=\"".trim($table_row['extra']['class'])."\""; 262 } 263 $table .= ">\n"; 264 $table .= $table_row['cells']; 265 $table .= "\t\t</tr>\n"; 266 } 267 $table .= "\t</tbody>\n"; 268 $table .= "</table>\n"; 269 // Clean up 270 $this->_cells = $this->_rows = $this->_headers = array(); 271 if($border == 1) 272 { 273 $table .= "</div>"; 274 } 275 return $table; 276 } 277 } 278 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Mar 31 17:55:03 2012 | Cross-referenced by PHPXref 0.7.1 |