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/Tab.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:  * Tab.
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class Tab
 21: {
 22:     /**
 23:      * @var array
 24:      */
 25:     private $datas;
 26:     /**
 27:      * @var string
 28:      */
 29:     private $id;
 30:     /**
 31:      * @var string
 32:      */
 33:     private $select;
 34:     /**
 35:      * @var array
 36:      */
 37:     private $urls;
 38: 
 39:     /**
 40:      * Construct.
 41:      *
 42:      * @param string $id    ID ของ Tab ห้ามซ้ำกับอันอื่น
 43:      * @param string $url   URL ของหน้านี้ ใช้เป็นค่าเริ่มต้นของเมนู
 44:      * @param array  $items รายการเริ่มต้น
 45:      */
 46:     public function __construct($id, $url, $items = array())
 47:     {
 48:         $this->id = $id;
 49:         $this->urls = explode('?', $url);
 50:         if (count($this->urls) == 1) {
 51:             $this->urls[1] = '';
 52:         } else {
 53:             $this->urls[1] = str_replace(array('&', '&amp;amp;'), '&amp;', $this->urls[1]);
 54:         }
 55:         $this->datas = empty($items) ? array() : $items;
 56:     }
 57: 
 58:     /**
 59:      * เพิ่มรายการ Tab.
 60:      *
 61:      * @param string $id     ID ของแท็บ ใช้สำหรับเลือกแท็บ
 62:      * @param string $title  ข้อความในเมนูแท็บ
 63:      * @param string $url    URL เมื่อคลิกแท็บ ถ้าไม่กำหนดจะใช้ URL ตอนสร้างแท็บ
 64:      * @param string $target ค่าเริ่มต้น null คือไม่มี target
 65:      */
 66:     public function add($id, $title, $url = '', $target = null)
 67:     {
 68:         $this->datas[] = array(
 69:             'title' => $title,
 70:             'url' => $url,
 71:             'id' => $id,
 72:             'target' => $target,
 73:         );
 74:     }
 75: 
 76:     /**
 77:      * คืนค่าชื่อแท็บที่ถูกเลือก
 78:      *
 79:      * @return string
 80:      */
 81:     public function getSelect()
 82:     {
 83:         return $this->select;
 84:     }
 85: 
 86:     /**
 87:      * สร้างโค้ด HTML.
 88:      *
 89:      * @param string $select ID ของ Tab ที่เลือก ถ้าเป็นค่าว่างจะเลือกรายการแรกสุด
 90:      *
 91:      * @return string
 92:      */
 93:     public function render($select = '')
 94:     {
 95:         $html = '<div class="inline"><div class="writetab"><ul id="'.$this->id.'">';
 96:         foreach ($this->datas as $i => $item) {
 97:             $prop = array();
 98:             if (empty($item['url'])) {
 99:                 if (isset($item['id'])) {
100:                     if ($this->urls[1] == '') {
101:                         $prop[] = 'href="'.$this->urls[0].'?tab='.$item['id'].'"';
102:                     } else {
103:                         $prop[] = 'href="'.$this->urls[0].'?'.$this->urls[1].'&amp;tab='.$item['id'].'"';
104:                     }
105:                     $prop[] = 'id="tab_'.$item['id'].'"';
106:                 }
107:             } else {
108:                 $prop[] = 'href="'.$item['url'].'"';
109:             }
110:             if (!empty($item['target'])) {
111:                 $prop[] = 'target="'.$item['target'].'"';
112:             }
113:             if ($select == $item['id'] || ($i == 0 && $select == '')) {
114:                 $prop[] = 'class="select"';
115:                 $this->select = $item['id'];
116:             }
117:             $html .= '<li><a '.implode(' ', $prop).'>'.$item['title'].'</a></li>';
118:         }
119: 
120:         return $html.'</ul></div></div>';
121:     }
122: }
123: 
Kotchasan API documentation generated by ApiGen