phpDocumentor table
[ class tree: table ] [ index: table ] [ all elements ]

Source for file Table.php

Documentation is available at Table.php

  1. <?
  2. /**
  3. * @package table
  4. * @filesource
  5. * @see HTML_TABLE_COMPONENT_PATH.'/Table.php'
  6. * @copyright (c) http://Finn-Rasmussen.com
  7. * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
  8. * @author http://Finn-Rasmussen.com
  9. * @version 1.9
  10. * @since 21-oct-2005
  11. */
  12.  
  13. /**
  14. * The required files
  15. */
  16. require_once(HTML_PATH.'/Html.php');
  17. require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
  18. require_once(HTML_TABLE_COMPONENT_PATH.'/Tr.php');
  19. require_once(HTML_TABLE_COMPONENT_PATH.'/Th.php');
  20. require_once(HTML_TABLE_COMPONENT_PATH.'/Td.php');
  21. if (defined('HTML_LOG_UTIL_PATH')) {
  22. require_once(HTML_LOG_UTIL_PATH.'/Log.php');
  23. }
  24.  
  25. /**
  26. * Generates the html for a table
  27. * <code>
  28. * Usage:
  29. * $table = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  30. * print $table->getHtml();
  31. * Or
  32. * Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  33. *
  34. * Generates a complete table interface
  35. * ---------------------------------
  36. * | Text header
  37. * ---------------------------------
  38. * | head1 | head2 | head3 |
  39. * ---------------------------------
  40. * | dat_1 | dat_2 | dat_3 |
  41. * ---------------------------------
  42. * </code>
  43. * @package table
  44. */
  45.  
  46. class Table extends Html {
  47. /**
  48. * @var String $text The text for the table header
  49. */
  50. var $text = '';
  51.  
  52. // Table data
  53. var $width = '';
  54. var $class = '';
  55. var $border = '';
  56. var $cellpadding = '';
  57. var $cellspacing = '';
  58. var $summary = '';
  59. var $caption = '';
  60.  
  61. /**
  62. * Constructor
  63. * @param String $text The text header for the table
  64. * @param String $width The Width for the table
  65. * @param String $class The Class
  66. * @param String $border The Border
  67. * @param String $cellpadding The CellSpacing
  68. * @param String $cellspacing The CellPadding
  69. * @param String $summary The Summary
  70. * @param String $caption The Caption
  71. */
  72. function Table($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
  73. $this->Html();
  74. if (defined('HTML_LOG_UTIL_PATH') && LOG_LEVEL & LOG_LEVEL_DEBUG) {
  75. $this->text = $text!=''?$text:$this->getClassName().'(), you forgot to add text';
  76. } else {
  77. $this->text = $text!=''?$text:'';
  78. }
  79. $theBorder = $border!=''?$border:TABLE_BORDER;
  80. if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_BORDER) {
  81. $theBorder = '1'; // Debug, show border
  82. }
  83. $this->width = $width!=''?$width:TABLE_WIDTH;
  84. $this->class = $class!=''?$class:TABLE_CLASS;
  85. $this->border = $theBorder;
  86. $this->cellpadding = $cellpadding!=''?$cellpadding:TABLE_CELLPADDING;
  87. $this->cellspacing = $cellspacing!=''?$cellspacing:TABLE_CELLSPACING;
  88. $this->summary = $summary!=''?$summary:'';
  89. $this->caption = $caption!=''?$caption:'';
  90. }
  91.  
  92. /**
  93. * Get the Table Header from class TableHeader
  94. * @return String the html table header
  95. */
  96. function getTableHeader() {
  97. $tableheader = new TableHeader($this->text,$this->width,$this->class,$this->border);
  98. return $tableheader->getHtml();
  99. }
  100.  
  101. /**
  102. * Get the start of the table
  103. * @return String the html for the start of the table
  104. */
  105. function getStart() {
  106. $html = '';
  107. $html .= '<table';
  108. $html .= $this->getAttribute('width');
  109. $html .= $this->getAttribute('class');
  110. $html .= $this->getAttribute('border');
  111. $html .= $this->getAttribute('cellpadding');
  112. $html .= $this->getAttribute('cellspacing');
  113. if ($this->summary!='') {
  114. $html .= $this->getAttribute('summary');
  115. }
  116. $html .= ">\r\n";
  117. if ($this->caption!='') {
  118. $html .= '<caption>'.$this->caption.'</caption>'."\r\n";
  119. }
  120. return $html;
  121. }
  122.  
  123. /**
  124. * Get the table end
  125. * @return String the html
  126. */
  127. function getEnd() {
  128. return "</table>\r\n";
  129. }
  130.  
  131. /**
  132. * Get the Row Start
  133. * @param String $class The css class name for the row
  134. * @return String the html
  135. */
  136. function getRowStart($class='') {
  137. $html = new Tr($class);
  138. return $html->getStart();
  139. }
  140.  
  141. /**
  142. * Get the Column Start
  143. * @param String $class The class name
  144. * @param String $valign The alignment of data
  145. * @param String $colspan The Column Span
  146. * @return String the html
  147. */
  148. function getColumnStart($class='',$valign='',$colspan='') {
  149. $html = new Td($class,$valign,$colspan);
  150. return $html->getStart();
  151. }
  152.  
  153. /**
  154. * Get the Column End
  155. * @return String the html
  156. */
  157. function getColumnEnd() {
  158. return Td::getEnd();
  159. }
  160.  
  161. /**
  162. * Get the Row End
  163. * @return String the html
  164. */
  165. function getRowEnd() {
  166. return Tr::getEnd();
  167. }
  168.  
  169. /**
  170. * Get the complete html for a table
  171. * @return String the html
  172. */
  173. function getHtml() {
  174. $html = $this->html;
  175. $html .= $this->getTableHeader();
  176. $html .= $this->getStart();
  177. if ($this->getSizeof()==0) {
  178. $html .= " <tr><td><!-- ";
  179. if (defined('TEXT_NO_DATA')) {
  180. $html .= TEXT_NO_DATA;
  181. } else {
  182. $html .= TABLE_TEXT_NO_DATA;
  183. }
  184. $html .= " -->&nbsp;</td></tr>\r\n";
  185. } else {
  186. $html .= $this->getElements();
  187. }
  188. $html .= $this->getEnd();
  189. return $html;
  190. }
  191.  
  192. /**
  193. * Get the start of the table tag
  194. * <code>
  195. * Usage:
  196. * Table::start($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  197. * </code>
  198. * @static
  199. * @param String $text The text header for the table
  200. * @param String $width The Width for the table
  201. * @param String $class The Class
  202. * @param String $border The Border
  203. * @param String $cellpadding The CellSpacing
  204. * @param String $cellspacing The CellPadding
  205. * @param String $summary The Summary
  206. * @param String $caption The Caption
  207. */
  208. function start($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
  209. switch ($text) {
  210. case 'tr':
  211. Tr::start();
  212. break;
  213. case 'td':
  214. Td::start($class);
  215. break;
  216. case 'th':
  217. Th::start('',$class);
  218. break;
  219. case 'table':
  220. // fall through
  221. default:
  222. $html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  223. $html->addHtml($html->getStart());
  224. break;
  225. }
  226. }
  227.  
  228. /**
  229. * Get the end of the table tag
  230. * <code>
  231. * Usage:
  232. * Table::end($type);
  233. * </code>
  234. * @static
  235. * @param String $type 'table', 'tr', 'td' or 'th' or empty
  236. */
  237. function end($type='') {
  238. switch ($type) {
  239. case 'tr':
  240. Tr::end();
  241. break;
  242. case 'td':
  243. Td::end();
  244. break;
  245. case 'th':
  246. Th::end();
  247. break;
  248. case 'table':
  249. // fall through
  250. default:
  251. $html = new Html();
  252. $html->addHtml(Table::getEnd());
  253. break;
  254. }
  255. }
  256.  
  257. /**
  258. * Get the start of the TR tag
  259. * <code>
  260. * Usage:
  261. * Table::trstart($class);
  262. * </code>
  263. * @static
  264. * @param String $class The class name
  265. */
  266. function trstart($class='') {
  267. Tr::start($class);
  268. }
  269.  
  270. /**
  271. * Display html for the TR tag
  272. * <code>
  273. * Usage:
  274. * Table::tr($class);
  275. * </code>
  276. * @static
  277. * @param String $class The class name
  278. */
  279. function tr($class='') {
  280. Tr::start($class);
  281. }
  282.  
  283. /**
  284. * Get the end of the TR tag
  285. * <code>
  286. * Usage:
  287. * Table::trend();
  288. * </code>
  289. * @static
  290. */
  291. function trend() {
  292. Tr::end();
  293. }
  294.  
  295. /**
  296. * Get the start of the TD tag
  297. * <code>
  298. * Usage:
  299. * Table::tdstart($class,$valign);
  300. * </code>
  301. * @static
  302. * @param String $class The class name
  303. * @param String $valign The alignment of data
  304. */
  305. function tdstart($class='',$valign='') {
  306. Td::start($class,$valign);
  307. }
  308.  
  309. /**
  310. * Display html for the TD tag
  311. * <code>
  312. * Usage:
  313. * Table::td($class,$valign);
  314. * </code>
  315. * @static
  316. * @param String $class The class name
  317. * @param String $valign The alignment of data
  318. */
  319. function td($class='',$valign='') {
  320. Td::start($class,$valign);
  321. }
  322.  
  323. /**
  324. * Get the end of the TD tag
  325. * <code>
  326. * Usage:
  327. * Table::tdend();
  328. * </code>
  329. * @static
  330. */
  331. function tdend() {
  332. Td::end();
  333. }
  334.  
  335. /**
  336. * Get the start of the TH tag
  337. * <code>
  338. * Usage:
  339. * Table::thstart($class,$valign,$align);
  340. * </code>
  341. * @static
  342. * @param String $class The class name
  343. * @param String $valign The valignment of data
  344. * @param String $align The alignment of data
  345. */
  346. function thstart($class='',$valign='',$align='') {
  347. Th::start($class,$valign,$align);
  348. }
  349.  
  350. /**
  351. * Display html for a TH
  352. * <code>
  353. * Usage:
  354. * Table::th($class,$valign,$align);
  355. * </code>
  356. * @static
  357. * @param String $class The class name
  358. * @param String $valign The valignment of data
  359. * @param String $align The alignment of data
  360. */
  361. function th($class='',$valign='',$align='') {
  362. Th::start($class,$valign,$align);
  363. }
  364.  
  365. /**
  366. * Get the end of the TH tag
  367. * <code>
  368. * Usage:
  369. * Table::thend();
  370. * </code>
  371. * @static
  372. */
  373. function thend() {
  374. Th::end();
  375. }
  376.  
  377. /**
  378. * Display html
  379. * <code>
  380. * Usage:
  381. * Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  382. * </code>
  383. * @static
  384. * @param String $text The text header for the table
  385. * @param String $width The width of the table
  386. * @param String $class The class of the table
  387. * @param String $border The border of the table
  388. * @param String $cellpadding The CellSpacing
  389. * @param String $cellspacing The CellPadding
  390. * @param String $summary The Summary
  391. * @param String $caption The Caption
  392. */
  393. function display($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
  394. $html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
  395. $html->addHtml();
  396. }
  397. }
  398. ?>

Documentation generated on Thu, 22 Dec 2005 17:19:32 +0100 by phpDocumentor 1.3.0RC3