From 6b5908947853281c4bd5577269b90ba3eead5ddd Mon Sep 17 00:00:00 2001 From: Gerry Date: Sun, 25 Sep 2011 00:16:39 +0800 Subject: Fixing the documentation url given in the Table library --- system/libraries/Table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index def696776..c14da727e 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -24,7 +24,7 @@ * @subpackage Libraries * @category HTML Tables * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/uri.html + * @link http://codeigniter.com/user_guide/libraries/table.html */ class CI_Table { @@ -528,4 +528,4 @@ class CI_Table { /* End of file Table.php */ -/* Location: ./system/libraries/Table.php */ \ No newline at end of file +/* Location: ./system/libraries/Table.php */ -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Table.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index c14da727e..8d0e11a43 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.3.1 * @filesource @@ -23,7 +35,7 @@ * @package CodeIgniter * @subpackage Libraries * @category HTML Tables - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/table.html */ class CI_Table { -- cgit v1.2.3-24-g4f1b From fe9b9a96b4aacc54765190c1c3fc01271d361c36 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 16:11:01 +0200 Subject: Improve the Table library --- system/libraries/Table.php | 109 +++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 63 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 8d0e11a43..fb410e9fd 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,13 +1,13 @@ -heading = $this->_prep_args($args); @@ -103,9 +103,9 @@ class CI_Table { * @param int * @return void */ - function make_columns($array = array(), $col_limit = 0) + public function make_columns($array = array(), $col_limit = 0) { - if ( ! is_array($array) OR count($array) == 0) + if ( ! is_array($array) OR count($array) === 0) { return FALSE; } @@ -120,7 +120,7 @@ class CI_Table { } $new = array(); - while (count($array) > 0) + do { $temp = array_splice($array, 0, $col_limit); @@ -134,6 +134,7 @@ class CI_Table { $new[] = $temp; } + while (count($array) > 0); return $new; } @@ -149,7 +150,7 @@ class CI_Table { * @param mixed * @return void */ - function set_empty($value) + public function set_empty($value) { $this->empty_cells = $value; } @@ -165,7 +166,7 @@ class CI_Table { * @param mixed * @return void */ - function add_row() + public function add_row() { $args = func_get_args(); $this->rows[] = $this->_prep_args($args); @@ -178,16 +179,16 @@ class CI_Table { * * Ensures a standard associative array format for all cell data * - * @access public + * @access private * @param type * @return type */ - function _prep_args($args) + private function _prep_args($args) { // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate // array(array('foo'=>'bar')) - if (isset($args[0]) AND (count($args) == 1 && is_array($args[0]))) + if (isset($args[0]) AND (count($args) === 1 && is_array($args[0]))) { // args sent as indexed array if ( ! isset($args[0]['data'])) @@ -228,7 +229,7 @@ class CI_Table { * @param string * @return void */ - function set_caption($caption) + public function set_caption($caption) { $this->caption = $caption; } @@ -242,7 +243,7 @@ class CI_Table { * @param mixed * @return string */ - function generate($table_data = NULL) + public function generate($table_data = NULL) { // The table data can optionally be passed to this function // either as a database result object or an array @@ -254,13 +255,13 @@ class CI_Table { } elseif (is_array($table_data)) { - $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; + $set_heading = (count($this->heading) === 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; $this->_set_from_array($table_data, $set_heading); } } // Is there anything to display? No? Smite them! - if (count($this->heading) == 0 AND count($this->rows) == 0) + if (count($this->heading) === 0 AND count($this->rows) === 0) { return 'Undefined table data'; } @@ -273,24 +274,18 @@ class CI_Table { // Build the table! - $out = $this->template['table_open']; - $out .= $this->newline; + $out = $this->template['table_open'].$this->newline; // Add any caption here if ($this->caption) { - $out .= $this->newline; - $out .= '' . $this->caption . ''; - $out .= $this->newline; + $out .= $this->newline.''.$this->caption.''.$this->newline; } // Is there a table heading to display? if (count($this->heading) > 0) { - $out .= $this->template['thead_open']; - $out .= $this->newline; - $out .= $this->template['heading_row_start']; - $out .= $this->newline; + $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline; foreach ($this->heading as $heading) { @@ -304,22 +299,16 @@ class CI_Table { } } - $out .= $temp; - $out .= isset($heading['data']) ? $heading['data'] : ''; - $out .= $this->template['heading_cell_end']; + $out .= $temp.(isset($heading['data']) ? $heading['data'] : '').$this->template['heading_cell_end']; } - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - $out .= $this->template['thead_close']; - $out .= $this->newline; + $out .= $this->template['heading_row_end'].$this->newline.$this->template['thead_close'].$this->newline; } // Build the table rows if (count($this->rows) > 0) { - $out .= $this->template['tbody_open']; - $out .= $this->newline; + $out .= $this->template['tbody_open'].$this->newline; $i = 1; foreach ($this->rows as $row) @@ -332,8 +321,7 @@ class CI_Table { // We use modulus to alternate the row colors $name = (fmod($i++, 2)) ? '' : 'alt_'; - $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; + $out .= $this->template['row_'.$name.'start'].$this->newline; foreach ($row as $cell) { @@ -341,7 +329,7 @@ class CI_Table { foreach ($cell as $key => $val) { - if ($key != 'data') + if ($key !== 'data') { $temp = str_replace('template['cell_'.$name.'end']; } - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; + $out .= $this->template['row_'.$name.'end'].$this->newline; } - $out .= $this->template['tbody_close']; - $out .= $this->newline; + $out .= $this->template['tbody_close'].$this->newline; } $out .= $this->template['table_close']; @@ -393,7 +379,7 @@ class CI_Table { * @access public * @return void */ - function clear() + public function clear() { $this->rows = array(); $this->heading = array(); @@ -405,11 +391,11 @@ class CI_Table { /** * Set table data from a database result object * - * @access public + * @access private * @param object * @return void */ - function _set_from_object($query) + private function _set_from_object($query) { if ( ! is_object($query)) { @@ -417,7 +403,7 @@ class CI_Table { } // First generate the headings from the table column names - if (count($this->heading) == 0) + if (count($this->heading) === 0) { if ( ! method_exists($query, 'list_fields')) { @@ -443,13 +429,13 @@ class CI_Table { /** * Set table data from an array * - * @access public + * @access private * @param array * @return void */ - function _set_from_array($data, $set_heading = TRUE) + private function _set_from_array($data, $set_heading = TRUE) { - if ( ! is_array($data) OR count($data) == 0) + if ( ! is_array($data) OR count($data) === 0) { return FALSE; } @@ -458,7 +444,7 @@ class CI_Table { foreach ($data as $row) { // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE) + if ($i++ === 0 AND count($data) > 1 AND count($this->heading) === 0 AND $set_heading == TRUE) { $this->heading = $this->_prep_args($row); } @@ -466,8 +452,6 @@ class CI_Table { { $this->rows[] = $this->_prep_args($row); } - - $i++; } } @@ -479,7 +463,7 @@ class CI_Table { * @access private * @return void */ - function _compile_template() + private function _compile_template() { if ($this->template == NULL) { @@ -505,7 +489,7 @@ class CI_Table { * @access private * @return void */ - function _default_template() + private function _default_template() { return array ( 'table_open' => '', @@ -538,6 +522,5 @@ class CI_Table { } - /* End of file Table.php */ /* Location: ./system/libraries/Table.php */ -- cgit v1.2.3-24-g4f1b From 49ddaa3a65e4fcfd362bc8eb57e7fc5f9dbfa42e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Dec 2011 16:54:10 +0200 Subject: Replace private with protected, so the class can be easily extended --- system/libraries/Table.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index fb410e9fd..9aa467b1a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -179,11 +179,11 @@ class CI_Table { * * Ensures a standard associative array format for all cell data * - * @access private + * @access protected * @param type * @return type */ - private function _prep_args($args) + protected function _prep_args($args) { // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate @@ -391,11 +391,11 @@ class CI_Table { /** * Set table data from a database result object * - * @access private + * @access protected * @param object * @return void */ - private function _set_from_object($query) + protected function _set_from_object($query) { if ( ! is_object($query)) { @@ -429,11 +429,11 @@ class CI_Table { /** * Set table data from an array * - * @access private + * @access protected * @param array * @return void */ - private function _set_from_array($data, $set_heading = TRUE) + protected function _set_from_array($data, $set_heading = TRUE) { if ( ! is_array($data) OR count($data) === 0) { @@ -460,10 +460,10 @@ class CI_Table { /** * Compile Template * - * @access private + * @access protected * @return void */ - private function _compile_template() + protected function _compile_template() { if ($this->template == NULL) { @@ -486,10 +486,10 @@ class CI_Table { /** * Default Template * - * @access private + * @access protected * @return void */ - private function _default_template() + protected function _default_template() { return array ( 'table_open' => '
', -- cgit v1.2.3-24-g4f1b From 0c82cf5fa2555a28c05d0b64a15f27933a4ab382 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 02:45:56 +0200 Subject: Remove access lines from method descriptions --- system/libraries/Table.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 9aa467b1a..1851bf3bc 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -59,7 +59,6 @@ class CI_Table { /** * Set the template * - * @access public * @param array * @return void */ @@ -80,7 +79,6 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @access public * @param mixed * @return void */ @@ -98,7 +96,6 @@ class CI_Table { * columns. This allows a single array with many elements to be * displayed in a table that has a fixed column count. * - * @access public * @param array * @param int * @return void @@ -146,7 +143,6 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @access public * @param mixed * @return void */ @@ -162,7 +158,6 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @access public * @param mixed * @return void */ @@ -179,7 +174,6 @@ class CI_Table { * * Ensures a standard associative array format for all cell data * - * @access protected * @param type * @return type */ @@ -225,7 +219,6 @@ class CI_Table { /** * Add a table caption * - * @access public * @param string * @return void */ @@ -239,7 +232,6 @@ class CI_Table { /** * Generate the table * - * @access public * @param mixed * @return string */ @@ -376,7 +368,6 @@ class CI_Table { /** * Clears the table arrays. Useful if multiple tables are being generated * - * @access public * @return void */ public function clear() @@ -391,7 +382,6 @@ class CI_Table { /** * Set table data from a database result object * - * @access protected * @param object * @return void */ @@ -429,7 +419,6 @@ class CI_Table { /** * Set table data from an array * - * @access protected * @param array * @return void */ @@ -460,7 +449,6 @@ class CI_Table { /** * Compile Template * - * @access protected * @return void */ protected function _compile_template() @@ -486,7 +474,6 @@ class CI_Table { /** * Default Template * - * @access protected * @return void */ protected function _default_template() -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1851bf3bc..fb154e50f 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.3.1 -- cgit v1.2.3-24-g4f1b From 46e3a9a365e6bae7954f5118db1409faa5f5decd Mon Sep 17 00:00:00 2001 From: Mike Funk Date: Fri, 24 Feb 2012 09:38:35 -0500 Subject: added config check, changelog entry, and user guide update. --- system/libraries/Table.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index fb154e50f..de5a6ba3a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -49,9 +49,23 @@ class CI_Table { public $empty_cells = ''; public $function = FALSE; - public function __construct() + // -------------------------------------------------------------------------- + + /** + * Set the template from the table config file if it exists + * + * @param array $config (default: array()) + * @return void + */ + public function __construct($config = array()) { log_message('debug', "Table Class Initialized"); + + // initialize config + foreach ($config as $key => $val) + { + $this->template[$key] = $val; + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From aa20f5b70f6da196d1a66d5dc17b05a037708e1a Mon Sep 17 00:00:00 2001 From: Mike Funk Date: Tue, 28 Feb 2012 13:43:16 -0500 Subject: using tabs as @item seperators in docblocks. --- system/libraries/Table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index de5a6ba3a..947aedd8f 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -54,8 +54,8 @@ class CI_Table { /** * Set the template from the table config file if it exists * - * @param array $config (default: array()) - * @return void + * @param array $config (default: array()) + * @return void */ public function __construct($config = array()) { -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index fb154e50f..8651b9e69 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 8749bc7e836c196dfef37d3b7b5a67736a15092c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 11 Mar 2012 05:43:45 +0700 Subject: Fix incomplete and skipped test --- system/libraries/Table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index fb154e50f..8f6ac8d45 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -102,7 +102,7 @@ class CI_Table { */ public function make_columns($array = array(), $col_limit = 0) { - if ( ! is_array($array) OR count($array) === 0) + if ( ! is_array($array) OR count($array) === 0 OR ! is_int($col_limit)) { return FALSE; } @@ -395,7 +395,7 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) === 0) { - if ( ! method_exists($query, 'list_fields')) + if ( ! is_callable(array($query, 'list_fields'))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 5fbaf27ac9da632b520457e91d9088e9aab6df89 Mon Sep 17 00:00:00 2001 From: Mike Funk Date: Mon, 12 Mar 2012 10:19:46 -0400 Subject: Changed space to tab in docblock. --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 947aedd8f..649d50875 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -54,7 +54,7 @@ class CI_Table { /** * Set the template from the table config file if it exists * - * @param array $config (default: array()) + * @param array $config (default: array()) * @return void */ public function __construct($config = array()) -- cgit v1.2.3-24-g4f1b From 802953234f0b7669333807aaa3f2318778cde187 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Mar 2012 16:29:16 +0200 Subject: Just some cleanup in the Table class --- system/libraries/Table.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index ceda6f323..99d001ce5 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * HTML Table Generating Class * @@ -49,18 +47,16 @@ class CI_Table { public $empty_cells = ''; public $function = FALSE; - // -------------------------------------------------------------------------- - /** * Set the template from the table config file if it exists - * + * * @param array $config (default: array()) * @return void */ public function __construct($config = array()) { - log_message('debug', "Table Class Initialized"); - + log_message('debug', 'Table Class Initialized'); + // initialize config foreach ($config as $key => $val) { -- cgit v1.2.3-24-g4f1b From 2b39d9d1b837c92a0901ea9f0385172b763e18c8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 19:14:23 +0300 Subject: Minor cleanup and style changes to the Table library --- system/libraries/Table.php | 123 +++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 67 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 11a4858a9..992b057ad 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -38,14 +38,14 @@ */ class CI_Table { - public $rows = array(); - public $heading = array(); - public $auto_heading = TRUE; - public $caption = NULL; - public $template = NULL; - public $newline = "\n"; - public $empty_cells = ''; - public $function = FALSE; + public $rows = array(); + public $heading = array(); + public $auto_heading = TRUE; + public $caption = NULL; + public $template = NULL; + public $newline = "\n"; + public $empty_cells = ''; + public $function = FALSE; /** * Set the template from the table config file if it exists @@ -55,13 +55,13 @@ class CI_Table { */ public function __construct($config = array()) { - log_message('debug', 'Table Class Initialized'); - // initialize config foreach ($config as $key => $val) { $this->template[$key] = $val; } + + log_message('debug', 'Table Class Initialized'); } // -------------------------------------------------------------------- @@ -70,7 +70,7 @@ class CI_Table { * Set the template * * @param array - * @return void + * @return bool */ public function set_template($template) { @@ -80,6 +80,7 @@ class CI_Table { } $this->template = $template; + return TRUE; } // -------------------------------------------------------------------- @@ -101,9 +102,9 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Set columns. Takes a one-dimensional array as input and creates + * Set columns. Takes a one-dimensional array as input and creates * a multi-dimensional array with a depth equal to the number of - * columns. This allows a single array with many elements to be + * columns. This allows a single array with many elements to be * displayed in a table that has a fixed column count. * * @param array @@ -184,29 +185,22 @@ class CI_Table { * * Ensures a standard associative array format for all cell data * - * @param type - * @return type + * @param array + * @return array */ protected function _prep_args($args) { // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate // array(array('foo'=>'bar')) - if (isset($args[0]) AND (count($args) === 1 && is_array($args[0]))) + if (isset($args[0]) && count($args) === 1 && is_array($args[0])) { // args sent as indexed array if ( ! isset($args[0]['data'])) { foreach ($args[0] as $key => $val) { - if (is_array($val) && isset($val['data'])) - { - $args[$key] = $val; - } - else - { - $args[$key] = array('data' => $val); - } + $args[$key] = (is_array($val) && isset($val['data'])) ? $val : array('data' => $val); } } } @@ -262,8 +256,8 @@ class CI_Table { } } - // Is there anything to display? No? Smite them! - if (count($this->heading) === 0 AND count($this->rows) === 0) + // Is there anything to display? No? Smite them! + if (count($this->heading) === 0 && count($this->rows) === 0) { return 'Undefined table data'; } @@ -297,7 +291,7 @@ class CI_Table { { if ($key != 'data') { - $temp = str_replace('template['row_'.$name.'start'].$this->newline; @@ -333,27 +327,24 @@ class CI_Table { { if ($key !== 'data') { - $temp = str_replace('empty_cells; } + elseif ($function !== FALSE && is_callable($function)) + { + $out .= call_user_func($function, $cell); + } else { - if ($function !== FALSE && is_callable($function)) - { - $out .= call_user_func($function, $cell); - } - else - { - $out .= $cell; - } + $out .= $cell; } $out .= $this->template['cell_'.$name.'end']; @@ -382,9 +373,9 @@ class CI_Table { */ public function clear() { - $this->rows = array(); - $this->heading = array(); - $this->auto_heading = TRUE; + $this->rows = array(); + $this->heading = array(); + $this->auto_heading = TRUE; } // -------------------------------------------------------------------- @@ -399,7 +390,7 @@ class CI_Table { { if ( ! is_object($query)) { - return FALSE; + return; } // First generate the headings from the table column names @@ -407,14 +398,13 @@ class CI_Table { { if ( ! is_callable(array($query, 'list_fields'))) { - return FALSE; + return; } $this->heading = $this->_prep_args($query->list_fields()); } // Next blast through the result array and build out the rows - if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) @@ -443,7 +433,7 @@ class CI_Table { foreach ($data as $row) { // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i++ === 0 AND count($data) > 1 AND count($this->heading) === 0 AND $set_heading == TRUE) + if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading == TRUE) { $this->heading = $this->_prep_args($row); } @@ -488,36 +478,35 @@ class CI_Table { */ protected function _default_template() { - return array ( - 'table_open' => '
', + return array( + 'table_open' => '
', - 'thead_open' => '', - 'thead_close' => '', + 'thead_open' => '', + 'thead_close' => '', - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', - 'tbody_open' => '', - 'tbody_close' => '', + 'tbody_open' => '', + 'tbody_close' => '', - 'row_start' => '', - 'row_end' => '', - 'cell_start' => '', + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', - 'row_alt_start' => '', - 'row_alt_end' => '', - 'cell_alt_start' => '', + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', - 'table_close' => '
', - 'heading_cell_end' => '
', + 'heading_cell_end' => '
', - 'cell_end' => '
', + 'cell_end' => '
', - 'cell_alt_end' => '
', + 'cell_alt_end' => '
' - ); + 'table_close' => '' + ); } - } /* End of file Table.php */ -/* Location: ./system/libraries/Table.php */ +/* Location: ./system/libraries/Table.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 38d0e93746f13b12af360eb614ba5353e93ecf83 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 19:27:45 +0300 Subject: Some very minor code style changes and comment fixes --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 992b057ad..3777d29ff 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -251,7 +251,7 @@ class CI_Table { } elseif (is_array($table_data)) { - $set_heading = (count($this->heading) === 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; + $set_heading = (count($this->heading) !== 0 OR $this->auto_heading != FALSE); $this->_set_from_array($table_data, $set_heading); } } -- cgit v1.2.3-24-g4f1b From 3182a76899e75bc99da855d79867ce9fcfdc5592 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 26 Apr 2012 18:09:25 -0400 Subject: Fix Table library docblocks --- system/libraries/Table.php | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 3777d29ff..c5c71d889 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -38,13 +38,60 @@ */ class CI_Table { + /** + * Data for table rows + * + * @var array + */ public $rows = array(); + + /** + * Data for table heading + * + * @var array + */ public $heading = array(); + + /** + * Whether or not to automatically create the table header + * + * @var bool + */ public $auto_heading = TRUE; + + /** + * Table caption + * + * @var string + */ public $caption = NULL; + + /** + * Table layout template + * + * @var array + */ public $template = NULL; + + /** + * Newline setting + * + * @var string + */ public $newline = "\n"; + + /** + * Contents of empty cells + * + * @var string + */ public $empty_cells = ''; + + /** + * Callback for custom table layout + * + * @var function + */ public $function = FALSE; /** @@ -93,7 +140,7 @@ class CI_Table { * @param mixed * @return void */ - public function set_heading() + public function set_heading($args=array()) { $args = func_get_args(); $this->heading = $this->_prep_args($args); @@ -172,7 +219,7 @@ class CI_Table { * @param mixed * @return void */ - public function add_row() + public function add_row($args = array()) { $args = func_get_args(); $this->rows[] = $this->_prep_args($args); @@ -420,6 +467,7 @@ class CI_Table { * Set table data from an array * * @param array + * @param bool * @return void */ protected function _set_from_array($data, $set_heading = TRUE) -- cgit v1.2.3-24-g4f1b From 68f098142cb71f6a57f74ce34b5f58616cc1ed2f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 10:38:32 -0400 Subject: Fix calendar and session libraries --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index c5c71d889..236129531 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -140,7 +140,7 @@ class CI_Table { * @param mixed * @return void */ - public function set_heading($args=array()) + public function set_heading($args = array()) { $args = func_get_args(); $this->heading = $this->_prep_args($args); -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Table.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 236129531..f844d6435 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -44,49 +44,49 @@ class CI_Table { * @var array */ public $rows = array(); - + /** * Data for table heading * * @var array */ public $heading = array(); - + /** * Whether or not to automatically create the table header * * @var bool */ public $auto_heading = TRUE; - + /** * Table caption * * @var string */ public $caption = NULL; - + /** - * Table layout template + * Table layout template * * @var array */ public $template = NULL; - + /** * Newline setting * * @var string */ public $newline = "\n"; - + /** * Contents of empty cells * * @var string */ public $empty_cells = ''; - + /** * Callback for custom table layout * -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Table.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Table.php') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index f844d6435..0f8404d85 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -169,7 +169,7 @@ class CI_Table { // will want headings from a one-dimensional array $this->auto_heading = FALSE; - if ($col_limit == 0) + if ($col_limit === 0) { return $array; } @@ -298,7 +298,7 @@ class CI_Table { } elseif (is_array($table_data)) { - $set_heading = (count($this->heading) !== 0 OR $this->auto_heading != FALSE); + $set_heading = (count($this->heading) !== 0 OR $this->auto_heading !== FALSE); $this->_set_from_array($table_data, $set_heading); } } @@ -336,7 +336,7 @@ class CI_Table { foreach ($heading as $key => $val) { - if ($key != 'data') + if ($key !== 'data') { $temp = str_replace(' 1 && count($this->heading) === 0 && $set_heading == TRUE) + if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading === TRUE) { $this->heading = $this->_prep_args($row); } @@ -501,7 +501,7 @@ class CI_Table { */ protected function _compile_template() { - if ($this->template == NULL) + if ($this->template === NULL) { $this->template = $this->_default_template(); return; -- cgit v1.2.3-24-g4f1b