Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.3.1 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * HTML Table Generating Class |
| 31 | * |
| 32 | * Lets you create tables manually or from database result objects, or arrays. |
| 33 | * |
| 34 | * @package CodeIgniter |
| 35 | * @subpackage Libraries |
| 36 | * @category HTML Tables |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 37 | * @author EllisLab Dev Team |
Gerry | 6b59089 | 2011-09-25 00:16:39 +0800 | [diff] [blame] | 38 | * @link http://codeigniter.com/user_guide/libraries/table.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | */ |
| 40 | class CI_Table { |
| 41 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Data for table rows |
| 44 | * |
| 45 | * @var array |
| 46 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 47 | public $rows = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 48 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 49 | /** |
| 50 | * Data for table heading |
| 51 | * |
| 52 | * @var array |
| 53 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 54 | public $heading = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 55 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 56 | /** |
| 57 | * Whether or not to automatically create the table header |
| 58 | * |
| 59 | * @var bool |
| 60 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 61 | public $auto_heading = TRUE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 62 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 63 | /** |
| 64 | * Table caption |
| 65 | * |
| 66 | * @var string |
| 67 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 68 | public $caption = NULL; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 69 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 70 | /** |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 71 | * Table layout template |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 72 | * |
| 73 | * @var array |
| 74 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 75 | public $template = NULL; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 76 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Newline setting |
| 79 | * |
| 80 | * @var string |
| 81 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 82 | public $newline = "\n"; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 83 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 84 | /** |
| 85 | * Contents of empty cells |
| 86 | * |
| 87 | * @var string |
| 88 | */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 89 | public $empty_cells = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 90 | |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 91 | /** |
| 92 | * Callback for custom table layout |
| 93 | * |
| 94 | * @var function |
| 95 | */ |
Andrey Andreev | a49c8ad | 2014-02-11 17:15:07 +0200 | [diff] [blame] | 96 | public $function = NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 97 | |
Mike Funk | 46e3a9a | 2012-02-24 09:38:35 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Set the template from the table config file if it exists |
Andrey Andreev | 8029532 | 2012-03-12 16:29:16 +0200 | [diff] [blame] | 100 | * |
Mike Funk | 5fbaf27 | 2012-03-12 10:19:46 -0400 | [diff] [blame] | 101 | * @param array $config (default: array()) |
Mike Funk | aa20f5b | 2012-02-28 13:43:16 -0500 | [diff] [blame] | 102 | * @return void |
Mike Funk | 46e3a9a | 2012-02-24 09:38:35 -0500 | [diff] [blame] | 103 | */ |
| 104 | public function __construct($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | { |
Mike Funk | 46e3a9a | 2012-02-24 09:38:35 -0500 | [diff] [blame] | 106 | // initialize config |
| 107 | foreach ($config as $key => $val) |
| 108 | { |
| 109 | $this->template[$key] = $val; |
| 110 | } |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 111 | |
| 112 | log_message('debug', 'Table Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // -------------------------------------------------------------------- |
| 116 | |
| 117 | /** |
| 118 | * Set the template |
| 119 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 120 | * @param array $template |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 121 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 123 | public function set_template($template) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | { |
| 125 | if ( ! is_array($template)) |
| 126 | { |
| 127 | return FALSE; |
| 128 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | $this->template = $template; |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 131 | return TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | // -------------------------------------------------------------------- |
| 135 | |
| 136 | /** |
| 137 | * Set the table heading |
| 138 | * |
| 139 | * Can be passed as an array or discreet params |
| 140 | * |
Andrey Andreev | 3fcc3f6 | 2014-02-11 17:28:36 +0200 | [diff] [blame] | 141 | * @param mixed |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 142 | * @return CI_Table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | */ |
Andrey Andreev | 3fcc3f6 | 2014-02-11 17:28:36 +0200 | [diff] [blame] | 144 | public function set_heading($args = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | { |
Andrey Andreev | 3fcc3f6 | 2014-02-11 17:28:36 +0200 | [diff] [blame] | 146 | $this->heading = $this->_prep_args(func_get_args()); |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 147 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // -------------------------------------------------------------------- |
| 151 | |
| 152 | /** |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 153 | * Set columns. Takes a one-dimensional array as input and creates |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 154 | * a multi-dimensional array with a depth equal to the number of |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 155 | * columns. This allows a single array with many elements to be |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | * displayed in a table that has a fixed column count. |
| 157 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 158 | * @param array $array |
| 159 | * @param int $col_limit |
| 160 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 162 | public function make_columns($array = array(), $col_limit = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | { |
Taufan Aditya | 8749bc7 | 2012-03-11 05:43:45 +0700 | [diff] [blame] | 164 | if ( ! is_array($array) OR count($array) === 0 OR ! is_int($col_limit)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | { |
| 166 | return FALSE; |
| 167 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | |
| 169 | // Turn off the auto-heading feature since it's doubtful we |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | // will want headings from a one-dimensional array |
| 171 | $this->auto_heading = FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 172 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 173 | if ($col_limit === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | { |
| 175 | return $array; |
| 176 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 177 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | $new = array(); |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 179 | do |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 180 | { |
| 181 | $temp = array_splice($array, 0, $col_limit); |
| 182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | if (count($temp) < $col_limit) |
| 184 | { |
| 185 | for ($i = count($temp); $i < $col_limit; $i++) |
| 186 | { |
| 187 | $temp[] = ' '; |
| 188 | } |
| 189 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 190 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | $new[] = $temp; |
| 192 | } |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 193 | while (count($array) > 0); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 194 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | return $new; |
| 196 | } |
| 197 | |
| 198 | // -------------------------------------------------------------------- |
| 199 | |
| 200 | /** |
| 201 | * Set "empty" cells |
| 202 | * |
| 203 | * Can be passed as an array or discreet params |
| 204 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 205 | * @param mixed $value |
| 206 | * @return CI_Table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 208 | public function set_empty($value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | { |
| 210 | $this->empty_cells = $value; |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 211 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | // -------------------------------------------------------------------- |
| 215 | |
| 216 | /** |
| 217 | * Add a table row |
| 218 | * |
| 219 | * Can be passed as an array or discreet params |
| 220 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | * @param mixed |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 222 | * @return CI_Table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | */ |
Timothy Warren | 3182a76 | 2012-04-26 18:09:25 -0400 | [diff] [blame] | 224 | public function add_row($args = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | { |
Andrey Andreev | 3fcc3f6 | 2014-02-11 17:28:36 +0200 | [diff] [blame] | 226 | $this->rows[] = $this->_prep_args(func_get_args()); |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 227 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 231 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 232 | /** |
| 233 | * Prep Args |
| 234 | * |
| 235 | * Ensures a standard associative array format for all cell data |
| 236 | * |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 237 | * @param array |
| 238 | * @return array |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 239 | */ |
Andrey Andreev | 49ddaa3 | 2011-12-26 16:54:10 +0200 | [diff] [blame] | 240 | protected function _prep_args($args) |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 241 | { |
| 242 | // If there is no $args[0], skip this and treat as an associative array |
| 243 | // This can happen if there is only a single key, for example this is passed to table->generate |
| 244 | // array(array('foo'=>'bar')) |
Andrey Andreev | f0b69a8 | 2014-02-11 17:56:44 +0200 | [diff] [blame^] | 245 | if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 246 | { |
Andrey Andreev | f0b69a8 | 2014-02-11 17:56:44 +0200 | [diff] [blame^] | 247 | $args = $args[0]; |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 248 | } |
Andrey Andreev | f0b69a8 | 2014-02-11 17:56:44 +0200 | [diff] [blame^] | 249 | |
| 250 | foreach ($args as $key => $val) |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 251 | { |
Andrey Andreev | f0b69a8 | 2014-02-11 17:56:44 +0200 | [diff] [blame^] | 252 | is_array($val) OR $args[$key] = array('data' => $val); |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 253 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 254 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 255 | return $args; |
| 256 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 258 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | /** |
| 261 | * Add a table caption |
| 262 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 263 | * @param string $caption |
| 264 | * @return CI_Table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 266 | public function set_caption($caption) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | { |
| 268 | $this->caption = $caption; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 269 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | |
| 271 | // -------------------------------------------------------------------- |
| 272 | |
| 273 | /** |
| 274 | * Generate the table |
| 275 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 276 | * @param mixed $table_data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 277 | * @return string |
| 278 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 279 | public function generate($table_data = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | { |
| 281 | // The table data can optionally be passed to this function |
| 282 | // either as a database result object or an array |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 283 | if ( ! empty($table_data)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 285 | if ($table_data instanceof CI_DB_result) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 287 | $this->_set_from_db_result($table_data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
| 289 | elseif (is_array($table_data)) |
| 290 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 291 | $this->_set_from_array($table_data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 294 | |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 295 | // Is there anything to display? No? Smite them! |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 296 | if (empty($this->heading) && empty($this->rows)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | { |
| 298 | return 'Undefined table data'; |
| 299 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 300 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | // Compile and validate the template date |
| 302 | $this->_compile_template(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 303 | |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 304 | // Validate a possibly existing custom cell manipulation function |
Andrey Andreev | a49c8ad | 2014-02-11 17:15:07 +0200 | [diff] [blame] | 305 | if (isset($this->function) && ! is_callable($this->function)) |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 306 | { |
Andrey Andreev | a49c8ad | 2014-02-11 17:15:07 +0200 | [diff] [blame] | 307 | $this->function = NULL; |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 308 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 309 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | // Build the table! |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 311 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 312 | $out = $this->template['table_open'].$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | |
| 314 | // Add any caption here |
| 315 | if ($this->caption) |
| 316 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 317 | $out .= '<caption>'.$this->caption.'</caption>'.$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | // Is there a table heading to display? |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 321 | if ( ! empty($this->heading)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | { |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 323 | $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 324 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 325 | foreach ($this->heading as $heading) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | { |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 327 | $temp = $this->template['heading_cell_start']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 328 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 329 | foreach ($heading as $key => $val) |
| 330 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 331 | if ($key !== 'data') |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 332 | { |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 333 | $temp = str_replace('<th', '<th '.$key.'="'.$val.'"', $temp); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 334 | } |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 335 | } |
| 336 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 337 | $out .= $temp.(isset($heading['data']) ? $heading['data'] : '').$this->template['heading_cell_end']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 340 | $out .= $this->template['heading_row_end'].$this->newline.$this->template['thead_close'].$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 342 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | // Build the table rows |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 344 | if ( ! empty($this->rows)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | { |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 346 | $out .= $this->template['tbody_open'].$this->newline; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 347 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 348 | $i = 1; |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 349 | foreach ($this->rows as $row) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 350 | { |
| 351 | if ( ! is_array($row)) |
| 352 | { |
| 353 | break; |
| 354 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 355 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | // We use modulus to alternate the row colors |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 357 | $name = fmod($i++, 2) ? '' : 'alt_'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 358 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 359 | $out .= $this->template['row_'.$name.'start'].$this->newline; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 360 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 361 | foreach ($row as $cell) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | { |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 363 | $temp = $this->template['cell_'.$name.'start']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 364 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 365 | foreach ($cell as $key => $val) |
| 366 | { |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 367 | if ($key !== 'data') |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 368 | { |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 369 | $temp = str_replace('<td', '<td '.$key.'="'.$val.'"', $temp); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 370 | } |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 371 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 372 | |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 373 | $cell = isset($cell['data']) ? $cell['data'] : ''; |
| 374 | $out .= $temp; |
| 375 | |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 376 | if ($cell === '' OR $cell === NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | { |
| 378 | $out .= $this->empty_cells; |
| 379 | } |
Andrey Andreev | a49c8ad | 2014-02-11 17:15:07 +0200 | [diff] [blame] | 380 | elseif (isset($this->function)) |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 381 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 382 | $out .= call_user_func($this->function, $cell); |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 383 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 384 | else |
| 385 | { |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 386 | $out .= $cell; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 388 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | $out .= $this->template['cell_'.$name.'end']; |
| 390 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 392 | $out .= $this->template['row_'.$name.'end'].$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 393 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 394 | |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 395 | $out .= $this->template['tbody_close'].$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | $out .= $this->template['table_close']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 399 | |
Greg Aker | 02b3a5b | 2011-02-01 01:29:21 -0600 | [diff] [blame] | 400 | // Clear table class properties before generating the table |
| 401 | $this->clear(); |
| 402 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | return $out; |
| 404 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | // -------------------------------------------------------------------- |
| 407 | |
| 408 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 409 | * Clears the table arrays. Useful if multiple tables are being generated |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | * |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 411 | * @return CI_Table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | */ |
Andrey Andreev | fe9b9a9 | 2011-12-25 16:11:01 +0200 | [diff] [blame] | 413 | public function clear() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | { |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 415 | $this->rows = array(); |
| 416 | $this->heading = array(); |
| 417 | $this->auto_heading = TRUE; |
| 418 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 420 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | // -------------------------------------------------------------------- |
| 422 | |
| 423 | /** |
| 424 | * Set table data from a database result object |
| 425 | * |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 426 | * @param CI_DB_result $db_result Database result object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 427 | * @return void |
| 428 | */ |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 429 | protected function _set_from_db_result($object) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | // First generate the headings from the table column names |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 432 | if ($this->auto_heading === TRUE && empty($this->heading)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 434 | $this->heading = $this->_prep_args($object->list_fields()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 435 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 437 | foreach ($object->result_array() as $row) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 439 | $this->rows[] = $this->_prep_args($row); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
| 443 | // -------------------------------------------------------------------- |
| 444 | |
| 445 | /** |
| 446 | * Set table data from an array |
| 447 | * |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 448 | * @param array $data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | * @return void |
| 450 | */ |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 451 | protected function _set_from_array($data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 452 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 453 | if ($this->auto_heading === TRUE && empty($this->heading)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 454 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 455 | $this->heading = $this->_prep_args(array_shift($data)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 457 | |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 458 | foreach ($data as &$row) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 459 | { |
Andrey Andreev | 05983fc | 2014-02-11 16:51:43 +0200 | [diff] [blame] | 460 | $this->rows[] = $this->_prep_args($row); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | // -------------------------------------------------------------------- |
| 465 | |
| 466 | /** |
| 467 | * Compile Template |
| 468 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | * @return void |
| 470 | */ |
Andrey Andreev | 49ddaa3 | 2011-12-26 16:54:10 +0200 | [diff] [blame] | 471 | protected function _compile_template() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 472 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 473 | if ($this->template === NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 474 | { |
| 475 | $this->template = $this->_default_template(); |
| 476 | return; |
| 477 | } |
| 478 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | $this->temp = $this->_default_template(); |
Derek Jones | 7b5b0e2 | 2010-03-02 22:48:53 -0600 | [diff] [blame] | 480 | 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | { |
| 482 | if ( ! isset($this->template[$val])) |
| 483 | { |
| 484 | $this->template[$val] = $this->temp[$val]; |
| 485 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 489 | // -------------------------------------------------------------------- |
| 490 | |
| 491 | /** |
| 492 | * Default Template |
| 493 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | * @return void |
| 495 | */ |
Andrey Andreev | 49ddaa3 | 2011-12-26 16:54:10 +0200 | [diff] [blame] | 496 | protected function _default_template() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | { |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 498 | return array( |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 499 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 501 | 'thead_open' => '<thead>', |
| 502 | 'thead_close' => '</thead>', |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 503 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 504 | 'heading_row_start' => '<tr>', |
| 505 | 'heading_row_end' => '</tr>', |
| 506 | 'heading_cell_start' => '<th>', |
| 507 | 'heading_cell_end' => '</th>', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 509 | 'tbody_open' => '<tbody>', |
| 510 | 'tbody_close' => '</tbody>', |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 511 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 512 | 'row_start' => '<tr>', |
| 513 | 'row_end' => '</tr>', |
| 514 | 'cell_start' => '<td>', |
| 515 | 'cell_end' => '</td>', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 516 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 517 | 'row_alt_start' => '<tr>', |
| 518 | 'row_alt_end' => '</tr>', |
| 519 | 'cell_alt_start' => '<td>', |
| 520 | 'cell_alt_end' => '</td>', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 522 | 'table_close' => '</table>' |
| 523 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 524 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 525 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | /* End of file Table.php */ |
Andrey Andreev | 2b39d9d | 2012-04-03 19:14:23 +0300 | [diff] [blame] | 529 | /* Location: ./system/libraries/Table.php */ |