PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Bvb/Grid/Template/Table.php

https://bitbucket.org/sader/domset
PHP | 305 lines | 234 code | 54 blank | 17 comment | 30 complexity | 51af398fb708f4bc1ea043f39b698553 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * LICENSE
  5. *
  6. * This source file is subject to the new BSD license
  7. * It is available through the world-wide-web at this URL:
  8. * http://www.petala-azul.com/bsd.txt
  9. * If you did not receive a copy of the license and are unable to
  10. * obtain it through the world-wide-web, please send an email
  11. * to geral@petala-azul.com so we can send you a copy immediately.
  12. *
  13. * @package Bvb_Grid
  14. * @copyright Copyright (c) (http://www.petala-azul.com)
  15. * @license http://www.petala-azul.com/bsd.txt New BSD License
  16. * @version $Id: Table.php 1796 2011-07-01 22:54:02Z bento.vilas.boas@gmail.com $
  17. * @author Bento Vilas Boas <geral@petala-azul.com >
  18. */
  19. class Bvb_Grid_Template_Table {
  20. public $hasExtraRow = 0;
  21. public $hasFilters = 1;
  22. public $i = 0;
  23. public $insideLoop;
  24. public $options;
  25. public $export;
  26. public $buildAbstract = false;
  27. public $result = array();
  28. public function buildAttr($class, $value)
  29. {
  30. if (strlen($value) == 0) {
  31. return '';
  32. }
  33. return $class . "='$value'";
  34. }
  35. public function getClass($name)
  36. {
  37. if (isset($this->options['userDefined']['cssClass'][$name])) {
  38. return ' class="' . $this->options['userDefined']['cssClass'][$name] . '" ';
  39. }
  40. return '';
  41. }
  42. public function globalStart()
  43. {
  44. if($this->buildAbstract)
  45. return;
  46. return "<table " . $this->getClass('table') . " align=\"center\" ".
  47. "cellspacing=\"0\" cellpadding=\"0\">" . PHP_EOL;
  48. }
  49. public function globalEnd()
  50. {
  51. if($this->buildAbstract)
  52. return;
  53. return "</table>" . PHP_EOL;
  54. }
  55. public function extra($value)
  56. {
  57. if($this->buildAbstract)
  58. return;
  59. return " <tr>" . PHP_EOL . " <td " . $this->getClass('topRow') .
  60. " colspan=\"{$this->options['colspan']}\"><div >$value</div></td></tr>";
  61. }
  62. public function titlesStart()
  63. {
  64. if($this->buildAbstract)
  65. return;
  66. return " <tr>";
  67. }
  68. public function titlesEnd()
  69. {
  70. return " </tr>" . PHP_EOL;
  71. }
  72. public function titlesLoop($title, $colspan)
  73. {
  74. $this->result['titles'][] = func_get_args();
  75. if($this->buildAbstract)
  76. return;
  77. return " <th " . $this->buildAttr('colspna', $colspan) . ">$title</th>" . PHP_EOL;
  78. }
  79. public function filtersStart()
  80. {
  81. if($this->buildAbstract)
  82. return;
  83. return " <tr>" . PHP_EOL;
  84. }
  85. public function filtersEnd()
  86. {
  87. if($this->buildAbstract)
  88. return;
  89. return " </tr>" . PHP_EOL;
  90. }
  91. public function noResults($message)
  92. {
  93. if($this->buildAbstract)
  94. return;
  95. return " <tr><td colspan=\"{$this->options['colspan']}\" " .
  96. $this->getClass('noRecords') . " >$message</div></td></tr>" . PHP_EOL;
  97. }
  98. public function filtersLoop($value, $colspan)
  99. {
  100. $this->result['filters'][] = func_get_args();
  101. if($this->buildAbstract)
  102. return;
  103. return " <td " . $this->buildAttr('colspan', $colspan) . "" .
  104. $this->getClass('filters') . " >$value</td>" . PHP_EOL;
  105. }
  106. public function hRow($value)
  107. {
  108. if($this->buildAbstract)
  109. return;
  110. return " <td colspan=\"{$this->options['colspan']}\" class=\"hrow\">$value</td>" . PHP_EOL;
  111. }
  112. public function loopStart($class, $style)
  113. {
  114. $this->i++;
  115. $this->insideLoop = 1;
  116. if($this->buildAbstract)
  117. return;
  118. return "<tr " . $this->buildAttr('class', $class) . " " . $this->buildAttr('style', $style) . ">";
  119. }
  120. public function loopEnd()
  121. {
  122. if($this->buildAbstract)
  123. return;
  124. return " </tr>" . PHP_EOL;
  125. }
  126. public function formMessage($sucess, $message)
  127. {
  128. if ($sucess) {
  129. $class = $this->getClass('formMessageOk');
  130. } else {
  131. $class = $this->getClass('formMessageError');
  132. }
  133. return "<div $class >$message</div>";
  134. }
  135. public function loopLoop($value, $class, $style, $rowspan, $colspan)
  136. {
  137. $this->result['loop'][$this->i][] = func_get_args();
  138. if($this->buildAbstract)
  139. return;
  140. return " <td " . $this->buildAttr('class', $class) . " " . $this->buildAttr('style', $style) . " " .
  141. $this->buildAttr('rowspan', $rowspan) . " " .
  142. $this->buildAttr('colspan', $colspan) . ">$value</td>" . PHP_EOL;
  143. }
  144. public function sqlExpStart()
  145. {
  146. if($this->buildAbstract)
  147. return;
  148. return " <tr>" . PHP_EOL;
  149. }
  150. public function sqlExpEnd()
  151. {
  152. if($this->buildAbstract)
  153. return;
  154. return " </tr>" . PHP_EOL;
  155. }
  156. public function sqlExpLoop($value, $class)
  157. {
  158. $this->result['sql'][] = func_get_args();
  159. if($this->buildAbstract)
  160. return;
  161. return " <td " . $this->buildAttr('class', $class) . "" .
  162. $this->getClass('sqlExp') . ">$value</td>" . PHP_EOL;
  163. }
  164. public function pagination($pagination, $numberRecords, $perPage, $pageSelect)
  165. {
  166. $this->result['pagination'] = func_get_args();
  167. if($this->buildAbstract)
  168. return;
  169. return " <tfoot><tr>" . PHP_EOL . " <td " . $this->getClass('tableFooter') .
  170. " colspan=\"{$this->options['colspan']}\"><div>
  171. <div " . $this->getClass('tableFooterExport') . ">" . $this->export . "</div>
  172. <div " . $this->getClass('tableFooterPagination') . "> <em>$numberRecords</em> $pagination $perPage
  173. $pageSelect</div>
  174. </div>
  175. </td>" . PHP_EOL . "</tr></tfoot>" . PHP_EOL;
  176. }
  177. public function images($url)
  178. {
  179. return array('asc' => "<img src=\"" . $url . "arrow_up.gif\" border=\"0\" />",
  180. 'desc' => "<img src=\"" . $url . "arrow_down.gif\" border=\"0\" />",
  181. 'delete' => "<img src=\"" . $url . "delete.png\" border=\"0\" />",
  182. 'detail' => "<img src=\"" . $url . "detail.png\" border=\"0\" />",
  183. 'edit' => "<img src=\"" . $url . "edit.png\" border=\"0\" />");
  184. }
  185. public function startDetail($title)
  186. {
  187. if($this->buildAbstract)
  188. return;
  189. return " <tr>" . PHP_EOL . " <th colspan='2' " . $this->getClass('detailLeft') . ">$title</th>"
  190. . PHP_EOL . "</tr>" . PHP_EOL;
  191. }
  192. public function detail($field, $value)
  193. {
  194. $this->result['detail'][] = func_get_args();
  195. if($this->buildAbstract)
  196. return;
  197. return " <tr>" . PHP_EOL . " <td " . $this->getClass('detailLeft') . ">$field</td><td " .
  198. $this->getClass('detailRight') . ">$value</td>" . PHP_EOL . "</tr>" . PHP_EOL;
  199. }
  200. public function detailEnd($url, $text)
  201. {
  202. $this->result['detailEnd'][] = func_get_args();
  203. if($this->buildAbstract)
  204. return;
  205. return " <tr>" . PHP_EOL . " <td colspan='2' class='detailEnd'><button type='button' class='detailReturn'
  206. onclick='window.location=\"$url\"';>$text</button></td>" . PHP_EOL . " </tr>" . PHP_EOL;
  207. }
  208. public function detailDelete($button)
  209. {
  210. $this->result['detailDelete'][] = func_get_args();
  211. if($this->buildAbstract)
  212. return;
  213. return "<tr><td colspan='2'>$button</td></tr>" . PHP_EOL;
  214. }
  215. public function export($exportDeploy, $images, $url, $gridId)
  216. {
  217. $exp = '';
  218. foreach ($exportDeploy as $export) {
  219. $caption = sprintf(Bvb_Grid_Translator::getInstance()->__('Export to %s format'), $export['caption']);
  220. $export['newWindow'] = isset($export['newWindow']) ? $export['newWindow'] : true;
  221. $class = isset($export['cssClass']) ? 'class="' . $export['cssClass'] . '"' : '';
  222. $blank = $export['newWindow'] == false ? '' : "target='_blank'";
  223. if (strlen($images) > 1) {
  224. $export['img'] = $images . $export['caption'] . '.gif';
  225. }
  226. if (isset($export['img'])) {
  227. $exp .= "<a title='$caption' $class $blank href='$url/_exportTo$gridId/{$export['caption']}'>
  228. <img alt='{$export['caption']}' src='{$export ['img']}' border='0'></a>";
  229. } else {
  230. $exp .= "<a title='$caption' $class $blank href='$url/_exportTo$gridId/{$export['caption']}'>" .
  231. $export['caption'] . "</a>";
  232. }
  233. }
  234. $this->exportWith = 25 * count($exportDeploy);
  235. $this->paginationWith = 630 + (10 - count($exportDeploy)) * 20;
  236. $this->export = $exp;
  237. return $exp;
  238. }
  239. public function scriptOnAjaxOpen($element)
  240. {
  241. return "document.getElementById(ponto).innerHTML= '<div style=\"width:'+(document.getElementById('" . $element . "').offsetWidth - 2)+'px;height:'+(document.getElementById('" . $element . "').offsetHeight - 2)+'px;\" " . $this->getClass('gridLoading') . ">&nbsp;</div>'";
  242. }
  243. public function scriptOnAjaxResponse($element)
  244. {
  245. return 'document.getElementById(ponto).innerHTML=xmlhttp.responseText';
  246. }
  247. public function scriptOnAjaxStateChange($element)
  248. {
  249. return '';
  250. }
  251. }