Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • ArrayIterator
  • DateInterval
  • DOMNode
  • Kotchasan
  • Kotchasan\Accordion
  • Kotchasan\ApiController
  • Kotchasan\ArrayTool
  • Kotchasan\Cache\ApcCache
  • Kotchasan\Cache\Cache
  • Kotchasan\Cache\CacheItem
  • Kotchasan\Cache\FileCache
  • Kotchasan\CKEditor
  • Kotchasan\Collection
  • Kotchasan\Config
  • Kotchasan\Controller
  • Kotchasan\Country
  • Kotchasan\Csv
  • Kotchasan\Curl
  • Kotchasan\Currency
  • Kotchasan\Database
  • Kotchasan\Database\Db
  • Kotchasan\Database\DbCache
  • Kotchasan\Database\Driver
  • Kotchasan\Database\PdoMysqlDriver
  • Kotchasan\Database\Query
  • Kotchasan\Database\QueryBuilder
  • Kotchasan\Database\Schema
  • Kotchasan\Database\Sql
  • Kotchasan\DataTable
  • Kotchasan\Date
  • Kotchasan\DOMNode
  • Kotchasan\DOMParser
  • Kotchasan\Email
  • Kotchasan\File
  • Kotchasan\Files
  • Kotchasan\Form
  • Kotchasan\Grid
  • Kotchasan\Html
  • Kotchasan\Htmldoc
  • Kotchasan\HtmlTable
  • Kotchasan\Http\AbstractMessage
  • Kotchasan\Http\AbstractRequest
  • Kotchasan\Http\Message
  • Kotchasan\Http\NotFound
  • Kotchasan\Http\Request
  • Kotchasan\Http\Response
  • Kotchasan\Http\Stream
  • Kotchasan\Http\UploadedFile
  • Kotchasan\Http\Uri
  • Kotchasan\Image
  • Kotchasan\InputItem
  • Kotchasan\Inputs
  • Kotchasan\KBase
  • Kotchasan\Language
  • Kotchasan\ListItem
  • Kotchasan\Log\AbstractLogger
  • Kotchasan\Log\Logger
  • Kotchasan\Login
  • Kotchasan\Menu
  • Kotchasan\Mime
  • Kotchasan\Model
  • Kotchasan\Number
  • Kotchasan\ObjectTool
  • Kotchasan\Orm\Field
  • Kotchasan\Orm\Recordset
  • Kotchasan\Password
  • Kotchasan\Pdf
  • Kotchasan\Province
  • Kotchasan\Router
  • Kotchasan\Session
  • Kotchasan\Singleton
  • Kotchasan\Tab
  • Kotchasan\TableRow
  • Kotchasan\Template
  • Kotchasan\Text
  • Kotchasan\Validator
  • Kotchasan\View
  • PHPMailer
  • Psr\Log\AbstractLogger
  • Psr\Log\LogLevel
  • Psr\Log\NullLogger
  • SMTP

Interfaces

  • ArrayAccess
  • Countable
  • DateTimeInterface
  • Iterator
  • IteratorAggregate
  • Psr\Cache\CacheItemInterface
  • Psr\Cache\CacheItemPoolInterface
  • Psr\Http\Message\MessageInterface
  • Psr\Http\Message\RequestInterface
  • Psr\Http\Message\ResponseInterface
  • Psr\Http\Message\ServerRequestInterface
  • Psr\Http\Message\StreamInterface
  • Psr\Http\Message\UploadedFileInterface
  • Psr\Http\Message\UriInterface
  • Psr\Log\LoggerAwareInterface
  • Psr\Log\LoggerInterface
  • SeekableIterator
  • Serializable
  • Traversable

Traits

  • Psr\Log\LoggerTrait

Exceptions

  • Exception
  • InvalidArgumentException
  • Kotchasan\ApiException
  • Kotchasan\Cache\Exception
  • Kotchasan\Database\Exception
  • Kotchasan\InputItemException
  • LogicException
  • phpmailerException
  • RuntimeException

Functions

  • createClass
  • debug
  • getClassPath
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @filesource Kotchasan/HtmlTable.php
  4:  *
  5:  * @copyright 2016 Goragod.com
  6:  * @license http://www.kotchasan.com/license/
  7:  *
  8:  * @see http://www.kotchasan.com/
  9:  */
 10: 
 11: namespace Kotchasan;
 12: 
 13: /**
 14:  * HTML table.
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class HtmlTable
 21: {
 22:     /**
 23:      * caption ของ ตาราง.
 24:      *
 25:      * @var string
 26:      */
 27:     private $caption;
 28:     /**
 29:      * แอเรย์เก็บ property ของตาราง.
 30:      *
 31:      * @var array
 32:      */
 33:     private $properties;
 34:     /**
 35:      * แอเรย์ของ TableRow เก็บแถวของตาราง (tbody).
 36:      *
 37:      * @var array
 38:      */
 39:     private $tbody;
 40:     /**
 41:      * แอเรย์ของ TableRow เก็บแถวของตาราง (tfoot).
 42:      *
 43:      * @var array
 44:      */
 45:     private $tfoot;
 46:     /**
 47:      * แอเรย์เก็บข้อมูลส่วน thead.
 48:      *
 49:      * @var array
 50:      */
 51:     private $thead;
 52: 
 53:     /**
 54:      * class constructure.
 55:      *
 56:      * @param array $properties
 57:      */
 58:     public function __construct($properties = array())
 59:     {
 60:         $this->tbody = array();
 61:         $this->tfoot = array();
 62:         $this->thead = array();
 63:         $this->properties = $properties;
 64:     }
 65: 
 66:     /**
 67:      * กำหนด caption ของตาราง.
 68:      *
 69:      * @param string $text
 70:      */
 71:     public function addCaption($text)
 72:     {
 73:         $this->caption = $text;
 74:     }
 75: 
 76:     /**
 77:      * แทรกแถวของ tfoot.
 78:      *
 79:      * @param TableRow $row
 80:      */
 81:     public function addFooter(TableRow $row)
 82:     {
 83:         $this->tfoot[] = $row;
 84:     }
 85: 
 86:     /**
 87:      * แทรกแถวของ thead.
 88:      *
 89:      * @param array $headers
 90:      */
 91:     public function addHeader($headers)
 92:     {
 93:         $this->thead[] = $headers;
 94:     }
 95: 
 96:     /**
 97:      * แทรกแถวของ tbody.
 98:      *
 99:      * @param array $rows
100:      * @param array $attributes
101:      */
102:     public function addRow($rows, $attributes = array())
103:     {
104:         $tr = TableRow::create($attributes);
105:         foreach ($rows as $td) {
106:             $tr->addCell($td);
107:         }
108:         $this->tbody[] = $tr;
109:     }
110: 
111:     /**
112:      * สร้างตาราง.
113:      *
114:      * @param array $properties
115:      *
116:      * @return \static
117:      */
118:     public static function create($properties = array())
119:     {
120:         $obj = new static($properties);
121: 
122:         return $obj;
123:     }
124: 
125:     /**
126:      * แสดงผลตาราง.
127:      *
128:      * @return string
129:      */
130:     public function render()
131:     {
132:         $prop = array();
133:         foreach ($this->properties as $k => $v) {
134:             $prop[] = $k.'="'.$v.'"';
135:         }
136:         $table = array("\n<table".(empty($prop) ? '' : ' '.implode(' ', $prop)).'>');
137:         if (!empty($this->caption)) {
138:             $table[] = '<caption>'.$this->caption.'</caption>';
139:         }
140:         // thead
141:         if (!empty($this->thead)) {
142:             $thead = array();
143:             foreach ($this->thead as $r => $rows) {
144:                 $tr = array();
145:                 foreach ($rows as $c => $th) {
146:                     $prop = array('id' => 'id="c'.$c.'"', 'scope' => 'scope="col"');
147:                     foreach ($th as $key => $value) {
148:                         if ($key != 'text') {
149:                             $prop[$key] = $key.'="'.$value.'"';
150:                         }
151:                     }
152:                     $tr[] = '<th '.implode(' ', $prop).'>'.(isset($th['text']) ? $th['text'] : '').'</th>';
153:                 }
154:                 if (!empty($tr)) {
155:                     $thead[] = "<tr>\n".implode("\n", $tr)."\n</tr>";
156:                 }
157:             }
158:             if (!empty($thead)) {
159:                 $table[] = "<thead>\n".implode("\n", $thead)."\n</thead>";
160:             }
161:         }
162:         // tfoot
163:         if (!empty($this->tfoot)) {
164:             $rows = array();
165:             foreach ($this->tfoot as $tr) {
166:                 $rows[] = $tr->render();
167:             }
168:             if (!empty($rows)) {
169:                 $table[] = "<tfoot>\n".implode("\n", $rows)."\n</tfoot>";
170:             }
171:         }
172:         // tbody
173:         if (!empty($this->tbody)) {
174:             $rows = array();
175:             foreach ($this->tbody as $tr) {
176:                 $rows[] = $tr->render();
177:             }
178:             if (!empty($rows)) {
179:                 $table[] = "<tbody>\n".implode("\n", $rows)."\n</tbody>";
180:             }
181:         }
182:         $table[] = "</table>\n";
183: 
184:         return implode("\n", $table);
185:     }
186: }
187: 
188: /**
189:  * HTML table row.
190:  *
191:  * @author Goragod Wiriya <admin@goragod.com>
192:  *
193:  * @since 1.0
194:  */
195: class TableRow
196: {
197:     /**
198:      * property ของแถว.
199:      *
200:      * @var array
201:      */
202:     private $properties;
203:     /**
204:      * แอเรย์เก็บรายการ cell ในแถว.
205:      *
206:      * @var array
207:      */
208:     private $tds;
209: 
210:     /**
211:      * class constructure.
212:      *
213:      * @param array $properties
214:      */
215:     public function __construct($properties = array())
216:     {
217:         $this->properties = $properties;
218:         $this->tds = array();
219:     }
220: 
221:     /**
222:      * เพิ่ม cell ลงในแถว.
223:      *
224:      * @param array $td
225:      */
226:     public function addCell($td)
227:     {
228:         $this->tds[] = $td;
229:     }
230: 
231:     /**
232:      * สร้างแถวสำหรับ tbody.
233:      *
234:      * @param array $properties
235:      *
236:      * @return \static
237:      */
238:     public static function create($properties = array())
239:     {
240:         $obj = new static($properties);
241: 
242:         return $obj;
243:     }
244: 
245:     /**
246:      * แสดงผลแถว.
247:      *
248:      * @return string
249:      */
250:     public function render()
251:     {
252:         $prop = array();
253:         foreach ($this->properties as $key => $value) {
254:             $prop[$key] = $key.'="'.$value.'"';
255:         }
256:         $row = array('<tr '.implode(' ', $prop).'>');
257:         foreach ($this->tds as $c => $td) {
258:             $prop = array();
259:             $tag = 'td';
260:             foreach ($td as $key => $value) {
261:                 if ($key == 'scope') {
262:                     $tag = 'th';
263:                     $prop['scope'] = 'scope="'.$value.'"';
264:                     if (isset($this->properties['id'])) {
265:                         $prop['id'] = 'id="r'.$this->properties['id'].'"';
266:                     }
267:                 } elseif ($key != 'text') {
268:                     $prop[$key] = $key.'="'.$value.'"';
269:                 }
270:             }
271:             if (isset($this->properties['id'])) {
272:                 $prop['headers'] = $tag == 'th' ? 'headers="c'.$c.'"' : 'headers="r'.$this->properties['id'].' c'.$c.'"';
273:             }
274:             $tr[] = '<'.$tag.' '.implode(' ', $prop).'>'.(isset($th['text']) ? $th['text'] : '').'</'.$tag.'>';
275:             $row[] = '<'.$tag.' '.implode(' ', $prop).'>'.(empty($td['text']) ? '' : $td['text']).'</'.$tag.'>';
276:         }
277:         $row[] = '</tr>';
278: 
279:         return implode("\n", $row);
280:     }
281: }
282: 
Kotchasan API documentation generated by ApiGen