blob: de5a6ba3a09f15fc9ae727931e5540b9e3f740ac [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 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 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
28// ------------------------------------------------------------------------
29
30/**
31 * HTML Table Generating Class
32 *
33 * Lets you create tables manually or from database result objects, or arrays.
34 *
35 * @package CodeIgniter
36 * @subpackage Libraries
37 * @category HTML Tables
Derek Jonesf4a4bd82011-10-20 12:18:42 -050038 * @author EllisLab Dev Team
Gerry6b590892011-09-25 00:16:39 +080039 * @link http://codeigniter.com/user_guide/libraries/table.html
Derek Allard2067d1a2008-11-13 22:59:24 +000040 */
41class CI_Table {
42
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020043 public $rows = array();
44 public $heading = array();
45 public $auto_heading = TRUE;
46 public $caption = NULL;
47 public $template = NULL;
48 public $newline = "\n";
49 public $empty_cells = '';
50 public $function = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +020051
Mike Funk46e3a9a2012-02-24 09:38:35 -050052 // --------------------------------------------------------------------------
53
54 /**
55 * Set the template from the table config file if it exists
56 *
57 * @param array $config (default: array())
58 * @return void
59 */
60 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
62 log_message('debug', "Table Class Initialized");
Mike Funk46e3a9a2012-02-24 09:38:35 -050063
64 // initialize config
65 foreach ($config as $key => $val)
66 {
67 $this->template[$key] = $val;
68 }
Derek Allard2067d1a2008-11-13 22:59:24 +000069 }
70
71 // --------------------------------------------------------------------
72
73 /**
74 * Set the template
75 *
Derek Allard2067d1a2008-11-13 22:59:24 +000076 * @param array
77 * @return void
78 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020079 public function set_template($template)
Derek Allard2067d1a2008-11-13 22:59:24 +000080 {
81 if ( ! is_array($template))
82 {
83 return FALSE;
84 }
Barry Mienydd671972010-10-04 16:33:58 +020085
Derek Allard2067d1a2008-11-13 22:59:24 +000086 $this->template = $template;
87 }
88
89 // --------------------------------------------------------------------
90
91 /**
92 * Set the table heading
93 *
94 * Can be passed as an array or discreet params
95 *
Derek Allard2067d1a2008-11-13 22:59:24 +000096 * @param mixed
97 * @return void
98 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +020099 public function set_heading()
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 {
101 $args = func_get_args();
Derek Jones7b5b0e22010-03-02 22:48:53 -0600102 $this->heading = $this->_prep_args($args);
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 }
104
105 // --------------------------------------------------------------------
106
107 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500108 * Set columns. Takes a one-dimensional array as input and creates
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 * a multi-dimensional array with a depth equal to the number of
Derek Jones4b9c6292011-07-01 17:40:48 -0500110 * columns. This allows a single array with many elements to be
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 * displayed in a table that has a fixed column count.
112 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 * @param array
114 * @param int
115 * @return void
116 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200117 public function make_columns($array = array(), $col_limit = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200119 if ( ! is_array($array) OR count($array) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 {
121 return FALSE;
122 }
Barry Mienydd671972010-10-04 16:33:58 +0200123
124 // Turn off the auto-heading feature since it's doubtful we
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 // will want headings from a one-dimensional array
126 $this->auto_heading = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200127
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 if ($col_limit == 0)
129 {
130 return $array;
131 }
Barry Mienydd671972010-10-04 16:33:58 +0200132
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 $new = array();
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200134 do
Barry Mienydd671972010-10-04 16:33:58 +0200135 {
136 $temp = array_splice($array, 0, $col_limit);
137
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 if (count($temp) < $col_limit)
139 {
140 for ($i = count($temp); $i < $col_limit; $i++)
141 {
142 $temp[] = '&nbsp;';
143 }
144 }
Barry Mienydd671972010-10-04 16:33:58 +0200145
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 $new[] = $temp;
147 }
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200148 while (count($array) > 0);
Barry Mienydd671972010-10-04 16:33:58 +0200149
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 return $new;
151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Set "empty" cells
157 *
158 * Can be passed as an array or discreet params
159 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * @param mixed
161 * @return void
162 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200163 public function set_empty($value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 {
165 $this->empty_cells = $value;
166 }
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 // --------------------------------------------------------------------
169
170 /**
171 * Add a table row
172 *
173 * Can be passed as an array or discreet params
174 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 * @param mixed
176 * @return void
177 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200178 public function add_row()
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 {
180 $args = func_get_args();
Derek Jones7b5b0e22010-03-02 22:48:53 -0600181 $this->rows[] = $this->_prep_args($args);
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 }
183
184 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200185
Derek Jones7b5b0e22010-03-02 22:48:53 -0600186 /**
187 * Prep Args
188 *
189 * Ensures a standard associative array format for all cell data
190 *
Derek Jones7b5b0e22010-03-02 22:48:53 -0600191 * @param type
192 * @return type
193 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200194 protected function _prep_args($args)
Derek Jones7b5b0e22010-03-02 22:48:53 -0600195 {
196 // If there is no $args[0], skip this and treat as an associative array
197 // This can happen if there is only a single key, for example this is passed to table->generate
198 // array(array('foo'=>'bar'))
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200199 if (isset($args[0]) AND (count($args) === 1 && is_array($args[0])))
Derek Jones7b5b0e22010-03-02 22:48:53 -0600200 {
201 // args sent as indexed array
202 if ( ! isset($args[0]['data']))
203 {
204 foreach ($args[0] as $key => $val)
205 {
206 if (is_array($val) && isset($val['data']))
207 {
208 $args[$key] = $val;
209 }
210 else
211 {
Barry Mienydd671972010-10-04 16:33:58 +0200212 $args[$key] = array('data' => $val);
Derek Jones7b5b0e22010-03-02 22:48:53 -0600213 }
Barry Mienydd671972010-10-04 16:33:58 +0200214 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600215 }
216 }
217 else
218 {
219 foreach ($args as $key => $val)
220 {
221 if ( ! is_array($val))
222 {
223 $args[$key] = array('data' => $val);
224 }
225 }
226 }
Barry Mienydd671972010-10-04 16:33:58 +0200227
Derek Jones7b5b0e22010-03-02 22:48:53 -0600228 return $args;
229 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000230
Derek Jones7b5b0e22010-03-02 22:48:53 -0600231 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200232
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 /**
234 * Add a table caption
235 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 * @param string
237 * @return void
238 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200239 public function set_caption($caption)
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 {
241 $this->caption = $caption;
Barry Mienydd671972010-10-04 16:33:58 +0200242 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000243
244 // --------------------------------------------------------------------
245
246 /**
247 * Generate the table
248 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 * @param mixed
250 * @return string
251 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200252 public function generate($table_data = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 {
254 // The table data can optionally be passed to this function
255 // either as a database result object or an array
256 if ( ! is_null($table_data))
257 {
258 if (is_object($table_data))
259 {
260 $this->_set_from_object($table_data);
261 }
262 elseif (is_array($table_data))
263 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200264 $set_heading = (count($this->heading) === 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 $this->_set_from_array($table_data, $set_heading);
266 }
267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Jones4b9c6292011-07-01 17:40:48 -0500269 // Is there anything to display? No? Smite them!
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200270 if (count($this->heading) === 0 AND count($this->rows) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 {
272 return 'Undefined table data';
273 }
Barry Mienydd671972010-10-04 16:33:58 +0200274
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 // Compile and validate the template date
276 $this->_compile_template();
Barry Mienydd671972010-10-04 16:33:58 +0200277
Derek Jones7b5b0e22010-03-02 22:48:53 -0600278 // set a custom cell manipulation function to a locally scoped variable so its callable
279 $function = $this->function;
Barry Mienydd671972010-10-04 16:33:58 +0200280
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 // Build the table!
Barry Mienydd671972010-10-04 16:33:58 +0200282
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200283 $out = $this->template['table_open'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000284
285 // Add any caption here
286 if ($this->caption)
287 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200288 $out .= $this->newline.'<caption>'.$this->caption.'</caption>'.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 }
290
291 // Is there a table heading to display?
292 if (count($this->heading) > 0)
293 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200294 $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000295
Pascal Kriete14287f32011-02-14 13:39:34 -0500296 foreach ($this->heading as $heading)
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600298 $temp = $this->template['heading_cell_start'];
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Jones7b5b0e22010-03-02 22:48:53 -0600300 foreach ($heading as $key => $val)
301 {
302 if ($key != 'data')
303 {
304 $temp = str_replace('<th', "<th $key='$val'", $temp);
Barry Mienydd671972010-10-04 16:33:58 +0200305 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600306 }
307
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200308 $out .= $temp.(isset($heading['data']) ? $heading['data'] : '').$this->template['heading_cell_end'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 }
310
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200311 $out .= $this->template['heading_row_end'].$this->newline.$this->template['thead_close'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 }
Barry Mienydd671972010-10-04 16:33:58 +0200313
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 // Build the table rows
315 if (count($this->rows) > 0)
316 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200317 $out .= $this->template['tbody_open'].$this->newline;
Barry Mienydd671972010-10-04 16:33:58 +0200318
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 $i = 1;
Pascal Kriete14287f32011-02-14 13:39:34 -0500320 foreach ($this->rows as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 {
322 if ( ! is_array($row))
323 {
324 break;
325 }
Barry Mienydd671972010-10-04 16:33:58 +0200326
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 // We use modulus to alternate the row colors
328 $name = (fmod($i++, 2)) ? '' : 'alt_';
Barry Mienydd671972010-10-04 16:33:58 +0200329
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200330 $out .= $this->template['row_'.$name.'start'].$this->newline;
Barry Mienydd671972010-10-04 16:33:58 +0200331
Pascal Kriete14287f32011-02-14 13:39:34 -0500332 foreach ($row as $cell)
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600334 $temp = $this->template['cell_'.$name.'start'];
Barry Mienydd671972010-10-04 16:33:58 +0200335
Derek Jones7b5b0e22010-03-02 22:48:53 -0600336 foreach ($cell as $key => $val)
337 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200338 if ($key !== 'data')
Derek Jones7b5b0e22010-03-02 22:48:53 -0600339 {
340 $temp = str_replace('<td', "<td $key='$val'", $temp);
Barry Mienydd671972010-10-04 16:33:58 +0200341 }
Derek Jones7b5b0e22010-03-02 22:48:53 -0600342 }
Barry Mienydd671972010-10-04 16:33:58 +0200343
Derek Jones7b5b0e22010-03-02 22:48:53 -0600344 $cell = isset($cell['data']) ? $cell['data'] : '';
345 $out .= $temp;
346
Derek Allardd8270582010-01-15 17:10:56 +0000347 if ($cell === "" OR $cell === NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 {
349 $out .= $this->empty_cells;
350 }
351 else
352 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600353 if ($function !== FALSE && is_callable($function))
354 {
Phil Sturgeon6c597f82010-12-27 17:35:35 +0000355 $out .= call_user_func($function, $cell);
Derek Jones7b5b0e22010-03-02 22:48:53 -0600356 }
357 else
358 {
359 $out .= $cell;
360 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 }
Barry Mienydd671972010-10-04 16:33:58 +0200362
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 $out .= $this->template['cell_'.$name.'end'];
364 }
Barry Mienydd671972010-10-04 16:33:58 +0200365
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200366 $out .= $this->template['row_'.$name.'end'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 }
Barry Mienydd671972010-10-04 16:33:58 +0200368
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200369 $out .= $this->template['tbody_close'].$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 }
371
372 $out .= $this->template['table_close'];
Barry Mienydd671972010-10-04 16:33:58 +0200373
Greg Aker02b3a5b2011-02-01 01:29:21 -0600374 // Clear table class properties before generating the table
375 $this->clear();
376
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 return $out;
378 }
Barry Mienydd671972010-10-04 16:33:58 +0200379
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 // --------------------------------------------------------------------
381
382 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500383 * Clears the table arrays. Useful if multiple tables are being generated
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 * @return void
386 */
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200387 public function clear()
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 {
389 $this->rows = array();
390 $this->heading = array();
Barry Mienydd671972010-10-04 16:33:58 +0200391 $this->auto_heading = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 }
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 // --------------------------------------------------------------------
395
396 /**
397 * Set table data from a database result object
398 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 * @param object
400 * @return void
401 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200402 protected function _set_from_object($query)
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 {
404 if ( ! is_object($query))
405 {
406 return FALSE;
407 }
Barry Mienydd671972010-10-04 16:33:58 +0200408
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 // First generate the headings from the table column names
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200410 if (count($this->heading) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
412 if ( ! method_exists($query, 'list_fields'))
413 {
414 return FALSE;
415 }
Barry Mienydd671972010-10-04 16:33:58 +0200416
Derek Jones7b5b0e22010-03-02 22:48:53 -0600417 $this->heading = $this->_prep_args($query->list_fields());
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 }
Barry Mienydd671972010-10-04 16:33:58 +0200419
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 // Next blast through the result array and build out the rows
Barry Mienydd671972010-10-04 16:33:58 +0200421
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 if ($query->num_rows() > 0)
423 {
424 foreach ($query->result_array() as $row)
425 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600426 $this->rows[] = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
428 }
429 }
430
431 // --------------------------------------------------------------------
432
433 /**
434 * Set table data from an array
435 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 * @param array
437 * @return void
438 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200439 protected function _set_from_array($data, $set_heading = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
Andrey Andreevfe9b9a92011-12-25 16:11:01 +0200441 if ( ! is_array($data) OR count($data) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 {
443 return FALSE;
444 }
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 $i = 0;
447 foreach ($data as $row)
Barry Mienydd671972010-10-04 16:33:58 +0200448 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 // 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 +0200450 if ($i++ === 0 AND count($data) > 1 AND count($this->heading) === 0 AND $set_heading == TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600452 $this->heading = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 }
454 else
455 {
Derek Jones7b5b0e22010-03-02 22:48:53 -0600456 $this->rows[] = $this->_prep_args($row);
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 }
459 }
460
461 // --------------------------------------------------------------------
462
463 /**
464 * Compile Template
465 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 * @return void
467 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200468 protected function _compile_template()
Barry Mienydd671972010-10-04 16:33:58 +0200469 {
470 if ($this->template == NULL)
471 {
472 $this->template = $this->_default_template();
473 return;
474 }
475
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 $this->temp = $this->_default_template();
Derek Jones7b5b0e22010-03-02 22:48:53 -0600477 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 +0000478 {
479 if ( ! isset($this->template[$val]))
480 {
481 $this->template[$val] = $this->temp[$val];
482 }
Barry Mienydd671972010-10-04 16:33:58 +0200483 }
484 }
485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 // --------------------------------------------------------------------
487
488 /**
489 * Default Template
490 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 * @return void
492 */
Andrey Andreev49ddaa32011-12-26 16:54:10 +0200493 protected function _default_template()
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500495 return array (
Barry Mienydd671972010-10-04 16:33:58 +0200496 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
497
Derek Jones7b5b0e22010-03-02 22:48:53 -0600498 'thead_open' => '<thead>',
499 'thead_close' => '</thead>',
Barry Mienydd671972010-10-04 16:33:58 +0200500
501 'heading_row_start' => '<tr>',
502 'heading_row_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 'heading_cell_start' => '<th>',
504 'heading_cell_end' => '</th>',
505
Derek Jones7b5b0e22010-03-02 22:48:53 -0600506 'tbody_open' => '<tbody>',
507 'tbody_close' => '</tbody>',
Barry Mienydd671972010-10-04 16:33:58 +0200508
509 'row_start' => '<tr>',
510 'row_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 'cell_start' => '<td>',
512 'cell_end' => '</td>',
513
Barry Mienydd671972010-10-04 16:33:58 +0200514 'row_alt_start' => '<tr>',
515 'row_alt_end' => '</tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 'cell_alt_start' => '<td>',
517 'cell_alt_end' => '</td>',
518
Barry Mienydd671972010-10-04 16:33:58 +0200519 'table_close' => '</table>'
520 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 }
Barry Mienydd671972010-10-04 16:33:58 +0200522
Derek Allard2067d1a2008-11-13 22:59:24 +0000523
524}
525
Derek Allard2067d1a2008-11-13 22:59:24 +0000526/* End of file Table.php */
Gerry6b590892011-09-25 00:16:39 +0800527/* Location: ./system/libraries/Table.php */