From dec0047b99af74939a6f43a16483a9aacafa2f9b Mon Sep 17 00:00:00 2001 From: Lloric Mayuga Garcia Date: Thu, 17 Aug 2017 16:38:34 +0800 Subject: [PATCH] Add captin Signed-off-by: Lloric Mayuga Garcia --- src/LaravelHtmlTableGenerator.php | 33 ++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/LaravelHtmlTableGenerator.php b/src/LaravelHtmlTableGenerator.php index de010d9..54d013d 100644 --- a/src/LaravelHtmlTableGenerator.php +++ b/src/LaravelHtmlTableGenerator.php @@ -33,7 +33,18 @@ class LaravelHtmlTableGenerator * * @type string */ - private $_links; + private $_links; + + /** + * + * + * + * + * @type string + */ + private $_caption; + + /** @@ -48,6 +59,7 @@ public function __construct() $this->_links = NULL; } + /** * @@ -61,6 +73,12 @@ public function __construct() private function _header(array $header) { $output = $this->_tags['head'].$this->_tags['head_row']; + + if(!is_null($this->_caption)) + { + $output = "$output{$this->_caption}"; + } + foreach($header as $row) { $output .= $this->_tags['head_cell'].$row.$this->_tags['head_cell_end']; @@ -68,6 +86,11 @@ private function _header(array $header) return $output.$this->_tags['head_row_end'].$this->_tags['head_end']; } + + private function _setCaption($caption) + { + $this->_caption = $caption; + } /** @@ -260,8 +283,10 @@ private function _checTagsFromAttrbutes() * @return string * @author Lloric Mayuga Garcia */ - public function generateTable($header, $data = [],$attributes = []) + public function generateTable($header, $data = [],$attributes = [], $caption = null) { + $this->_setCaption($caption); + $this->_attributes = $attributes; $this->_checTagsFromAttrbutes(); return $this->_generate($header ,$data); @@ -280,8 +305,10 @@ public function generateTable($header, $data = [],$attributes = []) * @return string * @author Lloric Mayuga Garcia */ - public function generateTableFromModel($header, $model,array $fields, $limit, $attributes = []) + public function generateTableFromModel($header, $model,array $fields, $limit, $attributes = [], $caption = null) { + $this->_setCaption($caption); + $this->_attributes = $attributes; $this->_checTagsFromAttrbutes(); return $this->_generate($header, $model, $limit, $fields);