blob: 11a4858a9b15156399ea57dfccb44c6d6a023c9a [file] [log] [blame]
Andrey Andreevfe9b9a92011-12-25 16:11:01 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevfe9b9a92011-12-25 16:11:01 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.3.1
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * HTML Table Generating Class
30 *
31 * Lets you create tables manually or from database result objects, or arrays.
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category HTML Tables
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Gerry6b590892011-09-25 00:16:39 +080037 * @link http://codeigniter.com/user_guide/libraries/table.html
Derek Allard2067d1a2008-11-13 22:59:24 +000038 */
39class CI_Table {
40
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020041 public $rows = array();
42 public $heading = array();
43 public $auto_heading = TRUE;
44 public $caption = NULL;
45 public $template = NULL;
46 public $newline = "\n";
47 public $empty_cells = '';
48 public $function = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +020049
Mike Funk46e3a9a2012-02-24 09:38:35 -050050 /**
51 * Set the template from the table config file if it exists
Andrey Andreev80295322012-03-12 16:29:16 +020052 *
Mike Funk5fbaf272012-03-12 10:19:46 -040053 * @param array $config (default: array())
Mike Funkaa20f5b2012-02-28 13:43:16 -050054 * @return void
Mike Funk46e3a9a2012-02-24 09:38:35 -050055 */
56 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000057 {
Andrey Andreev80295322012-03-12 16:29:16 +020058 log_message('debug', 'Table Class Initialized');
59
Mike Funk46e3a9a2012-02-24 09:38:35 -050060 // initialize config
61 foreach ($config as $key => $val)
62 {
63 $this->template[$key] = $val;
64 }
Derek Allard2067d1a2008-11-13 22:59:24 +000065 }
66
67 // --------------------------------------------------------------------
68
69 /**
70 * Set the template
71 *
Derek Allard2067d1a2008-11-13 22:59:24 +000072 * @param array
73 * @return void
74 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020075 public function set_template($template)
Derek Allard2067d1a2008-11-13 22:59:24 +000076 {
77 if ( ! is_array($template))
78 {
79 return FALSE;
80 }
Barry Mienydd671972010-10-04 16:33:58 +020081
Derek Allard2067d1a2008-11-13 22:59:24 +000082 $this->template = $template;
83 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * Set the table heading
89 *
90 * Can be passed as an array or discreet params
91 *
Derek Allard2067d1a2008-11-13 22:59:24 +000092 * @param mixed
93 * @return void
94 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020095 public function set_heading()
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
97 $args = func_get_args();
Derek Jones7b5b0e22010-03-02 22:48:53 -060098 $this->heading = $this->_prep_args($args);
Derek Allard2067d1a2008-11-13 22:59:24 +000099 }
100
101 // --------------------------------------------------------------------
102
103 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500104 * Set columns. Takes a one-dimensional array as input and creates
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 * a multi-dimensional array with a depth equal to the number of
Derek Jones4b9c6292011-07-01 17:40:48 -0500106 * columns. This allows a single array with many elements to be
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 * displayed in a table that has a fixed column count.
108 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 * @param array
110 * @param int
111 * @return void
112 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200113 public function make_columns($array = array(), $col_limit = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
Taufan Aditya8749bc72012-03-11 05:43:45 +0700115 if ( ! is_array($array) OR count($array) === 0 OR ! is_int($col_limit))
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
117 return FALSE;
118 }
Barry Mienydd671972010-10-04 16:33:58 +0200119
120 // Turn off the auto-heading feature since it's doubtful we
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 // will want headings from a one-dimensional array
122 $this->auto_heading = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200123
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 if ($col_limit == 0)
125 {
126 return $array;
127 }
Barry Mienydd671972010-10-04 16:33:58 +0200128
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 $new = array();
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200130 do
Barry Mienydd671972010-10-04 16:33:58 +0200131 {
132 $temp = array_splice($array, 0, $col_limit);
133
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 if (count($temp) < $col_limit)
135 {
136 for ($i = count($temp); $i < $col_limit; $i++)
137 {
138 $temp[] = '&nbsp;';
139 }
140 }
Barry Mienydd671972010-10-04 16:33:58 +0200141
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 $new[] = $temp;
143 }
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200144 while (count($array) > 0);
Barry Mienydd671972010-10-04 16:33:58 +0200145
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 return $new;
147 }
148
149 // --------------------------------------------------------------------
150
151 /**
152 * Set "empty" cells
153 *
154 * Can be passed as an array or discreet params
155 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 * @param mixed
157 * @return void
158 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200159 public function set_empty($value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 {
161 $this->empty_cells = $value;
162 }
Barry Mienydd671972010-10-04 16:33:58 +0200163
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 // --------------------------------------------------------------------
165
166 /**
167 * Add a table row
168 *
169 * Can be passed as an array or discreet params
170 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 * @param mixed
172 * @return void
173 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200174 public function add_row()
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 {
176 $args = func_get_args();
Derek Jones7b5b0e22010-03-02 22:48:53 -0600177 $this->rows[] = $this->_prep_args($args);
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 }
179
180 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200181
Derek Jones7b5b0e22010-03-02 22:48:53 -0600182 /**
183 * Prep Args
184 *
185 * Ensures a standard associative array format for all cell data
186 *
Derek Jones7b5b0e22010-03-02 22:48:53 -0600187 * @param type
188 * @return type
189 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200190 protected function _prep_args($args)
Derek Jones7b5b0e22010-03-02 22:48:53 -0600191 {
192 // If there is no $args[0], skip this and treat as an associative array
193 // This can happen if there is only a single key, for example this is passed to table->generate
194 // array(array('foo'=>'bar'))
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200195 if (isset($args[0]) AND (count($args) === 1 && is_array($args[0])))
Derek Jones7b5b0e22010-03-02 22:48:53 -0600196 {
197 // args sent as indexed array
198 if ( ! isset($args[0]['data']))
199 {
200 foreach ($args[0] as $key => $val)
201 {
202 if (is_array($val) && isset($val['data']))
203 {
204 $args[$key] = $val;
205 }
206 else
207 {
Barry Mienydd671972010-10-04 16:33:58 +0200208 $args[$key] = array('data' => $val);
Derek Jones7b5b0e22010-03-02 22:48:53 -0600209 }
Barry Mienydd671972010-10-04 16:33:58 +0200210 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600211 }
212 }
213 else
214 {
215 foreach ($args as $key => $val)
216 {
217 if ( ! is_array($val))
218 {
219 $args[$key] = array('data' => $val);
220 }
221 }
222 }
Barry Mienydd671972010-10-04 16:33:58 +0200223
Derek Jones7b5b0e22010-03-02 22:48:53 -0600224 return $args;
225 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000226
Derek Jones7b5b0e22010-03-02 22:48:53 -0600227 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 /**
230 * Add a table caption
231 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 * @param string
233 * @return void
234 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200235 public function set_caption($caption)
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 {
237 $this->caption = $caption;
Barry Mienydd671972010-10-04 16:33:58 +0200238 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000239
240 // --------------------------------------------------------------------
241
242 /**
243 * Generate the table
244 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 * @param mixed
246 * @return string
247 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200248 public function generate($table_data = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 {
250 // The table data can optionally be passed to this function
251 // either as a database result object or an array
252 if ( ! is_null($table_data))
253 {
254 if (is_object($table_data))
255 {
256 $this->_set_from_object($table_data);
257 }
258 elseif (is_array($table_data))
259 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200260 $set_heading = (count($this->heading) === 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 $this->_set_from_array($table_data, $set_heading);
262 }
263 }
Barry Mienydd671972010-10-04 16:33:58 +0200264
Derek Jones4b9c6292011-07-01 17:40:48 -0500265 // Is there anything to display? No? Smite them!
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200266 if (count($this->heading) === 0 AND count($this->rows) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 {
268 return 'Undefined table data';
269 }
Barry Mienydd671972010-10-04 16:33:58 +0200270
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 // Compile and validate the template date
272 $this->_compile_template();
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Jones7b5b0e22010-03-02 22:48:53 -0600274 // set a custom cell manipulation function to a locally scoped variable so its callable
275 $function = $this->function;
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 // Build the table!
Barry Mienydd671972010-10-04 16:33:58 +0200278
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200279 $out = $this->template['table_open'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000280
281 // Add any caption here
282 if ($this->caption)
283 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200284 $out .= $this->newline.'<caption>'.$this->caption.'</caption>'.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 }
286
287 // Is there a table heading to display?
288 if (count($this->heading) > 0)
289 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200290 $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000291
Pascal Kriete14287f32011-02-14 13:39:34 -0500292 foreach ($this->heading as $heading)
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600294 $temp = $this->template['heading_cell_start'];
Barry Mienydd671972010-10-04 16:33:58 +0200295
Derek Jones7b5b0e22010-03-02 22:48:53 -0600296 foreach ($heading as $key => $val)
297 {
298 if ($key != 'data')
299 {
300 $temp = str_replace('<th', "<th $key='$val'", $temp);
Barry Mienydd671972010-10-04 16:33:58 +0200301 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600302 }
303
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200304 $out .= $temp.(isset($heading['data']) ? $heading['data'] : '').$this->template['heading_cell_end'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 }
306
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200307 $out .= $this->template['heading_row_end'].$this->newline.$this->template['thead_close'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 }
Barry Mienydd671972010-10-04 16:33:58 +0200309
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 // Build the table rows
311 if (count($this->rows) > 0)
312 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200313 $out .= $this->template['tbody_open'].$this->newline;
Barry Mienydd671972010-10-04 16:33:58 +0200314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 $i = 1;
Pascal Kriete14287f32011-02-14 13:39:34 -0500316 foreach ($this->rows as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 {
318 if ( ! is_array($row))
319 {
320 break;
321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 // We use modulus to alternate the row colors
324 $name = (fmod($i++, 2)) ? '' : 'alt_';
Barry Mienydd671972010-10-04 16:33:58 +0200325
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200326 $out .= $this->template['row_'.$name.'start'].$this->newline;
Barry Mienydd671972010-10-04 16:33:58 +0200327
Pascal Kriete14287f32011-02-14 13:39:34 -0500328 foreach ($row as $cell)
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600330 $temp = $this->template['cell_'.$name.'start'];
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Jones7b5b0e22010-03-02 22:48:53 -0600332 foreach ($cell as $key => $val)
333 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200334 if ($key !== 'data')
Derek Jones7b5b0e22010-03-02 22:48:53 -0600335 {
336 $temp = str_replace('<td', "<td $key='$val'", $temp);
Barry Mienydd671972010-10-04 16:33:58 +0200337 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600338 }
Barry Mienydd671972010-10-04 16:33:58 +0200339
Derek Jones7b5b0e22010-03-02 22:48:53 -0600340 $cell = isset($cell['data']) ? $cell['data'] : '';
341 $out .= $temp;
342
Derek Allardd8270582010-01-15 17:10:56 +0000343 if ($cell === "" OR $cell === NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 {
345 $out .= $this->empty_cells;
346 }
347 else
348 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600349 if ($function !== FALSE && is_callable($function))
350 {
Phil Sturgeon6c597f82010-12-27 17:35:35 +0000351 $out .= call_user_func($function, $cell);
Derek Jones7b5b0e22010-03-02 22:48:53 -0600352 }
353 else
354 {
355 $out .= $cell;
356 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 }
Barry Mienydd671972010-10-04 16:33:58 +0200358
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 $out .= $this->template['cell_'.$name.'end'];
360 }
Barry Mienydd671972010-10-04 16:33:58 +0200361
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200362 $out .= $this->template['row_'.$name.'end'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 }
Barry Mienydd671972010-10-04 16:33:58 +0200364
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200365 $out .= $this->template['tbody_close'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 }
367
368 $out .= $this->template['table_close'];
Barry Mienydd671972010-10-04 16:33:58 +0200369
Greg Aker02b3a5b2011-02-01 01:29:21 -0600370 // Clear table class properties before generating the table
371 $this->clear();
372
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 return $out;
374 }
Barry Mienydd671972010-10-04 16:33:58 +0200375
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 // --------------------------------------------------------------------
377
378 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500379 * Clears the table arrays. Useful if multiple tables are being generated
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 * @return void
382 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200383 public function clear()
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 {
385 $this->rows = array();
386 $this->heading = array();
Barry Mienydd671972010-10-04 16:33:58 +0200387 $this->auto_heading = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 }
Barry Mienydd671972010-10-04 16:33:58 +0200389
Derek Allard2067d1a2008-11-13 22:59:24 +0000390 // --------------------------------------------------------------------
391
392 /**
393 * Set table data from a database result object
394 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 * @param object
396 * @return void
397 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200398 protected function _set_from_object($query)
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 {
400 if ( ! is_object($query))
401 {
402 return FALSE;
403 }
Barry Mienydd671972010-10-04 16:33:58 +0200404
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 // First generate the headings from the table column names
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200406 if (count($this->heading) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 {
Taufan Aditya8749bc72012-03-11 05:43:45 +0700408 if ( ! is_callable(array($query, 'list_fields')))
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 {
410 return FALSE;
411 }
Barry Mienydd671972010-10-04 16:33:58 +0200412
Derek Jones7b5b0e22010-03-02 22:48:53 -0600413 $this->heading = $this->_prep_args($query->list_fields());
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 }
Barry Mienydd671972010-10-04 16:33:58 +0200415
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 // Next blast through the result array and build out the rows
Barry Mienydd671972010-10-04 16:33:58 +0200417
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 if ($query->num_rows() > 0)
419 {
420 foreach ($query->result_array() as $row)
421 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600422 $this->rows[] = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 }
424 }
425 }
426
427 // --------------------------------------------------------------------
428
429 /**
430 * Set table data from an array
431 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 * @param array
433 * @return void
434 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200435 protected function _set_from_array($data, $set_heading = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200437 if ( ! is_array($data) OR count($data) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 {
439 return FALSE;
440 }
Barry Mienydd671972010-10-04 16:33:58 +0200441
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 $i = 0;
443 foreach ($data as $row)
Barry Mienydd671972010-10-04 16:33:58 +0200444 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 // If a heading hasn't already been set we'll use the first row of the array as the heading
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200446 if ($i++ === 0 AND count($data) > 1 AND count($this->heading) === 0 AND $set_heading == TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600448 $this->heading = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 }
450 else
451 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600452 $this->rows[] = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 }
455 }
456
457 // --------------------------------------------------------------------
458
459 /**
460 * Compile Template
461 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 * @return void
463 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200464 protected function _compile_template()
Barry Mienydd671972010-10-04 16:33:58 +0200465 {
466 if ($this->template == NULL)
467 {
468 $this->template = $this->_default_template();
469 return;
470 }
471
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 $this->temp = $this->_default_template();
Derek Jones7b5b0e22010-03-02 22:48:53 -0600473 foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 {
475 if ( ! isset($this->template[$val]))
476 {
477 $this->template[$val] = $this->temp[$val];
478 }
Barry Mienydd671972010-10-04 16:33:58 +0200479 }
480 }
481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 // --------------------------------------------------------------------
483
484 /**
485 * Default Template
486 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 * @return void
488 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200489 protected function _default_template()
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500491 return array (
Barry Mienydd671972010-10-04 16:33:58 +0200492 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
493
Derek Jones7b5b0e22010-03-02 22:48:53 -0600494 'thead_open' => '<thead>',
495 'thead_close' => '</thead>',
Barry Mienydd671972010-10-04 16:33:58 +0200496
497 'heading_row_start' => '<tr>',
498 'heading_row_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 'heading_cell_start' => '<th>',
500 'heading_cell_end' => '</th>',
501
Derek Jones7b5b0e22010-03-02 22:48:53 -0600502 'tbody_open' => '<tbody>',
503 'tbody_close' => '</tbody>',
Barry Mienydd671972010-10-04 16:33:58 +0200504
505 'row_start' => '<tr>',
506 'row_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 'cell_start' => '<td>',
508 'cell_end' => '</td>',
509
Barry Mienydd671972010-10-04 16:33:58 +0200510 'row_alt_start' => '<tr>',
511 'row_alt_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 'cell_alt_start' => '<td>',
513 'cell_alt_end' => '</td>',
514
Barry Mienydd671972010-10-04 16:33:58 +0200515 'table_close' => '</table>'
516 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 }
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519
520}
521
Derek Allard2067d1a2008-11-13 22:59:24 +0000522/* End of file Table.php */
Gerry6b590892011-09-25 00:16:39 +0800523/* Location: ./system/libraries/Table.php */